Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Commit 0ace4de

Browse files
rsolomakhinlgarron
authored andcommitted
Add web-payments sample
1 parent 74e3e9c commit 0ace4de

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: page
3+
favicon: gray
4+
background: gray
5+
---
6+
7+
<div id="content">
8+
<h1>web-payment</h1>
9+
<p><button onclick="handleClick();">Initiate payment</button></p>
10+
</div>
11+
12+
<div id="footer">This page requires web payment API.</div>
13+
14+
<script src="index.js"></script>

common/input/web-payment/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Builds PaymentRequest for credit cards, but does not show any UI yet.
3+
* @return {PaymentRequest} The PaymentRequest object.
4+
*/
5+
function initPaymentRequest() {
6+
return new PaymentRequest(
7+
[{
8+
supportedMethods: ['basic-card'],
9+
}],
10+
{
11+
total: {
12+
label: 'Total',
13+
amount: {
14+
currency: 'USD',
15+
value: '1.00',
16+
},
17+
},
18+
});
19+
}
20+
21+
let request = initPaymentRequest();
22+
23+
/** Invokes PaymentRequest for credit cards. */
24+
function handleClick() {
25+
request.show()
26+
.then(function(instrumentResponse) {
27+
return instrumentResponse.complete('success');
28+
})
29+
.catch(function(err) {
30+
console.log(err);
31+
});
32+
33+
request = initPaymentRequest();
34+
}

0 commit comments

Comments
 (0)