Skip to content

Commit d691f6e

Browse files
committed
added apple-pay example
1 parent f92573c commit d691f6e

4 files changed

Lines changed: 60 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@ node_modules/
6767
.idea
6868

6969
.DS_Store
70+
71+
Caddyfile

firebase.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
"value": "block-all-mixed-content; upgrade-insecure-requests; sandbox allow-scripts allow-same-origin allow-popups allow-forms allow-top-navigation-by-user-activation; frame-ancestors *; script-src 'self' 'unsafe-inline' pay.google.com"
2121
} ]
2222
},
23+
{
24+
"source": "/apple-pay.html",
25+
"headers": [ {
26+
"key": "Cross-Origin-Embedder-Policy",
27+
"value": "require-corp"
28+
} ]
29+
},
2330
{
2431
"source": "/coep.html",
2532
"headers": [ {

public/apple-pay.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Apple Pay Web</title>
7+
<style>
8+
apple-pay-button {
9+
--apple-pay-button-width: 150px;
10+
--apple-pay-button-height: 30px;
11+
--apple-pay-button-border-radius: 3px;
12+
--apple-pay-button-padding: 0px 0px;
13+
--apple-pay-button-box-sizing: border-box;
14+
}
15+
</style>
16+
</head>
17+
18+
<body>
19+
<p>Demo merchant checkout page with a Apple Pay button</p>
20+
<div id="apple-pay-container">
21+
<apple-pay-button buttonstyle="black" type="plain" locale="en-US"></apple-pay-button>
22+
</div>
23+
<hr/>
24+
<div id="user-agent"></div>
25+
<script type="text/javascript">
26+
function onPageLoaded() {
27+
document.getElementById('user-agent').innerHTML= window.navigator.userAgent;
28+
}
29+
</script>
30+
<script src="https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js" onload="onPageLoaded()"></script>
31+
</body>
32+
</html>

public/coep.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
<html>
33
<head>
44
<title>Google Pay COEP</title>
5-
<script src="https://pay.google.com/gp/p/js/pay.js"></script>
5+
<!--<script src="https://pay.google.com/gp/p/js/pay.js"></script>-->
6+
67
</head>
78
<body>
89
<div id="container"></div>
910

1011
<script>
11-
const paymentsClient = new google.payments.api.PaymentsClient({ environment: 'TEST' });
12+
window.addEventListener("error", (event) => {
13+
console.error(event);
14+
});
15+
16+
window.addEventListener("unhandledrejection", (event) => {
17+
console.error(event);
18+
});
1219

1320
const baseRequest = {
1421
apiVersion: 2,
@@ -20,7 +27,7 @@
2027

2128
const tokenizationSpecification = {
2229
type: 'PAYMENT_GATEWAY',
23-
parameters: {
30+
parametes: {
2431
gateway: 'example',
2532
gatewayMerchantId: 'exampleMerchantId'
2633
}
@@ -60,7 +67,12 @@
6067
});
6168
}
6269

70+
function getGooglePaymentsClient() {
71+
return new google.payments.api.PaymentsClient({ environment: 'TEST' });
72+
}
73+
6374
function onGooglePayLoaded() {
75+
const paymentsClient = getGooglePaymentsClient();
6476
paymentsClient.isReadyToPay(getGoogleIsReadyToPayRequest())
6577
.then(function(response) {
6678
if (response.result) {
@@ -76,6 +88,7 @@
7688
}
7789

7890
function onGooglePaymentButtonClicked() {
91+
const paymentsClient = getGooglePaymentsClient();
7992
const paymentDataRequest = getGooglePaymentDataRequest();
8093
paymentsClient.loadPaymentData(paymentDataRequest)
8194
.then(function(paymentData) {
@@ -84,9 +97,10 @@
8497
.catch(function(err) {
8598
console.error('Payment failed: ', err);
8699
});
87-
}
100+
}
88101

89-
window.onload = onGooglePayLoaded;
102+
//window.onload = onGooglePayLoaded;
90103
</script>
104+
<script src="http://localhost:10079/gp/p/js/pay.js" onload="onGooglePayLoaded()" crossorigin></script>
91105
</body>
92106
</html>

0 commit comments

Comments
 (0)