forked from oceanhuang/bankoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-checkout.html
80 lines (74 loc) · 2.5 KB
/
test-checkout.html
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
<!DOCTYPE html>
<html>
<head>
<title>W3C Payment Handler API Test</title>
</head>
<body>
<div><button id="buyButton">Buy</button></div>
<div><pre id="result"></pre></div>
<script type="text/javascript">
function initPaymentRequest() {
let supportedInstruments = [{
supportedMethods: ['https://oceanhuang-github-io-bankoo.herokuapp.com/'],
data: {
merchantName: 'Display name of merchant',
customKey: 'customValue'
},
}];
let 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'},
},
],
};
return new PaymentRequest(supportedInstruments, details);
}
/**
* Invokes PaymentRequest for Android Pay.
*
* @param {PaymentRequest} request The PaymentRequest object.
*/
function onBuyClicked(request) {
request.show().then(function(instrumentResponse) {
instrumentResponse.complete('success')
.then(function() {
document.getElementById('result').innerHTML =
instrumentToJsonString(instrumentResponse);
}).catch(function(err) {
console.log(err);
});
})
.catch(function(err) {
console.log(err);
});
}
function instrumentToJsonString(instrument) {
if (instrument.toJSON) {
return JSON.stringify(instrument, undefined, 2);
} else {
return JSON.stringify({
methodName: instrument.methodName,
details: instrument.details,
}, undefined, 2);
}
}
const payButton = document.getElementById('buyButton');
payButton.setAttribute('style', 'display: none;');
if (window.PaymentRequest) {
let request = initPaymentRequest();
payButton.setAttribute('style', 'display: inline;');
payButton.addEventListener('click', function() {
onBuyClicked(request);
request = initPaymentRequest();
});
}
</script>
</body>
</html>