-
Notifications
You must be signed in to change notification settings - Fork 1
/
pr.js
100 lines (90 loc) · 2.53 KB
/
pr.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* global done:false */
/* global error:false */
/* global PaymentRequest:false */
/**
* Initializes the payment request object.
*/
function buildPaymentRequest() {
if (!window.PaymentRequest) {
return null;
}
var supportedInstruments = [
{
supportedMethods: ['https://android.com/pay'],
data: {
merchantName: 'Vantiv IP Android Pay Web',
merchantId: '16662851041412722819',
allowedCardNetworks: ['AMEX', 'MASTERCARD', 'VISA', 'DISCOVER'],
paymentMethodTokenizationParameters: {
tokenizationType: 'GATEWAY_TOKEN',
parameters: {
'gateway': 'vantiv',
'vantiv:merchantPayPageId': 'KjJkn9DXJjdesuBf',
'vantiv:merchantOrderId': 'orderId',
'vantiv:merchantTransactionId': 'tranId',
'vantiv:merchantReportGroup': 'reportGroup'
}
}
}
}
];
var details = {
total: {label: 'Donation', amount: {currency: 'USD', value: '55.00'}},
displayItems: [
{
label: 'Original donation amount',
amount: {currency: 'USD', value: '65.00'}
},
{
label: 'Friends and family discount',
amount: {currency: 'USD', value: '-10.00'}
}
]
};
var request = null;
try {
request = new PaymentRequest(supportedInstruments, details);
if (request.canMakePayment) {
request.canMakePayment().then(function(result) {
info(result ? "Can make payment" : "Cannot make payment");
}).catch(function(err) {
error(err);
});
}
} catch (e) {
error('Developer mistake: \'' + e + '\'');
}
return request;
}
var request = buildPaymentRequest();
/**
* Launches payment request for Android Pay.
*/
function onBuyClicked() { // eslint-disable-line no-unused-vars
if (!window.PaymentRequest || !request) {
error('PaymentRequest API is not supported.');
return;
}
try {
request.show()
.then(function(instrumentResponse) {
window.setTimeout(function() {
instrumentResponse.complete('success')
.then(function() {
done('Thank you!', instrumentResponse);
})
.catch(function(err) {
error(err);
request = buildPaymentRequest();
});
}, 2000);
})
.catch(function(err) {
error(err);
request = buildPaymentRequest();
});
} catch (e) {
error('Developer mistake: \'' + e + '\'');
request = buildPaymentRequest();
}
}