From 45792374ce6ec3025373581e5661a4ce90855930 Mon Sep 17 00:00:00 2001 From: Avi Das Date: Wed, 14 Jan 2015 10:12:54 -0600 Subject: [PATCH] Add sample to demonstrate multiple configuration support, move openid sample to own folder --- samples/configuration/multiple_config.js | 60 +++++++++++++++++++ .../{ => openid_connect}/openid-connect.js | 0 2 files changed, 60 insertions(+) create mode 100644 samples/configuration/multiple_config.js rename samples/{ => openid_connect}/openid-connect.js (100%) diff --git a/samples/configuration/multiple_config.js b/samples/configuration/multiple_config.js new file mode 100644 index 00000000..f57d7ae6 --- /dev/null +++ b/samples/configuration/multiple_config.js @@ -0,0 +1,60 @@ +/* Copyright 2015 PayPal */ +"use strict"; +var paypal = require('../../'); + +var first_config = { + 'mode': 'sandbox', + 'client_id': '', + 'client_secret': '' +}; + +var second_config = { + 'mode': 'sandbox', + 'client_id': '', + 'client_secret': '' +}; + +//This sets up client id and secret globally +//to FIRST_CLIENT_ID and FIRST_CLIENT_SECRET +paypal.configure(first_config); + +var create_payment_json = { + "intent": "authorize", + "payer": { + "payment_method": "paypal" + }, + "redirect_urls": { + "return_url": "http://return.url", + "cancel_url": "http://cancel.url" + }, + "transactions": [{ + "item_list": { + "items": [{ + "name": "item", + "sku": "item", + "price": "1.00", + "currency": "USD", + "quantity": 1 + }] + }, + "amount": { + "currency": "USD", + "total": "1.00" + }, + "description": "This is the payment description." + }] +}; + +//Passing in the second_config here would override default settings +//and use SECOND_CLIENT_ID and SECOND_CLIENT_SECRET for creating the payment +//After buyer approves the payment via the HATEOS approval url, the second_config +//would need to be passed in the payment.execute call as well, otherwise +//a 404 with INVALID_RESOURCE_ID would get returned +paypal.payment.create(create_payment_json, second_config, function (error, payment) { + if (error) { + throw error; + } else { + console.log("Create Payment Response"); + console.log(payment); + } +}); diff --git a/samples/openid-connect.js b/samples/openid_connect/openid-connect.js similarity index 100% rename from samples/openid-connect.js rename to samples/openid_connect/openid-connect.js