@fat-zebra/sdk 1.5.5 → 1.5.7-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.
Files changed (116) hide show
  1. package/.idea/fatzebra-js.iml +12 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/prettier.xml +6 -0
  4. package/.idea/vcs.xml +6 -0
  5. package/dist/applepay/applepay.d.ts +22 -7
  6. package/dist/applepay/applepay.js +99 -21
  7. package/dist/applepay/applepaymanager.d.ts +28 -0
  8. package/dist/applepay/applepaymanager.js +115 -0
  9. package/dist/applepay/clients/apple-pay-client.d.ts +9 -5
  10. package/dist/applepay/clients/apple-pay-client.js +10 -4
  11. package/dist/applepay/clients/paynow-client.d.ts +4 -2
  12. package/dist/applepay/clients/paynow-client.js +2 -7
  13. package/dist/applepay/types.d.ts +15 -0
  14. package/dist/applepay/types.js +1 -0
  15. package/dist/click_to_pay/index.d.ts +1 -0
  16. package/dist/click_to_pay/index.js +42 -6
  17. package/dist/click_to_pay/types.d.ts +12 -2
  18. package/dist/fatzebra.css +91 -0
  19. package/dist/hpp/hpp.d.ts +4 -0
  20. package/dist/hpp/hpp.js +26 -5
  21. package/dist/local/fatzebra.js +19684 -0
  22. package/dist/local/fatzebra.js.map +1 -1
  23. package/dist/main.d.ts +2 -0
  24. package/dist/main.js +24 -2
  25. package/dist/production/fatzebra.css +91 -0
  26. package/dist/production/fatzebra.js +2 -0
  27. package/dist/react/ApplePay.d.ts +9 -0
  28. package/dist/react/ApplePay.js +11 -0
  29. package/dist/react/ApplePayButton.d.ts +8 -0
  30. package/dist/react/ApplePayButton.js +18 -0
  31. package/dist/react/{url.d.ts → applePayUrl.d.ts} +2 -2
  32. package/dist/react/applePayUrl.js +19 -0
  33. package/dist/react/index.d.ts +2 -1
  34. package/dist/react/index.js +2 -1
  35. package/dist/react/useFatZebra.js +8 -57
  36. package/dist/react/useMessage.d.ts +10 -0
  37. package/dist/react/useMessage.js +70 -0
  38. package/dist/sandbox/fatzebra.css +91 -0
  39. package/dist/sandbox/fatzebra.js +2 -0
  40. package/dist/sandbox/fatzebra.js.LICENSE.txt +1 -0
  41. package/dist/sca/cardinal.d.ts +2 -11
  42. package/dist/sca/cardinal.js +4 -10
  43. package/dist/sca/index.d.ts +11 -1
  44. package/dist/sca/index.js +3 -38
  45. package/dist/sca/scenarios/enrollment.js +12 -0
  46. package/dist/sca/types/cardinal_types.d.ts +61 -0
  47. package/dist/sca/types/cardinal_types.js +11 -0
  48. package/dist/sca/types.d.ts +4 -1
  49. package/dist/sca/types.js +1 -0
  50. package/dist/sca/utility/index.d.ts +7 -0
  51. package/dist/sca/utility/index.js +39 -0
  52. package/dist/shared/bridge-client.d.ts +5 -1
  53. package/dist/shared/bridge-client.js +19 -1
  54. package/dist/shared/env.development.d.ts +3 -3
  55. package/dist/shared/env.development.js +3 -3
  56. package/dist/shared/envs/local.d.ts +3 -3
  57. package/dist/shared/envs/local.js +3 -3
  58. package/dist/shared/event-manager.d.ts +1 -1
  59. package/dist/shared/post-message-client.d.ts +2 -0
  60. package/dist/shared/post-message-client.js +1 -1
  61. package/dist/shared/types.d.ts +28 -13
  62. package/dist/shared/types.js +11 -1
  63. package/dist/src/applepay/applepaymanager.js +279 -0
  64. package/dist/src/applepay/applepaymanager.js.map +1 -0
  65. package/dist/src/react/ApplePayButton.js +56 -0
  66. package/dist/src/react/ApplePayButton.js.map +1 -0
  67. package/dist/src/react/{url.js → applePayUrl.js} +7 -21
  68. package/dist/src/react/applePayUrl.js.map +1 -0
  69. package/dist/src/react/applePayUrl.test.js +57 -0
  70. package/dist/src/react/applePayUrl.test.js.map +1 -0
  71. package/dist/src/react/useFatZebra.js +7 -56
  72. package/dist/src/react/useFatZebra.js.map +1 -1
  73. package/dist/src/react/useMessage.js +140 -0
  74. package/dist/src/react/useMessage.js.map +1 -0
  75. package/dist/src/react/useMessage.test.js +222 -0
  76. package/dist/src/react/useMessage.test.js.map +1 -0
  77. package/dist/src/validation/validators/apple-pay-load-params-button-validator.js +19 -0
  78. package/dist/src/validation/validators/apple-pay-load-params-button-validator.js.map +1 -0
  79. package/dist/staging/fatzebra.css +91 -0
  80. package/dist/staging/fatzebra.js +19684 -0
  81. package/dist/staging/fatzebra.js.map +1 -0
  82. package/dist/staging/index.html +247 -0
  83. package/dist/validation/schemas/applepay/load-params.json +31 -0
  84. package/dist/validation/schemas/applepay/options.json +115 -0
  85. package/dist/validation/schemas/applepay/payment-intent.json +42 -0
  86. package/dist/validation/schemas/click-to-pay/options.json +33 -3
  87. package/dist/validation/validators/apple-pay-load-params-button-validator.d.ts +3 -0
  88. package/dist/validation/validators/apple-pay-load-params-button-validator.js +12 -0
  89. package/dist/version.d.ts +1 -1
  90. package/dist/version.js +1 -1
  91. package/package.json +4 -3
  92. package/tsconfig.json +1 -1
  93. package/dist/paypal/paypal-button.d.ts +0 -31
  94. package/dist/paypal/paypal-button.js +0 -199
  95. package/dist/paypal/paypal-checkout.d.ts +0 -21
  96. package/dist/paypal/paypal-checkout.js +0 -100
  97. package/dist/paypal/types.d.ts +0 -188
  98. package/dist/paypal/types.js +0 -5
  99. package/dist/paypal/validation.d.ts +0 -4
  100. package/dist/paypal/validation.js +0 -65
  101. package/dist/react/url.js +0 -33
  102. package/dist/src/paypal/paypal-button.js +0 -311
  103. package/dist/src/paypal/paypal-button.js.map +0 -1
  104. package/dist/src/paypal/paypal-button.test.js +0 -41
  105. package/dist/src/paypal/paypal-button.test.js.map +0 -1
  106. package/dist/src/paypal/paypal-checkout.js +0 -111
  107. package/dist/src/paypal/paypal-checkout.js.map +0 -1
  108. package/dist/src/paypal/paypal-checkout.test.js +0 -167
  109. package/dist/src/paypal/paypal-checkout.test.js.map +0 -1
  110. package/dist/src/paypal/types.js +0 -9
  111. package/dist/src/paypal/types.js.map +0 -1
  112. package/dist/src/paypal/validation.js +0 -73
  113. package/dist/src/paypal/validation.js.map +0 -1
  114. package/dist/src/react/url.js.map +0 -1
  115. package/dist/src/react/url.test.js +0 -88
  116. package/dist/src/react/url.test.js.map +0 -1
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/fatzebra-js.iml" filepath="$PROJECT_DIR$/.idea/fatzebra-js.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="PrettierConfiguration">
4
+ <option name="myConfigurationMode" value="AUTOMATIC" />
5
+ </component>
6
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -1,20 +1,35 @@
1
1
  import { PaymentRequest } from './clients/apple-pay-client';
