forked from tjmehta/rest-api-sdk-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple_config.js
60 lines (55 loc) · 1.65 KB
/
multiple_config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Copyright 2015-2016 PayPal, Inc. */
"use strict";
var paypal = require('../../');
var first_config = {
'mode': 'sandbox',
'client_id': '<FIRST_CLIENT_ID>',
'client_secret': '<FIRST_CLIENT_SECRET>'
};
var second_config = {
'mode': 'sandbox',
'client_id': '<SECOND_CLIENT_ID>',
'client_secret': '<SECOND_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);
}
});