-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment-request.html
68 lines (63 loc) · 2.01 KB
/
payment-request.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
<html>
<head>
</head>
<body>
<button id="checkout">Buy</butoon>
<script>
function() startPaymentRequestCheckout {
var methodData = [
{
supportedMethods: ['basic-card'],
data: {
supportedNetworks: ['visa', 'mastercard', 'amex'],
supportedTypes: ['credit']
}
}
];
var details = {
displayItems: [
{
label: "Sub-total",
amount: { currency: "USD", value : "100.00" }, // US$100.00
},
{
label: "Sales Tax",
amount: { currency: "USD", value : "9.00" }, // US$9.00
}
],
total: {
label: "Total due",
amount: { currency: "USD", value : "109.00" }, // US$109.00
}
};
var options = {
requestShipping: true
};
//constructor
var request = new PaymentRequest(methodData, details, options);
//Show the Native UI
request.show()
//When the promise is fulfilled, pass the results to your server for processing
.then(result => {
return process(result).then(response => {
// Examine server response
if (response.status === 200) {
//Show that the transaction was successful in the UI
return result.complete('success');
} else {
//Show in the Native UI that the transaction failed
return result.complete('fail');
}
})
});
request.addEventListener("shippingaddresschange", function (changeEvent) {
// Process shipping address change
});
request.addEventListener("onshippingoptionchange", function (changeEvent) {
// Process shipping option change (e.g. "one day shipping")
});
}
document.getElementById('#checkout').addEventListener('click', startPaymentRequestCheckout)
</script>
</body>
</html>