2
2
  import * as payNow from './clients/paynow-client';
3
- import { PostMessage } from '../shared/post-message-client';
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
- iframe: HTMLIFrameElement;
21
+ environment: Environment;
22
+ paymentIntent: PaymentIntent;
23
+ username: string;
12
24
  });
13
- checkApplePayEligibilty(): void;
14
- notifyApplePayEligibiity(): void;
15
- registerEventListener(): void;
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,85 @@ 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, getEligibilty, } from './clients/apple-pay-client';
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 fzPayNowDomain = process.env.PAYNOW_BASE_URL;
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.iframe = config.iframe;
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%');
35
+ this.iframe.setAttribute('allow', 'payment');
18
36
  this.postMessageClient = new PostMessageClient({
19
- channel: 'applepay',
20
- target: this.iframe
37
+ channel,
38
+ target: this.iframe,
39
+ environment: this.environment,
40
+ });
41
+ this.iframe.onload = () => __awaiter(this, void 0, void 0, function* () {
42
+ yield this.initialize();
21
43
  });
22
- this.registerEventListener();
23
- this.checkApplePayEligibilty();
24
- this.notifyApplePayEligibiity();
25
44
  }
26
- checkApplePayEligibilty() {
27
- if (getEligibilty()) {
45
+ getPayNowUrl(options) {
46
+ const { payment, verification } = this.paymentIntent;
47
+ const base = [
48
+ this.fzPayNowDomain,
49
+ 'sdk',
50
+ 'apple_pay',
51
+ this.username,
52
+ payment.reference,
53
+ payment.currency,
54
+ payment.amount,
55
+ verification
56
+ ].join('/');
57
+ const query = new URLSearchParams();
58
+ if (options === null || options === void 0 ? void 0 : options.allowed_card_networks) {
59
+ query.append('allowed_card_networks', options.allowed_card_networks.toString());
60
+ }
61
+ if (options === null || options === void 0 ? void 0 : options.allowed_card_types) {
62
+ query.append('allowed_card_types', options.allowed_card_types.toString());
63
+ }
64
+ if (options === null || options === void 0 ? void 0 : options.apple_button_type) {
65
+ query.append('apple_button_type', options.apple_button_type.toString());
66
+ }
67
+ if (options === null || options === void 0 ? void 0 : options.apple_button_style) {
68
+ query.append('apple_button_style', options.apple_button_style.toString());
69
+ }
70
+ if (options === null || options === void 0 ? void 0 : options.apple_button_locale) {
71
+ query.append('apple_button_locale', options.apple_button_locale.toString());
72
+ }
73
+ query.append('domain_name', this.domain_name);
74
+ return `${base}?${query.toString()}`;
75
+ }
76
+ initialize() {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ yield this.registerEventListener();
79
+ this.checkApplePayEligibility();
80
+ this.notifyApplePayEligibility();
81
+ });
82
+ }
83
+ checkApplePayEligibility() {
84
+ if (getEligibility()) {
28
85
  this.canMakePayments = true;
29
86
  }
30
87
  }
