@fat-zebra/sdk 1.5.3-beta.3 → 1.5.5-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.dev.md +22 -0
- package/deploy-menu.png +0 -0
- package/dist/applepay/applepay.d.ts +22 -7
- package/dist/applepay/applepay.js +89 -21
- package/dist/applepay/applepaymanager.d.ts +28 -0
- package/dist/applepay/applepaymanager.js +115 -0
- package/dist/applepay/clients/apple-pay-client.d.ts +9 -5
- package/dist/applepay/clients/apple-pay-client.js +9 -3
- package/dist/applepay/clients/paynow-client.d.ts +4 -2
- package/dist/applepay/clients/paynow-client.js +2 -7
- package/dist/applepay/types.d.ts +15 -0
- package/dist/applepay/types.js +1 -0
- package/dist/click_to_pay/index.js +12 -0
- package/dist/click_to_pay/types.d.ts +11 -2
- package/dist/local/fatzebra.js +585 -11
- package/dist/local/fatzebra.js.map +1 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.js +24 -2
- package/dist/production/fatzebra.css +91 -0
- package/dist/production/fatzebra.js +2 -0
- package/dist/production/fatzebra.js.LICENSE.txt +1 -0
- package/dist/react/ApplePayButton.d.ts +8 -0
- package/dist/react/ApplePayButton.js +18 -0
- package/dist/react/applePayUrl.js +0 -16
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/useFatZebra.js +8 -57
- package/dist/react/useMessage.d.ts +10 -0
- package/dist/react/useMessage.js +70 -0
- package/dist/sandbox/fatzebra.css +91 -0
- package/dist/sandbox/fatzebra.js +2 -0
- package/dist/sandbox/fatzebra.js.LICENSE.txt +1 -0
- package/dist/scripts/release-package.js +324 -0
- package/dist/scripts/release-package.js.map +1 -0
- package/dist/shared/env.development.d.ts +3 -3
- package/dist/shared/env.development.js +3 -3
- package/dist/shared/envs/local.d.ts +3 -3
- package/dist/shared/envs/local.js +3 -3
- package/dist/shared/post-message-client.d.ts +2 -0
- package/dist/shared/post-message-client.js +1 -1
- package/dist/shared/types.d.ts +14 -2
- package/dist/shared/types.js +2 -0
- package/dist/src/applepay/applepay.js +198 -0
- package/dist/src/applepay/applepay.js.map +1 -0
- package/dist/src/applepay/applepaymanager.js +279 -0
- package/dist/src/applepay/applepaymanager.js.map +1 -0
- package/dist/src/applepay/clients/apple-pay-client.js +66 -0
- package/dist/src/applepay/clients/apple-pay-client.js.map +1 -0
- package/dist/src/applepay/clients/paynow-client.js +96 -0
- package/dist/src/applepay/clients/paynow-client.js.map +1 -0
- package/dist/src/applepay/index.js +6 -0
- package/dist/src/applepay/index.js.map +1 -0
- package/dist/src/click_to_pay/clicktopay.test.js +131 -0
- package/dist/src/click_to_pay/clicktopay.test.js.map +1 -0
- package/dist/src/click_to_pay/index.js +135 -0
- package/dist/src/click_to_pay/index.js.map +1 -0
- package/dist/src/click_to_pay/types.js +3 -0
- package/dist/src/click_to_pay/types.js.map +1 -0
- package/dist/src/hpp/hpp.js +230 -0
- package/dist/src/hpp/hpp.js.map +1 -0
- package/dist/src/hpp/hpp.test.js +137 -0
- package/dist/src/hpp/hpp.test.js.map +1 -0
- package/dist/src/hpp/index.js +6 -0
- package/dist/src/hpp/index.js.map +1 -0
- package/dist/src/index.js +15 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/main.js +229 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/main.test.js +236 -0
- package/dist/src/main.test.js.map +1 -0
- package/dist/src/react/ApplePayButton.js +56 -0
- package/dist/src/react/ApplePayButton.js.map +1 -0
- package/dist/src/react/VerifyCard.js +29 -0
- package/dist/src/react/VerifyCard.js.map +1 -0
- package/dist/src/react/VerifyExistingCard.js +30 -0
- package/dist/src/react/VerifyExistingCard.js.map +1 -0
- package/dist/src/react/applePayUrl.js +46 -0
- package/dist/src/react/applePayUrl.js.map +1 -0
- package/dist/src/react/applePayUrl.test.js +57 -0
- package/dist/src/react/applePayUrl.test.js.map +1 -0
- package/dist/src/react/index.js +13 -0
- package/dist/src/react/index.js.map +1 -0
- package/dist/src/react/paymentUrl.js +60 -0
- package/dist/src/react/paymentUrl.js.map +1 -0
- package/dist/src/react/paymentUrl.test.js +88 -0
- package/dist/src/react/paymentUrl.test.js.map +1 -0
- package/dist/src/react/submitForm.js +13 -0
- package/dist/src/react/submitForm.js.map +1 -0
- package/dist/src/react/useFatZebra.js +70 -0
- package/dist/src/react/useFatZebra.js.map +1 -0
- package/dist/src/react/useMessage.js +140 -0
- package/dist/src/react/useMessage.js.map +1 -0
- package/dist/src/react/useMessage.test.js +222 -0
- package/dist/src/react/useMessage.test.js.map +1 -0
- package/dist/src/react/verifyUrl.js +49 -0
- package/dist/src/react/verifyUrl.js.map +1 -0
- package/dist/src/sca/cardinal.js +145 -0
- package/dist/src/sca/cardinal.js.map +1 -0
- package/dist/src/sca/cardinal.test.js +77 -0
- package/dist/src/sca/cardinal.test.js.map +1 -0
- package/dist/src/sca/eci-mappings.js +63 -0
- package/dist/src/sca/eci-mappings.js.map +1 -0
- package/dist/src/sca/eci-mappings.test.js +31 -0
- package/dist/src/sca/eci-mappings.test.js.map +1 -0
- package/dist/src/sca/index.js +382 -0
- package/dist/src/sca/index.js.map +1 -0
- package/dist/src/sca/index.test.js +624 -0
- package/dist/src/sca/index.test.js.map +1 -0
- package/dist/src/sca/scenarios/enrollment.js +161 -0
- package/dist/src/sca/scenarios/enrollment.js.map +1 -0
- package/dist/src/sca/scenarios/index.js +8 -0
- package/dist/src/sca/scenarios/index.js.map +1 -0
- package/dist/src/sca/scenarios/validation.js +139 -0
- package/dist/src/sca/scenarios/validation.js.map +1 -0
- package/dist/src/sca/types.js +57 -0
- package/dist/src/sca/types.js.map +1 -0
- package/dist/src/shared/api-gateway-client.js +148 -0
- package/dist/src/shared/api-gateway-client.js.map +1 -0
- package/dist/src/shared/bridge-client.js +24 -0
- package/dist/src/shared/bridge-client.js.map +1 -0
- package/dist/src/shared/constants.js +19 -0
- package/dist/src/shared/constants.js.map +1 -0
- package/dist/src/shared/env.development.js +12 -0
- package/dist/src/shared/env.development.js.map +1 -0
- package/dist/src/shared/env.js +50 -0
- package/dist/src/shared/env.js.map +1 -0
- package/dist/src/shared/envs/local.js +12 -0
- package/dist/src/shared/envs/local.js.map +1 -0
- package/dist/src/shared/envs/production.js +12 -0
- package/dist/src/shared/envs/production.js.map +1 -0
- package/dist/src/shared/envs/sandbox.js +12 -0
- package/dist/src/shared/envs/sandbox.js.map +1 -0
- package/dist/src/shared/envs/staging.js +12 -0
- package/dist/src/shared/envs/staging.js.map +1 -0
- package/dist/src/shared/event-manager.js +24 -0
- package/dist/src/shared/event-manager.js.map +1 -0
- package/dist/src/shared/post-message-client.js +127 -0
- package/dist/src/shared/post-message-client.js.map +1 -0
- package/dist/src/shared/post-message-client.test.js +58 -0
- package/dist/src/shared/post-message-client.test.js.map +1 -0
- package/dist/src/shared/types.js +36 -0
- package/dist/src/shared/types.js.map +1 -0
- package/dist/src/shared/types.test.js +55 -0
- package/dist/src/shared/types.test.js.map +1 -0
- package/dist/src/shared/util.js +96 -0
- package/dist/src/shared/util.js.map +1 -0
- package/dist/src/shared/util.test.js +148 -0
- package/dist/src/shared/util.test.js.map +1 -0
- package/dist/src/validation/index.js +12 -0
- package/dist/src/validation/index.js.map +1 -0
- package/dist/src/validation/schemas/click-to-pay/load-params.json +34 -0
- package/dist/src/validation/schemas/click-to-pay/options.json +23 -0
- package/dist/src/validation/schemas/click-to-pay/payment-intent.json +42 -0
- package/dist/src/validation/schemas/customer.json +38 -0
- package/dist/src/validation/schemas/hpp-load-params.json +40 -0
- package/dist/src/validation/schemas/hpp-options.json +48 -0
- package/dist/src/validation/schemas/payment-intent.json +48 -0
- package/dist/src/validation/schemas/payment-method.json +83 -0
- package/dist/src/validation/schemas/verify-card-options.json +15 -0
- package/dist/src/validation/schemas/verify-card-params.json +24 -0
- package/dist/src/validation/validation-helper.js +10 -0
- package/dist/src/validation/validation-helper.js.map +1 -0
- package/dist/src/validation/validation-helper.test.js +34 -0
- package/dist/src/validation/validation-helper.test.js.map +1 -0
- package/dist/src/validation/validators/apple-pay-load-params-button-validator.js +19 -0
- package/dist/src/validation/validators/apple-pay-load-params-button-validator.js.map +1 -0
- package/dist/src/validation/validators/click-to-pay-load-params-validator.js +19 -0
- package/dist/src/validation/validators/click-to-pay-load-params-validator.js.map +1 -0
- package/dist/src/validation/validators/hpp-load-params-validator.js +21 -0
- package/dist/src/validation/validators/hpp-load-params-validator.js.map +1 -0
- package/dist/src/validation/validators/hpp-load-params-validator.test.js +56 -0
- package/dist/src/validation/validators/hpp-load-params-validator.test.js.map +1 -0
- package/dist/src/validation/validators/verify-card-params-validator.js +23 -0
- package/dist/src/validation/validators/verify-card-params-validator.js.map +1 -0
- package/dist/src/version.js +5 -0
- package/dist/src/version.js.map +1 -0
- package/dist/staging/fatzebra.css +91 -0
- package/dist/staging/fatzebra.js +19565 -0
- package/dist/staging/fatzebra.js.map +1 -0
- package/dist/staging/index.html +247 -0
- package/dist/tests/helpers/api-gateway-mock.js +37 -0
- package/dist/tests/helpers/api-gateway-mock.js.map +1 -0
- package/dist/validation/schemas/applepay/load-params.json +31 -0
- package/dist/validation/schemas/applepay/options.json +42 -0
- package/dist/validation/schemas/applepay/payment-intent.json +42 -0
- package/dist/validation/schemas/click-to-pay/options.json +30 -3
- package/dist/validation/validators/apple-pay-load-params-button-validator.d.ts +3 -0
- package/dist/validation/validators/apple-pay-load-params-button-validator.js +12 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +10 -4
- package/tsconfig.json +1 -0
package/README.dev.md
CHANGED
|
@@ -165,6 +165,28 @@ from here enter your 2FA code and voila! You have published a new version of the
|
|
|
165
165
|
|
|
166
166
|
## Release Management
|
|
167
167
|
|
|
168
|
+
### Automated release:
|
|
169
|
+
|
|
170
|
+
To deploy to npm run this command:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
npm run npm:publish
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+

