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

Commit 70068fb

Browse files
Add support for Apple Pay JS versions 7-10
Add support for versions 7, 8, 9 and 10 of Apple Pay JS. Simplify the markdown syntax for code elements.
1 parent eeaea5f commit 70068fb

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

ApplePaySession.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,23 @@
99
*/
1010
ApplePaySessionPolyfill = (function () {
1111

12+
var latestApplePayVersion = 10;
1213
var self = {};
1314

1415
self.hasActiveSession = false;
1516
self.isApplePaySetUp = true;
1617
self.paymentsEnabled = true;
1718
self.paymentRequest = null;
1819
self.merchantIdentifier = "";
19-
self.supportedVersions = [1, 2, 3, 4, 5, 6];
20+
self.supportedVersions = [];
2021
self.validationURL = "https://apple-pay-gateway-cert.apple.com/paymentservices/startSession";
21-
self.version = 6;
22+
self.version = latestApplePayVersion;
23+
24+
var version;
25+
26+
for (version = 1; version <= latestApplePayVersion; version++) {
27+
self.supportedVersions.push(version);
28+
}
2229

2330
/**
2431
* Disables payments with ApplePaySession.

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ This repository contains a polyfill for [Apple Pay JS](https://developer.apple.c
88

99
Apple Pay JS is a way of accepting Apple Pay in websites using Safari in either iOS 10 (and later) and macOS for users who have a TouchID compatible device.
1010

11-
This polyfill provides a way to make [```ApplePaySession```](https://developer.apple.com/reference/applepayjs/applepaysession) available for testing your implementation in browsers that would otherwise not provide support for Apple Pay JS, such as in Chrome on Windows.
11+
This polyfill provides a way to make [`ApplePaySession`](https://developer.apple.com/reference/applepayjs/applepaysession) available for testing your implementation in browsers that would otherwise not provide support for Apple Pay JS, such as in Chrome on Windows.
1212

13-
The polyfill supports the Apple Pay JS API for versions 1 to 6. The Payment Request API is not supported.
13+
The polyfill supports the Apple Pay JS API for versions 1 to 10. The Payment Request API is not supported.
1414

1515
## Examples
1616

@@ -26,7 +26,7 @@ Then reference it in your HTML (don't forget to remove it in production environm
2626
<script src="/lib/applepayjs-polyfill/ApplePaySession.js"></script>
2727
```
2828

29-
Next, configure the callbacks on the ```ApplePaySessionPolyfill``` object to return the values you want:
29+
Next, configure the callbacks on the `ApplePaySessionPolyfill` object to return the values you want:
3030

3131
```js
3232
// Set the merchant identifier to drive ApplePaySession.canMakePaymentsWithActiveCard()
@@ -57,7 +57,7 @@ ApplePaySessionPolyfill.createPaymentToken = function (session) {
5757
};
5858
```
5959

60-
Now you should be able to test your implementation of [```ApplePaySession```](https://developer.apple.com/reference/applepayjs/applepaysession) in an HTML page in a browser that does not already provide the object in ```window```. For example:
60+
Now you should be able to test your implementation of [`ApplePaySession`](https://developer.apple.com/reference/applepayjs/applepaysession) in an HTML page in a browser that does not already provide the object in `window`. For example:
6161

6262
```js
6363
if ("ApplePaySession" in window && ApplePaySession.canMakePayments() === true) {
@@ -79,7 +79,7 @@ if ("ApplePaySession" in window && ApplePaySession.canMakePayments() === true) {
7979
}
8080
};
8181

82-
var session = new ApplePaySession(6, paymentRequest);
82+
var session = new ApplePaySession(10, paymentRequest);
8383

8484
session.onvalidatemerchant = function (event) {
8585
/* Merchant validation implementation */
@@ -97,15 +97,15 @@ if ("ApplePaySession" in window && ApplePaySession.canMakePayments() === true) {
9797

9898
### Apple Pay Set Up
9999

100-
If you need to test displaying the "Set Up Apple Pay" button, use the ```setUserSetupStatus(bool)``` function, as shown below, to specify that the user has not yet set up Apple Pay on the device.
100+
If you need to test displaying the "Set Up Apple Pay" button, use the `setUserSetupStatus(bool)` function, as shown below, to specify that the user has not yet set up Apple Pay on the device.
101101

102102
```js
103103
ApplePaySessionPolyfill.setUserSetupStatus(false);
104104
```
105105

106-
By default this value is set to ```true``` so that Apple Pay is available in the polyfill.
106+
By default this value is set to `true` so that Apple Pay is available in the polyfill.
107107

108-
If you need to test compatibility with devices that do not support Apple Pay set up, then delete the function from ```ApplePaySession``` before your implementation code is loaded:
108+
If you need to test compatibility with devices that do not support Apple Pay set up, then delete the function from `ApplePaySession` before your implementation code is loaded:
109109

110110
```js
111111
delete ApplePaySession.openPaymentSetup;

0 commit comments

Comments
 (0)