forked from tjmehta/rest-api-sdk-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_payment_with_customized_experience.js
More file actions
81 lines (72 loc) · 2.11 KB
/
create_payment_with_customized_experience.js
File metadata and controls
81 lines (72 loc) · 2.11 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Creating a custom PayPal payment/checkout experience and creating a
* payment with it by using the returned id as experience_profile_id in
* the payment json
*
* Copyright 2015-2016 PayPal, Inc.
*/
"use strict";
var paypal = require('../../../');
require('../../configure');
//Name needs to be unique so just generating a random one
var profile_name = Math.random().toString(36).substring(7);
var create_web_profile_json = {
"name": profile_name,
"presentation": {
"brand_name": "Best Brand",
"logo_image": "https://www.paypalobjects.com/webstatic/mktg/logo/AM_SbyPP_mc_vs_dc_ae.jpg",
"locale_code": "US"
},
"input_fields": {
"allow_note": true,
"no_shipping": 1,
"address_override": 1
},
"flow_config": {
"landing_page_type": "billing",
"bank_txn_pending_url": "http://www.yeowza.com"
}
};
var create_payment_json = {
"intent": "sale",
"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."
}]
};
paypal.webProfile.create(create_web_profile_json, function (error, web_profile) {
if (error) {
throw error;
} else {
//Set the id of the created payment experience in payment json
var experience_profile_id = web_profile.id;
create_payment_json.experience_profile_id = experience_profile_id;
paypal.payment.create(create_payment_json, function (error, payment) {
if (error) {
throw error;
} else {
console.log("Create Payment Response");
console.log(payment);
}
});
}
});