|
|
177
|
+
|
|
178
|
+
The semantic version will be bumped according to the selected release type.
|
|
179
|
+
|
|
180
|
+
| Release type | version |
|
|
181
|
+
|--------------|--------------|
|
|
182
|
+
| Major | x-0-0 |
|
|
183
|
+
| Minor | 0-x-0 |
|
|
184
|
+
| Patch | 0-0-x |
|
|
185
|
+
| Beta | 0-0-0-beta-x |
|
|
186
|
+
|
|
187
|
+
The publish script will also tag the release and push to the current branch.
|
|
188
|
+
This process is an automated version of the process below, excluding changelog
|
|
189
|
+
|
|
168
190
|
The release of the sdk follows a weekly schedule. In the beginning of a new release cycle, do the following
|
|
169
191
|
|
|
170
192
|
1. Create a release branch, release/vX.X.X
|
package/deploy-menu.png
ADDED
|
Binary file
|
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
import { PaymentRequest } from './clients/apple-pay-client';
|
|
2
2
|
import * as payNow from './clients/paynow-client';
|
|
3
|
-
import {
|
|
3
|
+
import { OptionalUrlValues, PaymentIntent } from "../shared/types";
|
|
4
|
+
import { Environment } from "../shared/env";
|
|
5
|
+
interface ApplePayLoadParams {
|
|
6
|
+
containerId: string;
|
|
7
|
+
paymentIntent: PaymentIntent;
|
|
8
|
+
options?: OptionalUrlValues;
|
|
9
|
+
}
|
|
4
10
|
export declare class ApplePay {
|
|
5
|
-
private merchantId;
|
|
6
11
|
private canMakePayments;
|
|
7
12
|
private iframe;
|
|
8
13
|
private applePaySession;
|
|
9
14
|
private postMessageClient;
|
|
15
|
+
private fzPayNowDomain;
|
|
16
|
+
private domain_name;
|
|
17
|
+
private username;
|
|
18
|
+
private environment;
|
|
19
|
+
private paymentIntent;
|
|
10
20
|
constructor(config: {
|
|
11
|
-
|
|
21
|
+
environment: Environment;
|
|
22
|
+
paymentIntent: PaymentIntent;
|
|
23
|
+
username: string;
|
|
12
24
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
load(config: ApplePayLoadParams): void;
|
|
26
|
+
getPayNowUrl(options?: OptionalUrlValues): string;
|
|
27
|
+
initialize(): Promise<void>;
|
|
28
|
+
checkApplePayEligibility(): void;
|
|
29
|
+
notifyApplePayEligibility(): void;
|
|
30
|
+
registerEventListener(): Promise<void>;
|
|
16
31
|
purchase(request: PaymentRequest): Promise<void>;
|
|
17
32
|
extractApplePaymentRequestParams(payload: any): PaymentRequest;
|
|
18
33
|
extractPayNowPaymentAttributes(payload: any): payNow.PaymentAttributes;
|
|
19
|
-
sendMessage(payload: PostMessage): void;
|
|
20
34
|
}
|
|
35
|
+
export {};
|
|
@@ -7,28 +7,75 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { createSession,
|
|
10
|
+
import { createSession, getEligibility, } from './clients/apple-pay-client';
|
|
11
11
|
import * as payNow from './clients/paynow-client';
|
|
12
12
|
import { PostMessageClient } from '../shared/post-message-client';
|
|
13
|
+
import * as FatZebra from "../shared/types";
|
|
14
|
+
import env from "../shared/env";
|
|
15
|
+
import { emit } from "../shared/event-manager";
|
|
13
16
|
const channel = 'applepay';
|
|
14
|
-
const
|
|
17
|
+
const merchantSessionPath = '/v2/apple_pay/auth';
|
|
18
|
+
const purchaseTokenPath = '/v2/apple_pay/token';
|
|
15
19
|
export class ApplePay {
|
|
16
20
|
constructor(config) {
|
|
17
|
-
this.
|
|
21
|
+
this.paymentIntent = config.paymentIntent;
|
|
22
|
+
this.environment = config.environment;
|
|
23
|
+
this.fzPayNowDomain = env[this.environment].payNowUrl;
|
|
24
|
+
this.username = config.username;
|
|
25
|
+
}
|
|
26
|
+
load(config) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
this.domain_name = (_b = (_a = config === null || config === void 0 ? void 0 : config.options) === null || _a === void 0 ? void 0 : _a.domain_name) !== null && _b !== void 0 ? _b : window.location.hostname;
|
|
29
|
+
this.iframe = document.createElement('iframe');
|
|
30
|
+
document.getElementById(config.containerId).appendChild(this.iframe);
|
|
31
|
+
const applePayUrl = this.getPayNowUrl(config.options);
|
|
32
|
+
this.iframe.setAttribute("src", applePayUrl);
|
|
33
|
+
this.iframe.setAttribute("height", '100%');
|
|
34
|
+
this.iframe.setAttribute("width", '100%');
|
|
18
35
|
this.postMessageClient = new PostMessageClient({
|
|
19
|
-
channel
|
|
20
|
-
target: this.iframe
|
|
36
|
+
channel,
|
|
37
|
+
target: this.iframe,
|
|
38
|
+
environment: this.environment,
|
|
39
|
+
});
|
|
40
|
+
this.iframe.onload = () => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
yield this.initialize();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
getPayNowUrl(options) {
|
|
45
|
+
const { payment, verification } = this.paymentIntent;
|
|
46
|
+
const base = [
|
|
47
|
+
this.fzPayNowDomain,
|
|
48
|
+
'sdk',
|
|
49
|
+
'apple_pay',
|
|
50
|
+
this.username,
|
|
51
|
+
payment.reference,
|
|
52
|
+
payment.currency,
|
|
53
|
+
payment.amount,
|
|
54
|
+
verification
|
|
55
|
+
].join('/');
|
|
56
|
+
const query = new URLSearchParams();
|
|
57
|
+
if (options === null || options === void 0 ? void 0 : options.allowed_card_networks) {
|
|
58
|
+
query.append('allowed_card_networks', options.allowed_card_networks.toString());
|
|
59
|
+
}
|
|
60
|
+
if (options === null || options === void 0 ? void 0 : options.allowed_card_types) {
|
|
61
|
+
query.append('allowed_card_types', options.allowed_card_types.toString());
|
|
62
|
+
}
|
|
63
|
+
query.append('domain_name', this.domain_name);
|
|
64
|
+
return `${base}?${query.toString()}`;
|
|
65
|
+
}
|
|
66
|
+
initialize() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
yield this.registerEventListener();
|
|
69
|
+
this.checkApplePayEligibility();
|
|
70
|
+
this.notifyApplePayEligibility();
|
|
21
71
|
});
|
|
22
|
-
this.registerEventListener();
|
|
23
|
-
this.checkApplePayEligibilty();
|
|
24
|
-
this.notifyApplePayEligibiity();
|
|
25
72
|
}
|
|
26
|
-
|
|
27
|
-
if (
|
|
73
|
+
checkApplePayEligibility() {
|
|
74
|
+
if (getEligibility()) {
|
|
28
75
|
this.canMakePayments = true;
|
|
29
76
|
}
|
|
30
77
|
}
|
|
31
|
-
|
|
78
|
+
notifyApplePayEligibility() {
|
|
32
79
|
const message = {
|
|
33
80
|
channel,
|
|
34
81
|
subject: 'eligibility',
|
|
@@ -39,10 +86,13 @@ export class ApplePay {
|
|
|
39
86
|
this.postMessageClient.send(message);
|
|
40
87
|
}
|
|
41
88
|
registerEventListener() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
89
|
+
return new Promise((resolve, _) => {
|
|
90
|
+
this.postMessageClient.setEventListeners({
|
|
91
|
+
'paymentrequest': (data) => __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
yield this.purchase(data);
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
resolve();
|
|
46
96
|
});
|
|
47
97
|
}
|
|
48
98
|
purchase(request) {
|
|
@@ -53,23 +103,44 @@ export class ApplePay {
|
|
|
53
103
|
this.applePaySession.onvalidatemerchant = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
54
104
|
let merchantSession;
|
|
55
105
|
try {
|
|
56
|
-
merchantSession = yield payNow.getMerchantSession(event.validationURL, payNowPaymentAttributes);
|
|
106
|
+
merchantSession = yield payNow.getMerchantSession(event.validationURL, Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, domain_name: this.domain_name, display_name: this.username }), `${this.fzPayNowDomain}${merchantSessionPath}`);
|
|
57
107
|
}
|
|
58
108
|
catch (e) {
|
|
59
|
-
|
|
109
|
+
const payload = {
|
|
110
|
+
data: 'Payment failed. Unable to establish session',
|
|
111
|
+
errors: e,
|
|
112
|
+
};
|
|
113
|
+
emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
|
|
60
114
|
return;
|
|
61
115
|
}
|
|
62
116
|
this.applePaySession.completeMerchantValidation(merchantSession);
|
|
63
117
|
});
|
|
64
118
|
this.applePaySession.onpaymentauthorized = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
65
119
|
try {
|
|
66
|
-
yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), event.payment.token));
|
|
120
|
+
const result = yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, token: event.payment.token, domain_name: this.domain_name }), `${this.fzPayNowDomain}${purchaseTokenPath}`);
|
|
67
121
|
this.applePaySession.completePayment(window.ApplePaySession.STATUS_SUCCESS);
|
|
122
|
+
const payload = {
|
|
123
|
+
message: 'Payment successful.',
|
|
124
|
+
data: result,
|
|
125
|
+
};
|
|
126
|
+
emit(FatZebra.PublicEvent.PAYMENT_SUCCESS, payload);
|
|
68
127
|
}
|
|
69
128
|
catch (e) {
|
|
70
129
|
this.applePaySession.completePayment(window.ApplePaySession.STATUS_FAILURE);
|
|
130
|
+
const payload = {
|
|
131
|
+
data: 'Payment failed.',
|
|
132
|
+
errors: ['Payment declined']
|
|
133
|
+
};
|
|
134
|
+
emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
|
|
71
135
|
}
|
|
72
136
|
});
|
|
137
|
+
this.applePaySession.oncancel = () => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const payload = {
|
|
139
|
+
data: 'Payment failed.',
|
|
140
|
+
errors: ['User cancelled payment.'],
|
|
141
|
+
};
|
|
142
|
+
emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
|
|
143
|
+
});
|
|
73
144
|
this.applePaySession.begin();
|
|
74
145
|
});
|
|
75
146
|
}
|
|
@@ -87,7 +158,4 @@ export class ApplePay {
|
|
|
87
158
|
const { paymentAttributes } = payload;
|
|
88
159
|
return paymentAttributes;
|
|
89
160
|
}
|
|
90
|
-
sendMessage(payload) {
|
|
91
|
-
this.iframe.contentWindow.postMessage(payload, fzPayNowDomain);
|
|
92
|
-
}
|
|
93
161
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PaymentRequest } from './clients/apple-pay-client';
|
|
2
|
+
import * as payNow from './clients/paynow-client';
|
|
3
|
+
import { PostMessage } from '../shared/post-message-client';
|
|
4
|
+
declare class ApplePayManager {
|
|
5
|
+
private merchantId;
|
|
6
|
+
private canMakePayments;
|
|
7
|
+
private iframe;
|
|
8
|
+
private applePaySession;
|
|
9
|
+
private postMessageClient;
|
|
10
|
+
private fzPayNowDomain;
|
|
11
|
+
private username?;
|
|
12
|
+
private token?;
|
|
13
|
+
constructor(config: {
|
|
14
|
+
iframe: HTMLIFrameElement;
|
|
15
|
+
fzPayNowDomain: string;
|
|
16
|
+
username?: string;
|
|
17
|
+
token?: string;
|
|
18
|
+
});
|
|
19
|
+
initialize(): Promise<void>;
|
|
20
|
+
checkApplePayEligibility(): void;
|
|
21
|
+
notifyApplePayEligibility(): void;
|
|
22
|
+
registerEventListener(): Promise<void>;
|
|
23
|
+
purchase(request: PaymentRequest): Promise<void>;
|
|
24
|
+
extractApplePaymentRequestParams(payload: any): PaymentRequest;
|
|
25
|
+
extractPayNowPaymentAttributes(payload: any): payNow.PaymentAttributes;
|
|
26
|
+
sendMessage(payload: PostMessage): void;
|
|
27
|
+
}
|
|
28
|
+
export default ApplePayManager;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { createSession, getEligibilty, } from './clients/apple-pay-client';
|
|
11
|
+
import * as payNow from './clients/paynow-client';
|
|
12
|
+
import { PostMessageClient } from '../shared/post-message-client';
|
|
13
|
+
// import * as process from "process";
|
|
14
|
+
const channel = 'applepay';
|
|
15
|
+
// const fzPayNowDomain = process.env.PAYNOW_BASE_URL
|
|
16
|
+
// do the domain handling stuff better
|
|
17
|
+
const paynowDomain = 'https://paynow.test';
|
|
18
|
+
const merchantSessionPath = '/v2/apple_pay/payment_session';
|
|
19
|
+
const purchaseTokenPath = '/v2/apple_pay/token';
|
|
20
|
+
class ApplePayManager {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
// if (!config.fzPayNowDomain) {
|
|
23
|
+
// console.log('hitting i here')
|
|
24
|
+
// this.fzPayNowDomain = process?.env?.PAYNOW_BASE_URL;
|
|
25
|
+
// } else {
|
|
26
|
+
this.fzPayNowDomain = config.fzPayNowDomain;
|
|
27
|
+
this.username = config.username;
|
|
28
|
+
this.token = config.token;
|
|
29
|
+
// }
|
|
30
|
+
this.iframe = config.iframe;
|
|
31
|
+
this.postMessageClient = new PostMessageClient({
|
|
32
|
+
channel: 'applepay',
|
|
33
|
+
target: this.iframe
|
|
34
|
+
});
|
|
35
|
+
this.initialize();
|
|
36
|
+
}
|
|
37
|
+
initialize() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
yield this.registerEventListener();
|
|
40
|
+
this.checkApplePayEligibility();
|
|
41
|
+
this.notifyApplePayEligibility();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
checkApplePayEligibility() {
|
|
45
|
+
if (getEligibilty()) {
|
|
46
|
+
this.canMakePayments = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
notifyApplePayEligibility() {
|
|
50
|
+
const message = {
|
|
51
|
+
channel,
|
|
52
|
+
subject: 'eligibility',
|
|
53
|
+
data: {
|
|
54
|
+
canMakePayments: this.canMakePayments
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.postMessageClient.send(message);
|
|
58
|
+
}
|
|
59
|
+
registerEventListener() {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
this.postMessageClient.setEventListeners({
|
|
62
|
+
'paymentrequest': (data) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
yield this.purchase(data);
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
resolve();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
purchase(request) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const applePayPaymentRequest = this.extractApplePaymentRequestParams(request);
|
|
72
|
+
const payNowPaymentAttributes = this.extractPayNowPaymentAttributes(request);
|
|
73
|
+
this.applePaySession = yield createSession(applePayPaymentRequest);
|
|
74
|
+
this.applePaySession.onvalidatemerchant = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
let merchantSession;
|
|
76
|
+
try {
|
|
77
|
+
merchantSession = yield payNow.getMerchantSession(event.validationURL, Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, domain_name: window.location.hostname, display_name: this.username }), `${paynowDomain}${merchantSessionPath}`, this.username, this.token);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
console.log('Unable to establish new merchant session');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.applePaySession.completeMerchantValidation(merchantSession);
|
|
84
|
+
});
|
|
85
|
+
this.applePaySession.onpaymentauthorized = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
try {
|
|
87
|
+
yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, token: event.payment.token }), `${paynowDomain}${purchaseTokenPath}`);
|
|
88
|
+
this.applePaySession.completePayment(window.ApplePaySession.STATUS_SUCCESS);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
this.applePaySession.completePayment(window.ApplePaySession.STATUS_FAILURE);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
this.applePaySession.begin();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
extractApplePaymentRequestParams(payload) {
|
|
98
|
+
const { countryCode, currencyCode, merchantCapabilities, supportedNetworks, total, } = payload;
|
|
99
|
+
return {
|
|
100
|
+
countryCode,
|
|
101
|
+
currencyCode,
|
|
102
|
+
merchantCapabilities,
|
|
103
|
+
supportedNetworks,
|
|
104
|
+
total,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
extractPayNowPaymentAttributes(payload) {
|
|
108
|
+
const { paymentAttributes } = payload;
|
|
109
|
+
return paymentAttributes;
|
|
110
|
+
}
|
|
111
|
+
sendMessage(payload) {
|
|
112
|
+
this.iframe.contentWindow.postMessage(payload, this.fzPayNowDomain);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export default ApplePayManager;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
declare enum SupportedNetwork {
|
|
2
2
|
Amex = "amex",
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
ChinaUnionPay = "chinaUnionPay",
|
|
4
|
+
Discover = "discover",
|
|
5
|
+
JCB = "jcb",
|
|
6
|
+
Maestro = "maestro",
|
|
7
|
+
MasterCard = "masterCard",
|
|
8
|
+
Visa = "visa"
|
|
5
9
|
}
|
|
6
10
|
declare enum MerchantCapability {
|
|
7
11
|
Supports3DS = "supports3DS",
|
|
@@ -15,10 +19,10 @@ interface PaymentRequest {
|
|
|
15
19
|
merchantCapabilities: MerchantCapability[];
|
|
16
20
|
supportedNetworks: SupportedNetwork[];
|
|
17
21
|
total: {
|
|
18
|
-
|
|
22
|
+
label: string;
|
|
19
23
|
amount: string;
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
|
-
declare const
|
|
26
|
+
declare const getEligibility: () => boolean;
|
|
23
27
|
declare const createSession: (payload: PaymentRequest) => Promise<any>;
|
|
24
|
-
export { createSession, type PaymentRequest,
|
|
28
|
+
export { createSession, type PaymentRequest, getEligibility, MerchantCapability, SupportedNetwork, };
|
|
@@ -7,11 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
// valid schemes
|
|
11
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest/1916122-supportednetworks
|
|
10
12
|
var SupportedNetwork;
|
|
11
13
|
(function (SupportedNetwork) {
|
|
12
14
|
SupportedNetwork["Amex"] = "amex";
|
|
13
|
-
SupportedNetwork["
|
|
15
|
+
SupportedNetwork["ChinaUnionPay"] = "chinaUnionPay";
|
|
16
|
+
SupportedNetwork["Discover"] = "discover";
|
|
17
|
+
SupportedNetwork["JCB"] = "jcb";
|
|
18
|
+
SupportedNetwork["Maestro"] = "maestro";
|
|
14
19
|
SupportedNetwork["MasterCard"] = "masterCard";
|
|
20
|
+
SupportedNetwork["Visa"] = "visa";
|
|
15
21
|
})(SupportedNetwork || (SupportedNetwork = {}));
|
|
16
22
|
var MerchantCapability;
|
|
17
23
|
(function (MerchantCapability) {
|
|
@@ -20,10 +26,10 @@ var MerchantCapability;
|
|
|
20
26
|
MerchantCapability["SupportsDebit"] = "supportsDebit";
|
|
21
27
|
MerchantCapability["SupportsEMV"] = "supportsEMV";
|
|
22
28
|
})(MerchantCapability || (MerchantCapability = {}));
|
|
23
|
-
const
|
|
29
|
+
const getEligibility = () => {
|
|
24
30
|
return window.ApplePaySession && window.ApplePaySession.canMakePayments();
|
|
25
31
|
};
|
|
26
32
|
const createSession = (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
33
|
return yield new window.ApplePaySession(2, payload);
|
|
28
34
|
});
|
|
29
|
-
export { createSession,
|
|
35
|
+
export { createSession, getEligibility, MerchantCapability, SupportedNetwork, };
|
|
@@ -8,10 +8,12 @@ export interface PaymentAttributes {
|
|
|
8
8
|
merchant_id?: string;
|
|
9
9
|
recurring: boolean;
|
|
10
10
|
send_email?: string;
|
|
11
|
+
display_name?: string;
|
|
12
|
+
domain_name?: string;
|
|
11
13
|
}
|
|
12
14
|
export interface AuthorizePaymentRequestPayload extends PaymentAttributes {
|
|
13
15
|
token: string;
|
|
14
16
|
}
|
|
15
17
|
export declare const objectToQueryString: (obj: any) => string;
|
|
16
|
-
export declare const getMerchantSession: (validationUrl: string, paymentAttributes: PaymentAttributes) => Promise<any>;
|
|
17
|
-
export declare const authorizePayment: (payload: AuthorizePaymentRequestPayload) => Promise<any>;
|
|
18
|
+
export declare const getMerchantSession: (validationUrl: string, paymentAttributes: PaymentAttributes, baseUrl: string) => Promise<any>;
|
|
19
|
+
export declare const authorizePayment: (payload: AuthorizePaymentRequestPayload, url: string) => Promise<any>;
|
|
@@ -7,9 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
const paynowDomain = process.env.PAYNOW_BASE_URL;
|
|
11
|
-
const merchantSessionPath = process.env.PAYNOW_APPLEPAY_AUTH_PATH;
|
|
12
|
-
const purchaseTokenPath = process.env.PAYNOW_APPLEPAY_TOKEN_PATH;
|
|
13
10
|
export const objectToQueryString = (obj) => {
|
|
14
11
|
let queryString = [];
|
|
15
12
|
for (const key of Object.keys(obj)) {
|
|
@@ -17,8 +14,7 @@ export const objectToQueryString = (obj) => {
|
|
|
17
14
|
}
|
|
18
15
|
return queryString.join("&");
|
|
19
16
|
};
|
|
20
|
-
export const getMerchantSession = (validationUrl, paymentAttributes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
const baseUrl = `${paynowDomain}${merchantSessionPath}`;
|
|
17
|
+
export const getMerchantSession = (validationUrl, paymentAttributes, baseUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
18
|
const queryString = `url=${validationUrl}&${objectToQueryString(paymentAttributes)}`;
|
|
23
19
|
return new Promise((resolve, reject) => {
|
|
24
20
|
const request = new XMLHttpRequest();
|
|
@@ -35,8 +31,7 @@ export const getMerchantSession = (validationUrl, paymentAttributes) => __awaite
|
|
|
35
31
|
request.send();
|
|
36
32
|
});
|
|
37
33
|
});
|
|
38
|
-
export const authorizePayment = (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
const url = `${paynowDomain}${purchaseTokenPath}`;
|
|
34
|
+
export const authorizePayment = (payload, url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
35
|
return new Promise((resolve, reject) => {
|
|
41
36
|
const request = new XMLHttpRequest();
|
|
42
37
|
request.onload = () => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Environment } from "../shared/env";
|
|
2
|
+
import { PaymentIntent } from "../shared/types";
|
|
3
|
+
import { MerchantCapability, SupportedNetwork } from "./clients/apple-pay-client";
|
|
4
|
+
interface ApplePayOptions {
|
|
5
|
+
allowed_card_networks?: Array<SupportedNetwork>;
|
|
6
|
+
allowed_card_types?: Array<MerchantCapability>;
|
|
7
|
+
domain_name?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ApplePayParams {
|
|
10
|
+
containerId: string;
|
|
11
|
+
environment: Environment;
|
|
12
|
+
paymentIntent: PaymentIntent;
|
|
13
|
+
options?: ApplePayOptions;
|
|
14
|
+
}
|
|
15
|
+
export { type ApplePayParams, type ApplePayOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -81,6 +81,18 @@ class ClickToPay {
|
|
|
81
81
|
data
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
|
+
handlers[PublicEvent.CLICK_TO_PAY_RESIZE] = (data) => {
|
|
85
|
+
emit(PublicEvent.CLICK_TO_PAY_RESIZE, {
|
|
86
|
+
message: 'Container resized.',
|
|
87
|
+
data
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
handlers[PublicEvent.CLICK_TO_PAY_DCF_LOADED] = (data) => {
|
|
91
|
+
emit(PublicEvent.CLICK_TO_PAY_DCF_LOADED, {
|
|
92
|
+
message: 'Digital checkout form loaded.',
|
|
93
|
+
data
|
|
94
|
+
});
|
|
95
|
+
};
|
|
84
96
|
this.postMessageClient.setEventListeners(handlers);
|
|
85
97
|
}
|
|
86
98
|
purchase() {
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { PaymentIntent } from "../shared/types";
|
|
2
2
|
interface ClickToPayOptions {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
auth?: boolean;
|
|
4
|
+
cardListButtonText?: string;
|
|
5
5
|
css?: string;
|
|
6
6
|
cssSignature?: string;
|
|
7
|
+
displayName?: string;
|
|
8
|
+
hideConfirmButton?: boolean;
|
|
9
|
+
hideManualEntryLink?: boolean;
|
|
10
|
+
returnPath?: string;
|
|
11
|
+
returnTarget?: string;
|
|
12
|
+
saveCard?: boolean;
|
|
13
|
+
sharedData?: string;
|
|
14
|
+
submitPaymentButtonText?: string;
|
|
15
|
+
tokenizeOnly?: boolean;
|
|
7
16
|
}
|
|
8
17
|
interface HppClickToPayParams {
|
|
9
18
|
containerId: string;
|