31
- notifyApplePayEligibiity() {
88
+ notifyApplePayEligibility() {
32
89
  const message = {
33
90
  channel,
34
91
  subject: 'eligibility',
@@ -39,10 +96,13 @@ export class ApplePay {
39
96
  this.postMessageClient.send(message);
40
97
  }
41
98
  registerEventListener() {
42
- this.postMessageClient.setEventListeners({
43
- 'paymentrequest': (data) => __awaiter(this, void 0, void 0, function* () {
44
- yield this.purchase(data);
45
- })
99
+ return new Promise((resolve, _) => {
100
+ this.postMessageClient.setEventListeners({
101
+ 'paymentrequest': (data) => __awaiter(this, void 0, void 0, function* () {
102
+ yield this.purchase(data);
103
+ })
104
+ });
105
+ resolve();
46
106
  });
47
107
  }
48
108
  purchase(request) {
@@ -53,23 +113,44 @@ export class ApplePay {
53
113
  this.applePaySession.onvalidatemerchant = (event) => __awaiter(this, void 0, void 0, function* () {
54
114
  let merchantSession;
55
115
  try {
56
- merchantSession = yield payNow.getMerchantSession(event.validationURL, payNowPaymentAttributes);
116
+ 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
117
  }
58
118
  catch (e) {
59
- console.log('Unable to establish new merchant session');
119
+ const payload = {
120
+ data: 'Payment failed. Unable to establish session',
121
+ errors: e,
122
+ };
123
+ emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
60
124
  return;
61
125
  }
62
126
  this.applePaySession.completeMerchantValidation(merchantSession);
63
127
  });
64
128
  this.applePaySession.onpaymentauthorized = (event) => __awaiter(this, void 0, void 0, function* () {
65
129
  try {
66
- yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), event.payment.token));
130
+ 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
131
  this.applePaySession.completePayment(window.ApplePaySession.STATUS_SUCCESS);
132
+ const payload = {
133
+ message: 'Payment successful.',
134
+ data: result,
135
+ };
136
+ emit(FatZebra.PublicEvent.PAYMENT_SUCCESS, payload);
68
137
  }
69
138
  catch (e) {
70
139
  this.applePaySession.completePayment(window.ApplePaySession.STATUS_FAILURE);
140
+ const payload = {
141
+ data: 'Payment failed.',
142
+ errors: ['Payment declined']
143
+ };
144
+ emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
71
145
  }
72
146
  });
147
+ this.applePaySession.oncancel = () => __awaiter(this, void 0, void 0, function* () {
148
+ const payload = {
149
+ data: 'Payment failed.',
150
+ errors: ['User cancelled payment.'],
151
+ };
152
+ emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
153
+ });
73
154
  this.applePaySession.begin();
74
155
  });
75
156
  }
@@ -87,7 +168,4 @@ export class ApplePay {
87
168
  const { paymentAttributes } = payload;
88
169
  return paymentAttributes;
89
170
  }
90
- sendMessage(payload) {
91
- this.iframe.contentWindow.postMessage(payload, fzPayNowDomain);
92
- }
93
171
  }
@@ -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
- Visa = "visa",
4
- MasterCard = "masterCard"
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
- lable: string;
22
+ label: string;
19
23
  amount: string;
20
24
  };
21
25
  }
22
- declare const getEligibilty: () => boolean;
26
+ declare const getEligibility: () => boolean;
23
27
  declare const createSession: (payload: PaymentRequest) => Promise<any>;
