-
Notifications
You must be signed in to change notification settings - Fork 10
/
payment.js
60 lines (58 loc) · 1.84 KB
/
payment.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
var debug = require('debug')('apple-pay');
var request = require('request');
exports.authorize = authorize;
function authorize (req, res) {
var token = req.body.payment.token;
var shippingContact = req.body.payment.shippingContact;
var billingContact = req.body.payment.billingContact;
request.post({
url: process.env.PSP_URL,
headers: {
Authorization: 'Basic ' + Buffer.from(process.env.PSP_USERNAME + ':' + process.env.PSP_PASSWORD).toString('base64')
},
json: true,
body: {
merchant_account_id: process.env.PSP_MERCHANT_ACCOUNT_ID,
order_no: '0000001', // test order no
payment: {
payment_id: '089e4cd378bff63d9d7bd63f8f', // test UUID
type: 'ApplePay',
amount: req.body.amount * 100,
currency: 'USD',
token: Buffer.from(JSON.stringify(token.paymentData))
.toString('base64')
},
customer_info: {
customer_no: '',
email: shippingContact.emailAddress,
customer_name: shippingContact.givenName + ' ' + shippingContact.familyName
},
shipping_address: {
first_name: shippingContact.givenName,
last_name: shippingContact.familyName,
address1: shippingContact.addressLines[0],
city: shippingContact.locality,
state_code: shippingContact.administrativeArea,
postal_code: shippingContact.postalCode,
country_code: shippingContact.countryCode
},
billing_address: {
first_name: billingContact.givenName || shippingContact.givenName,
last_name: billingContact.familyName || shippingContact.familyName,
address1: billingContact.addressLines[0],
city: billingContact.locality,
state_code: billingContact.administrativeArea,
postal_code: billingContact.postalCode,
country_code: billingContact.countryCode
}
}
}, function (err, resp, body) {
if (err) {
debug(err);
res.sendStatus(500);
return;
}
debug(body);
res.json(body);
});
}