24
- export { createSession, type PaymentRequest, getEligibilty, MerchantCapability, SupportedNetwork, };
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["Visa"] = "visa";
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 getEligibilty = () => {
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
- return yield new window.ApplePaySession(2, payload);
33
+ return yield new window.ApplePaySession(14, payload);
28
34
  });
29
- export { createSession, getEligibilty, MerchantCapability, SupportedNetwork, };
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 {};
@@ -22,6 +22,7 @@ declare class ClickToPay {
22
22
  private options;
23
23
  constructor(config: ClickToPayModuleConfig);
24
24
  load(config: ClickToPayLoadParams): void;
25
+ addMRTListener: (mrt: string) => void;
25
26
  getPayNowUrl(options?: {
26
27
  [key: string]: any;
27
28
  }): string;
@@ -1,27 +1,45 @@
1
1
  import { PostMessageClient } from "../shared/post-message-client";
2
- import { BridgeEvent, PublicEvent } from "../shared/types";
2
+ import { BridgeEvent, Channel, PublicEvent } from "../shared/types";
3
3
  import * as util from '../shared/util';
4
4
  import { emit } from "../shared/event-manager";
5
5
  export const CLICK_TO_PAY_DEFAULT_OPTIONS = {
6
6
  iframe: true,
7
7
  postmessage: true,
8
8
  };
9
+ const OPTIONS_EXCLUDED_FROM_URL_PARAMS = ["mrt"];
9
10
  class ClickToPay {
10
11
  constructor(config) {
12
+ this.addMRTListener = (mrt) => {
13
+ const handlers = {};
14
+ handlers[PublicEvent.CLICK_TO_PAY_INITIAL_MRT_REQUEST] = (data) => {
15
+ const message = {
16
+ channel: Channel.CLICK_TO_PAY,
17
+ subject: PublicEvent.CLICK_TO_PAY_INITIAL_MRT_RESPONSE,
18
+ data: {
19
+ mrt
20
+ },
21
+ };
22
+ this.postMessageClient.send(message);
23
+ };
24
+ this.postMessageClient.setEventListeners(handlers);
25
+ };
11
26
  this.paymentIntent = config.paymentIntent;
12
27
  this.username = config.username;
13
28
  this.test = config.test;
14
- this.postMessageClient = new PostMessageClient({
15
- channel: 'click_to_pay',
16
- target: this.iframe
17
- });
18
29
  }
19
30
  load(config) {
20
31
  this.options = config.options;
21
32
  this.iframe = document.createElement('iframe');
22
33
  document.getElementById(config.containerId).appendChild(this.iframe);
23
- const payNowUrl = this.getPayNowUrl(config.options);
34
+ const urlParams = Object.fromEntries(Object.entries(config.options).filter(([key]) => !OPTIONS_EXCLUDED_FROM_URL_PARAMS.includes(key)));
35
+ const payNowUrl = this.getPayNowUrl(urlParams);
24
36
  this.iframe.setAttribute("src", payNowUrl);
37
+ this.postMessageClient = new PostMessageClient({
38
+ channel: Channel.CLICK_TO_PAY,
39
+ target: this.iframe
40
+ });
41
+ // Adding this before other crossframe event listener setup as we miss handling the MRT request event if we wait for this.iframe.onload to trigger
42
+ this.addMRTListener(this.options.mrt);
25
43
  this.iframe.onload = () => {
26
44
  this.setCrossFramesEventListeners();
27
45
  };
@@ -81,6 +99,24 @@ class ClickToPay {
81
99
  data
82
100
  });
83
101
  };
102
+ handlers[PublicEvent.CLICK_TO_PAY_RESIZE] = (data) => {
103
+ emit(PublicEvent.CLICK_TO_PAY_RESIZE, {
104
+ message: 'Container resized.',
105
+ data
106
+ });
107
+ };
108
+ handlers[PublicEvent.CLICK_TO_PAY_DCF_LOADED] = (data) => {
109
+ emit(PublicEvent.CLICK_TO_PAY_DCF_LOADED, {
110
+ message: 'Digital checkout form loaded.',
111
+ data
112
+ });
113
+ };
114
+ handlers[PublicEvent.CLICK_TO_PAY_MRT] = (data) => {
115
+ emit(PublicEvent.CLICK_TO_PAY_MRT, {
116
+ message: 'MRT created.',
117
+ data
118
+ });
119
+ };
84
120
  this.postMessageClient.setEventListeners(handlers);
85
121
  }
86
122
  purchase() {
@@ -1,9 +1,19 @@
1
1
  import { PaymentIntent } from "../shared/types";
2
2
  interface ClickToPayOptions {
3
- hideConfirmButton?: boolean;
4
- tokenizeOnly?: boolean;
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;
16
+ mrt?: string;
7
17
  }
8
18
  interface HppClickToPayParams {
9
19
  containerId: string;