@fat-zebra/sdk 1.4.13 → 1.4.15

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 (156) hide show
  1. package/.jest/setup-env-vars.js +0 -1
  2. package/dist/click_to_pay/index.d.ts +28 -0
  3. package/dist/click_to_pay/index.js +50 -0
  4. package/dist/click_to_pay/types.d.ts +13 -0
  5. package/dist/click_to_pay/types.js +1 -0
  6. package/dist/hpp/hpp.js +1 -3
  7. package/dist/local/fatzebra.js.map +1 -0
  8. package/dist/local/index.html +247 -0
  9. package/dist/main.js +0 -1
  10. package/dist/production/fatzebra.js.LICENSE.txt +1 -0
  11. package/dist/react/url.js +0 -4
  12. package/dist/react/useFatZebra.js +1 -3
  13. package/dist/sca/index.d.ts +1 -1
  14. package/dist/sca/index.js +24 -8
  15. package/dist/sca/scenarios/enrollment.d.ts +2 -1
  16. package/dist/sca/scenarios/enrollment.js +11 -1
  17. package/dist/sca/scenarios/validation.d.ts +2 -1
  18. package/dist/sca/scenarios/validation.js +11 -1
  19. package/dist/shared/api-gateway-client.d.ts +4 -3
  20. package/dist/shared/api-gateway-client.js +18 -5
  21. package/dist/shared/env.d.ts +4 -0
  22. package/dist/shared/env.js +4 -0
  23. package/dist/shared/post-message-client.d.ts +1 -0
  24. package/dist/shared/post-message-client.js +8 -11
  25. package/dist/shared/types.d.ts +2 -9
  26. package/dist/shared/types.js +1 -9
  27. package/dist/src/applepay/applepay.js +198 -0
  28. package/dist/src/applepay/applepay.js.map +1 -0
  29. package/dist/src/applepay/clients/apple-pay-client.js +66 -0
  30. package/dist/src/applepay/clients/apple-pay-client.js.map +1 -0
  31. package/dist/src/applepay/clients/paynow-client.js +96 -0
  32. package/dist/src/applepay/clients/paynow-client.js.map +1 -0
  33. package/dist/src/applepay/index.js +6 -0
  34. package/dist/src/applepay/index.js.map +1 -0
  35. package/dist/src/click_to_pay/index.js +88 -0
  36. package/dist/src/click_to_pay/index.js.map +1 -0
  37. package/dist/src/click_to_pay/types.js +3 -0
  38. package/dist/src/click_to_pay/types.js.map +1 -0
  39. package/dist/src/hpp/hpp.js +230 -0
  40. package/dist/src/hpp/hpp.js.map +1 -0
  41. package/dist/src/hpp/hpp.test.js +135 -0
  42. package/dist/src/hpp/hpp.test.js.map +1 -0
  43. package/dist/src/hpp/index.js +6 -0
  44. package/dist/src/hpp/index.js.map +1 -0
  45. package/dist/src/index.js +14 -0
  46. package/dist/src/index.js.map +1 -0
  47. package/dist/src/main.js +243 -0
  48. package/dist/src/main.js.map +1 -0
  49. package/dist/src/main.test.js +236 -0
  50. package/dist/src/main.test.js.map +1 -0
  51. package/dist/src/paypal/paypal-button.js +311 -0
  52. package/dist/src/paypal/paypal-button.js.map +1 -0
  53. package/dist/src/paypal/paypal-button.test.js +41 -0
  54. package/dist/src/paypal/paypal-button.test.js.map +1 -0
  55. package/dist/src/paypal/paypal-checkout.js +111 -0
  56. package/dist/src/paypal/paypal-checkout.js.map +1 -0
  57. package/dist/src/paypal/paypal-checkout.test.js +167 -0
  58. package/dist/src/paypal/paypal-checkout.test.js.map +1 -0
  59. package/dist/src/paypal/types.js +9 -0
  60. package/dist/src/paypal/types.js.map +1 -0
  61. package/dist/src/paypal/validation.js +73 -0
  62. package/dist/src/paypal/validation.js.map +1 -0
  63. package/dist/src/react/VerifyCard.js +29 -0
  64. package/dist/src/react/VerifyCard.js.map +1 -0
  65. package/dist/src/react/index.js +11 -0
  66. package/dist/src/react/index.js.map +1 -0
  67. package/dist/src/react/submitForm.js +13 -0
  68. package/dist/src/react/submitForm.js.map +1 -0
  69. package/dist/src/react/url.js +60 -0
  70. package/dist/src/react/url.js.map +1 -0
  71. package/dist/src/react/url.test.js +88 -0
  72. package/dist/src/react/url.test.js.map +1 -0
  73. package/dist/src/react/useFatZebra.js +119 -0
  74. package/dist/src/react/useFatZebra.js.map +1 -0
  75. package/dist/src/sca/cardinal.js +110 -0
  76. package/dist/src/sca/cardinal.js.map +1 -0
  77. package/dist/src/sca/eci-mappings.js +63 -0
  78. package/dist/src/sca/eci-mappings.js.map +1 -0
  79. package/dist/src/sca/eci-mappings.test.js +31 -0
  80. package/dist/src/sca/eci-mappings.test.js.map +1 -0
  81. package/dist/src/sca/index.js +363 -0
  82. package/dist/src/sca/index.js.map +1 -0
  83. package/dist/src/sca/index.test.js +620 -0
  84. package/dist/src/sca/index.test.js.map +1 -0
  85. package/dist/src/sca/scenarios/enrollment.js +161 -0
  86. package/dist/src/sca/scenarios/enrollment.js.map +1 -0
  87. package/dist/src/sca/scenarios/index.js +8 -0
  88. package/dist/src/sca/scenarios/index.js.map +1 -0
  89. package/dist/src/sca/scenarios/validation.js +139 -0
  90. package/dist/src/sca/scenarios/validation.js.map +1 -0
  91. package/dist/src/sca/types.js +57 -0
  92. package/dist/src/sca/types.js.map +1 -0
  93. package/dist/src/shared/api-gateway-client.js +184 -0
  94. package/dist/src/shared/api-gateway-client.js.map +1 -0
  95. package/dist/src/shared/bridge-client.js +24 -0
  96. package/dist/src/shared/bridge-client.js.map +1 -0
  97. package/dist/src/shared/constants.js +19 -0
  98. package/dist/src/shared/constants.js.map +1 -0
  99. package/dist/src/shared/env.development.js +12 -0
  100. package/dist/src/shared/env.development.js.map +1 -0
  101. package/dist/src/shared/env.js +46 -0
  102. package/dist/src/shared/env.js.map +1 -0
  103. package/dist/src/shared/envs/local.js +12 -0
  104. package/dist/src/shared/envs/local.js.map +1 -0
  105. package/dist/src/shared/envs/production.js +12 -0
  106. package/dist/src/shared/envs/production.js.map +1 -0
  107. package/dist/src/shared/envs/sandbox.js +12 -0
  108. package/dist/src/shared/envs/sandbox.js.map +1 -0
  109. package/dist/src/shared/envs/staging.js +12 -0
  110. package/dist/src/shared/envs/staging.js.map +1 -0
  111. package/dist/src/shared/event-manager.js +14 -0
  112. package/dist/src/shared/event-manager.js.map +1 -0
  113. package/dist/src/shared/post-message-client.js +107 -0
  114. package/dist/src/shared/post-message-client.js.map +1 -0
  115. package/dist/src/shared/post-message-client.test.js +58 -0
  116. package/dist/src/shared/post-message-client.test.js.map +1 -0
  117. package/dist/src/shared/types.js +47 -0
  118. package/dist/src/shared/types.js.map +1 -0
  119. package/dist/src/shared/types.test.js +55 -0
  120. package/dist/src/shared/types.test.js.map +1 -0
  121. package/dist/src/shared/util.js +96 -0
  122. package/dist/src/shared/util.js.map +1 -0
  123. package/dist/src/shared/util.test.js +148 -0
  124. package/dist/src/shared/util.test.js.map +1 -0
  125. package/dist/src/validation/index.js +12 -0
  126. package/dist/src/validation/index.js.map +1 -0
  127. package/dist/src/validation/schemas/click-to-pay/load-params.json +34 -0
  128. package/dist/src/validation/schemas/click-to-pay/options.json +23 -0
  129. package/dist/src/validation/schemas/click-to-pay/payment-intent.json +42 -0
  130. package/dist/src/validation/schemas/customer.json +38 -0
  131. package/dist/src/validation/schemas/hpp-load-params.json +40 -0
  132. package/dist/src/validation/schemas/hpp-options.json +48 -0
  133. package/dist/src/validation/schemas/payment-intent.json +48 -0
  134. package/dist/src/validation/schemas/payment-method.json +83 -0
  135. package/dist/src/validation/schemas/verify-card-options.json +15 -0
  136. package/dist/src/validation/schemas/verify-card-params.json +24 -0
  137. package/dist/src/validation/validation-helper.js +10 -0
  138. package/dist/src/validation/validation-helper.js.map +1 -0
  139. package/dist/src/validation/validation-helper.test.js +34 -0
  140. package/dist/src/validation/validation-helper.test.js.map +1 -0
  141. package/dist/src/validation/validators/click-to-pay-load-params-validator.js +19 -0
  142. package/dist/src/validation/validators/click-to-pay-load-params-validator.js.map +1 -0
  143. package/dist/src/validation/validators/hpp-load-params-validator.js +21 -0
  144. package/dist/src/validation/validators/hpp-load-params-validator.js.map +1 -0
  145. package/dist/src/validation/validators/hpp-load-params-validator.test.js +56 -0
  146. package/dist/src/validation/validators/hpp-load-params-validator.test.js.map +1 -0
  147. package/dist/src/validation/validators/verify-card-params-validator.js +23 -0
  148. package/dist/src/validation/validators/verify-card-params-validator.js.map +1 -0
  149. package/dist/tests/helpers/api-gateway-mock.js +37 -0
  150. package/dist/tests/helpers/api-gateway-mock.js.map +1 -0
  151. package/dist/validation/schemas/click-to-pay/load-params.json +34 -0
  152. package/dist/validation/schemas/click-to-pay/options.json +23 -0
  153. package/dist/validation/schemas/click-to-pay/payment-intent.json +42 -0
  154. package/dist/validation/validators/click-to-pay-load-params-validator.d.ts +3 -0
  155. package/dist/validation/validators/click-to-pay-load-params-validator.js +12 -0
  156. package/package.json +1 -1
@@ -0,0 +1,247 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>Merchant XYZ Checkout Page</title>
6
+ <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
7
+ <style type="text/css">
8
+ iframe {
9
+ height: 600px;
10
+ width: 700px;
11
+ }
12
+ </style>
13
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
14
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-md5.js"></script>
15
+ <script>
16
+ window.localStorage.setItem('fz-access-token', "<DO NOT USE>")
17
+ // card tokens will be filled out
18
+ var actionItems = {
19
+ tokens: [
20
+ {
21
+ token: 'whatever',
22
+ number: '4000000000001000',
23
+ description: 'Successful Frictionless Authentication'
24
+ },
25
+ {
26
+ token: '',
27
+ number: '4000000000001026',
28
+ description: 'Attempts Stand-In Frictionless'
29
+ },
30
+ {
31
+ token: '',
32
+ number: '4000000000001034',
33
+ description: 'Unavailable Frictionless'
34
+ },
35
+ {
36
+ token: '',
37
+ number: '4000000000001059',
38
+ description: 'Authentication Not Available on Lookup'
39
+ },
40
+ {
41
+ token: '',
42
+ number: '4000000000001067',
43
+ description: 'Error on Lookup'
44
+ },
45
+ {
46
+ token: '',
47
+ number: '4000000000001075',
48
+ description: 'Timeout on cmpi_lookup'
49
+ },
50
+ {
51
+ token: '',
52
+ number: '4000000000001083',
53
+ description: 'Bypassed Authentication'
54
+ },
55
+ {
56
+ token: '',
57
+ number: '4000000000001018',
58
+ description: 'Failed Frictionless'
59
+ },
60
+ {
61
+ token: '',
62
+ number: '4000000000001042',
63
+ description: 'Rejected Frictionless'
64
+ },
65
+ {
66
+ token: 'ahq94qb60fs0xaruga3h',
67
+ number: '4000000000001091',
68
+ description: 'Challenge'
69
+ }
70
+ ],
71
+ cards: [
72
+ {
73
+ number: '4000000000001000',
74
+ description: 'Successful Frictionless Authentication'
75
+ },
76
+ {
77
+ number: '4000000000001026',
78
+ description: 'Attempts Stand-In Frictionless'
79
+ },
80
+ {
81
+ number: '4000000000001034',
82
+ description: 'Unavailable Frictionless'
83
+ },
84
+ {
85
+ number: '4000000000001059',
86
+ description: 'Authentication Not Available on Lookup'
87
+ },
88
+ {
89
+ number: '4000000000001067',
90
+ description: 'Error on Lookup'
91
+ },
92
+ {
93
+ number: '4000000000001075',
94
+ description: 'Timeout on cmpi_lookup'
95
+ },
96
+ {
97
+ number: '4000000000001083',
98
+ description: 'Bypassed Authentication'
99
+ },
100
+ {
101
+ number: '4000000000001018',
102
+ description: 'Failed Frictionless'
103
+ },
104
+ {
105
+ number: '4000000000001042',
106
+ description: 'Rejected Frictionless'
107
+ },
108
+ {
109
+ number: '4000000000001091',
110
+ description: 'Challenge'
111
+ }
112
+ ]
113
+ }
114
+ </script>
115
+ <script src="fatzebra.js"></script></head>
116
+ <body>
117
+ <table id="options" class="table table-bordered">
118
+ <thead>
119
+ <tr>
120
+ <th scope="col">Card Token</th>
121
+ <th scope="col">New Card</th>
122
+ <th scope="col">Description</th>
123
+ </tr>
124
+ </thead>
125
+ <tbody>
126
+ </tbody>
127
+ </table>
128
+ <button type="button" class="btn btn-primary" id='doCheckout'>Primary</button>
129
+
130
+ <script>
131
+ var selectedMode = undefined
132
+ var selectedValue = undefined
133
+
134
+ $(document).ready(function() {
135
+
136
+ for (var i = 0; i < actionItems.tokens.length; i ++ ) {
137
+ const row = "<tr><td><input type='checkbox' class='option' data-mode='token' value='" + actionItems.tokens[i].token + "'><label>token for " + actionItems.tokens[i].number + "</label></td>" +
138
+ "<td><input type='checkbox' class='option' data-mode='card' value='" + actionItems.cards[i].number + "'><label>" + actionItems.cards[i].number + "</label></td>" +
139
+ "<td><label>" + actionItems.cards[i].description + "</label></td></tr>";
140
+ $('#options').append(row)
141
+ }
142
+
143
+ $('.option').change(function() {
144
+
145
+ if ($(this).prop("checked") == true) {
146
+ if (selectedValue === undefined) {
147
+ selectedMode = $(this).data('mode');
148
+ selectedValue = $(this).val();
149
+ } else {
150
+ $(this).prop("checked", false)
151
+ alert("There can only be one checkbox selected!");
152
+ }
153
+ } else {
154
+ selectedMode = undefined;
155
+ selectedValue = undefined;
156
+ }
157
+
158
+ console.log('selectedMode: ' + selectedMode);
159
+ console.log('selectedValue: ' + selectedValue);
160
+ })
161
+ })
162
+
163
+ </script>
164
+ </body>
165
+ <footer>
166
+
167
+ <script>
168
+ var fz = new FatZebra({
169
+ username: 'TEST'
170
+ });
171
+
172
+ $('#doCheckout').click(function() {
173
+ if (selectedMode === undefined || selectedValue == undefined) {
174
+ alert('Please select an option.');
175
+ return
176
+ }
177
+
178
+ var paymentMethod = undefined;
179
+
180
+ if (selectedMode === 'card') {
181
+ paymentMethod = {
182
+ type: 'card',
183
+ data: {
184
+ number: selectedValue,
185
+ holder: 'John Doe',
186
+ expiryMonth: '01',
187
+ expiryYear: '2022',
188
+ cvv: '123'
189
+ }
190
+ }
191
+ } else {
192
+ paymentMethod = {
193
+ type: 'card_on_file',
194
+ data: {
195
+ token: selectedValue
196
+ }
197
+ }
198
+ }
199
+
200
+ function randomString(length) {
201
+ return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1);
202
+ }
203
+
204
+ const reference = randomString(16);
205
+ const amount = 1200000;
206
+ const currency = 'AUD';
207
+ const message = [reference, amount, currency].join(':')
208
+ const verification = CryptoJS.HmacMD5(message, "033bd94b11").toString();
209
+
210
+ fz.verifyCard({
211
+ customer: {
212
+ firstName: 'Captain',
213
+ lastName: 'America',
214
+ email: 'sos@fatzebra.com.au',
215
+ address: '123 Get High Blvd.',
216
+ city: 'Red Light District',
217
+ postcode: '6666',
218
+ state: 'NSW',
219
+ country: 'Australia'
220
+ },
221
+ paymentIntent: {
222
+ payment: {
223
+ amount: amount,
224
+ currency: currency,
225
+ reference: reference
226
+ },
227
+ verification: verification
228
+ },
229
+ paymentMethod: paymentMethod
230
+ })
231
+ })
232
+
233
+ fz.on('fz.sca.error', function(event) {
234
+ console.log(JSON.stringify(event.detail))
235
+ })
236
+
237
+ fz.on('fz.sca.success', function(event) {
238
+ console.log(JSON.stringify(event.detail))
239
+ })
240
+
241
+ fz.on('fz.validation.error', function(event) {
242
+ console.log(JSON.stringify(event.detail))
243
+ })
244
+ </script>
245
+
246
+ </footer>
247
+ </html>
package/dist/main.js CHANGED
@@ -22,7 +22,6 @@ export default class FatZebra {
22
22
  this.fzConfig = config;
23
23
  window.MerchantUsername = config.username;
24
24
  this.gatewayClient = new GatewayClient({
25
- accessToken: window.localStorage.getItem(LocalStorageAccessTokenKey),
26
25
  username: config.username,
27
26
  environment: process.env.API_ENV,
28
27
  });
@@ -0,0 +1 @@
1
+ /** @license URI.js v4.2.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
package/dist/react/url.js CHANGED
@@ -9,14 +9,10 @@ const generatePaymentURL = (values, environment) => {
9
9
  "postmessage",
10
10
  "hide_card_holder",
11
11
  "hide_button",
12
- "return_path",
13
- "card_types",
14
- "surcharge_enabled",
15
12
  "sca_enabled",
16
13
  ];
17
14
  const environmentConfig = env[environment || Environment.sandbox];
18
15
  const urlTemplate = parseTemplate(`${environmentConfig.payNowUrl}/sdk/v3/{merchant}/{reference}/{currency}/{amount}/{verification}{?${queryParts.join(",")}}`);
19
- console.log(values);
20
16
  const url = urlTemplate.expand({
21
17
  merchant: values.merchant,
22
18
  reference: values.reference,
@@ -31,9 +31,7 @@ const useFatZebra = ({ config, handlers }) => {
31
31
  else {
32
32
  emit(FatZebra.PublicEvent.TOKENIZATION_SUCCESS, {
33
33
  message: "Card tokenization success.",
34
- data: {
35
- token: data.token,
36
- },
34
+ data
37
35
  });
38
36
  }
39
37
  if (options.sca_enabled) {
@@ -29,7 +29,7 @@ declare class Sca {
29
29
  private successCallback;
30
30
  private failureCallback;
31
31
  private environmentConfig;
32
- constructor({ gatewayClient, successCallback, failureCallback, environment }: ScaConfig);
32
+ constructor({ gatewayClient, successCallback, failureCallback }: ScaConfig);
33
33
  loadScript(): void;
34
34
  get cardinal(): CardinalManager;
35
35
  set cardinal(cardinal: CardinalManager);
package/dist/sca/index.js CHANGED
@@ -14,12 +14,14 @@ import { CardinalManager, } from './cardinal';
14
14
  import { emit, } from '../shared/event-manager';
15
15
  import { toFzSli } from './eci-mappings';
16
16
  import env, { Environment } from "../shared/env";
17
+ import { failedEnrollmentRequestScenario } from './scenarios/enrollment';
18
+ import { failedValidationRequestScenario } from './scenarios/validation';
17
19
  class Sca {
18
- constructor({ gatewayClient, successCallback, failureCallback, environment }) {
20
+ constructor({ gatewayClient, successCallback, failureCallback }) {
19
21
  this.gatewayClient = gatewayClient;
20
22
  this.successCallback = successCallback;
21
23
  this.failureCallback = failureCallback;
22
- this.environmentConfig = env[environment || Environment.sandbox];
24
+ this.environmentConfig = env[gatewayClient.environment || Environment.sandbox];
23
25
  }
24
26
  loadScript() {
25
27
  if (!document.getElementById("songbird-script")) {
@@ -59,7 +61,15 @@ class Sca {
59
61
  }
60
62
  run(config) {
61
63
  return __awaiter(this, void 0, void 0, function* () {
62
- this._cardinal = new CardinalManager();
64
+ try {
65
+ if (!this._cardinal) {
66
+ this._cardinal = new CardinalManager();
67
+ }
68
+ }
69
+ catch (error) {
70
+ this.reportFailure(`FatZebra.3DS: Failed to setup 3DS provider.`);
71
+ return;
72
+ }
63
73
  // Persist states until next 3DS run.
64
74
  this.paymentIntent = config.paymentIntent;
65
75
  this.bin = config.bin;
@@ -82,6 +92,7 @@ class Sca {
82
92
  this.sessionId = paymentsSetupCompleteResponse.sessionId;
83
93
  // Register handler. Called after OTP is entered on challenge prompt.
84
94
  this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
95
+ var _a;
85
96
  if (typeof error == 'string') {
86
97
  this.reportFailure(`FatZebra.3DS: Validation failed. ${error}.`);
87
98
  return;
@@ -114,7 +125,8 @@ class Sca {
114
125
  this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
115
126
  }
116
127
  else {
117
- this.reportFailure(`FatZebra.3DS: 3DS error - ${scenario.description} - ${scenario.outcome.errorCode}`, {
128
+ const failureMessage = [scenario.description, (_a = scenario.outcome) === null || _a === void 0 ? void 0 : _a.errorCode].filter(Boolean).join(' - ');
129
+ this.reportFailure(`FatZebra.3DS: 3DS error - ${failureMessage}`, {
118
130
  errorCode: scenario.outcome.errorCode,
119
131
  });
120
132
  }
@@ -188,6 +200,7 @@ class Sca {
188
200
  return properties;
189
201
  }
190
202
  handleEnrollmentResult(enrollSCAResponse) {
203
+ var _a;
191
204
  const threedsData = threedsResponseData(enrollSCAResponse);
192
205
  const scenario = getEnrollmentResult(enrollSCAResponse);
193
206
  if (scenario.outcome.authenticationType === 'challenge') {
@@ -198,7 +211,8 @@ class Sca {
198
211
  this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
199
212
  }
200
213
  else {
201
- this.reportFailure(`FatZebra.3DS: 3DS error - ${scenario.description} - ${scenario.outcome.errorCode}`, { errorCode: scenario.outcome.errorCode });
214
+ const failureMessage = [scenario.description, (_a = scenario.outcome) === null || _a === void 0 ? void 0 : _a.errorCode].filter(Boolean).join(' - ');
215
+ this.reportFailure(`FatZebra.3DS: 3DS error - ${failureMessage}`, { errorCode: scenario.outcome.errorCode });
202
216
  }
203
217
  }
204
218
  }
@@ -216,22 +230,24 @@ const threedsResponseData = (response) => {
216
230
  };
217
231
  };
218
232
  const getEnrollmentResult = (enrollment) => {
219
- return enrollmentScenarios.find((item) => {
233
+ const result = enrollmentScenarios.find((item) => {
220
234
  return item.reasonCode === enrollment.reason_code &&
221
235
  item.veresEnrolled === enrollment.enrolled &&
222
236
  item.pares === enrollment.pares &&
223
237
  item.threedsVersion === getMajor3dsVersion(enrollment.version);
224
238
  });
239
+ return result || failedEnrollmentRequestScenario;
225
240
  };
226
241
  const getValidationResult = (validation) => {
227
- return validationScenarios.find((item) => {
242
+ const result = validationScenarios.find((item) => {
228
243
  return item.reasonCode === validation.reason_code &&
229
244
  item.pares === validation.pares &&
230
245
  item.threedsVersion === getMajor3dsVersion(validation.version);
231
246
  });
247
+ return result || failedValidationRequestScenario;
232
248
  };
233
249
  // 3DS versioning follows SEMVER format. The first charactor is the major version number.
234
250
  const getMajor3dsVersion = (original) => {
235
- return original[0];
251
+ return original === null || original === void 0 ? void 0 : original[0];
236
252
  };
237
253
  export default Sca;
@@ -11,6 +11,7 @@ interface EnrollmentScenario {
11
11
  errorCode?: string;
12
12
  };
13
13
  }
14
+ declare const failedEnrollmentRequestScenario: EnrollmentScenario;
14
15
  declare const enrollmentScenarios: EnrollmentScenario[];
15
- export { enrollmentScenarios };
16
+ export { enrollmentScenarios, failedEnrollmentRequestScenario };
16
17
  export type { EnrollmentScenario };
@@ -1,4 +1,14 @@
1
1
  import { ScaErrorCode, VEResEnrolled, PARes } from '../types';
2
+ const failedEnrollmentRequestScenario = {
3
+ description: 'Enrollment Request Failed',
4
+ threedsVersion: null,
5
+ reasonCode: null,
6
+ veresEnrolled: null,
7
+ pares: null,
8
+ outcome: {
9
+ success: false, // no liability shift
10
+ },
11
+ };
2
12
  const enrollmentScenarios = [
3
13
  /***************************************************************/
4
14
  /********************** 3DS2 scenarios *************************/
@@ -143,4 +153,4 @@ const enrollmentScenarios = [
143
153
  }
144
154
  },
145
155
  ];
146
- export { enrollmentScenarios };
156
+ export { enrollmentScenarios, failedEnrollmentRequestScenario };
@@ -11,6 +11,7 @@ interface ValidationScenario {
11
11
  errorCode?: string;
12
12
  };
13
13
  }
14
+ declare const failedValidationRequestScenario: ValidationScenario;
14
15
  declare const validationScenarios: ValidationScenario[];
15
- export { validationScenarios };
16
+ export { validationScenarios, failedValidationRequestScenario };
16
17
  export type { ValidationScenario };
@@ -1,4 +1,14 @@
1
1
  import { ScaErrorCode, PARes } from '../types';
2
+ const failedValidationRequestScenario = {
3
+ description: 'Validation Request Failed',
4
+ threedsVersion: null,
5
+ reasonCode: null,
6
+ veresEnrolled: null,
7
+ pares: null,
8
+ outcome: {
9
+ success: false, // no liability shift
10
+ },
11
+ };
2
12
  const validationScenarios = [
3
13
  /***************************************************************/
4
14
  /********************** 3DS2 scenarios *************************/
@@ -121,4 +131,4 @@ const validationScenarios = [
121
131
  }
122
132
  },
123
133
  ];
124
- export { validationScenarios };
134
+ export { validationScenarios, failedValidationRequestScenario };
@@ -3,14 +3,15 @@ import { Environment } from "../shared/env";
3
3
  import * as sca from "../sca/types";
4
4
  import * as paypal from "../paypal/types";
5
5
  export type GatewayClientProps = {
6
- accessToken: string;
7
6
  username: string;
8
7
  environment?: Environment;
8
+ accessToken?: string;
9
9
  };
10
10
  declare class GatewayClient {
11
- client: AxiosInstance | null;
11
+ username: string;
12
12
  environment?: Environment;
13
- constructor({ accessToken, username, environment }: GatewayClientProps);
13
+ client: AxiosInstance;
14
+ constructor({ username, environment, accessToken }: GatewayClientProps);
14
15
  /**************** SCA/3DS2 /****************/
15
16
  createSCASession(data: sca.CreateSCASessionRequest): Promise<AxiosResponse>;
16
17
  decodeSCASession(data: sca.DecodeSCASessionRequest): Promise<AxiosResponse>;
@@ -7,18 +7,19 @@ 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 { RequestHeaderSdkVersion, RequestHeaderMerchantUsername, RequestTimeout, LongRequestTimeout, } from "./constants";
10
+ import { RequestHeaderSdkVersion, RequestHeaderMerchantUsername, RequestTimeout, LongRequestTimeout, LocalStorageAccessTokenKey, } from "./constants";
11
11
  import axios from "axios";
12
12
  import { getSdkVersionNumber } from "./util";
13
13
  import env, { Environment } from "../shared/env";
14
14
  class GatewayClient {
15
- constructor({ accessToken, username, environment }) {
15
+ constructor({ username, environment, accessToken }) {
16
+ this.username = username;
16
17
  this.environment = environment || Environment.sandbox;
17
18
  const headers = {};
18
19
  headers["Authorization"] = `Bearer ${accessToken}`;
19
20
  headers[RequestHeaderSdkVersion] = getSdkVersionNumber();
20
- headers[RequestHeaderMerchantUsername] = username;
21
- this.client = axios.create({
21
+ headers[RequestHeaderMerchantUsername] = this.username;
22
+ const client = axios.create({
22
23
  baseURL: env[this.environment].apiUrl,
23
24
  timeout: RequestTimeout,
24
25
  headers,
@@ -30,6 +31,13 @@ class GatewayClient {
30
31
  },
31
32
  ],
32
33
  });
34
+ client.interceptors.request.use(function (config) {
35
+ const localStorageAccessToken = window.localStorage.getItem(LocalStorageAccessTokenKey);
36
+ config.headers["Authorization"] = `Bearer ${accessToken || localStorageAccessToken}`;
37
+ // Do something before request is sent
38
+ return config;
39
+ });
40
+ this.client = client;
33
41
  }
34
42
  /**************** SCA/3DS2 /****************/
35
43
  createSCASession(data) {
@@ -55,7 +63,12 @@ class GatewayClient {
55
63
  }
56
64
  validateSCA(data) {
57
65
  return __awaiter(this, void 0, void 0, function* () {
58
- return this.client.post("/sca/validation", data);
66
+ return this.client.post("/sca/validation", data).then((response) => response).catch(err => {
67
+ if (err.response && err.response.status == 422) {
68
+ return err.response;
69
+ }
70
+ throw err;
71
+ });
59
72
  });
60
73
  }
61
74
  getCard(data) {
@@ -4,12 +4,16 @@ import * as sandbox from "./envs/sandbox";
4
4
  import * as production from "./envs/production";
5
5
  export declare enum Environment {
6
6
  local = "local",
7
+ test = "test",
8
+ development = "development",
7
9
  staging = "staging",
8
10
  sandbox = "sandbox",
9
11
  production = "production"
10
12
  }
11
13
  declare const env: {
14
+ test: typeof local;
12
15
  local: typeof local;
16
+ development: typeof local;
13
17
  staging: typeof staging;
14
18
  sandbox: typeof sandbox;
15
19
  production: typeof production;
@@ -5,12 +5,16 @@ import * as production from "./envs/production";
5
5
  export var Environment;
6
6
  (function (Environment) {
7
7
  Environment["local"] = "local";
8
+ Environment["test"] = "test";
9
+ Environment["development"] = "development";
8
10
  Environment["staging"] = "staging";
9
11
  Environment["sandbox"] = "sandbox";
10
12
  Environment["production"] = "production";
11
13
  })(Environment || (Environment = {}));
12
14
  const env = {
15
+ [Environment.test]: local,
13
16
  [Environment.local]: local,
17
+ [Environment.development]: local,
14
18
  [Environment.staging]: staging,
15
19
  [Environment.sandbox]: sandbox,
16
20
  [Environment.production]: production,
@@ -39,6 +39,7 @@ declare class PostMessageClient {
39
39
  private channel;
40
40
  private fzEnv;
41
41
  private target;
42
+ private domain;
42
43
  constructor(config: PostMessageClientConfig);
43
44
  setEventListeners(handlers: EventHandlers): void;
44
45
  setEventListenersLegacy(handlers: EventHandlers): void;
@@ -7,23 +7,20 @@ 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 { NODE_ENV } from '../shared/types';
11
- const domain = process.env.PAYNOW_BASE_URL;
12
- // NODE_ENV is introduced to PostMessageClient purely for the purpose of bypassing security
13
- // check on the postMessage event between parent and child frames. Unforunately there is
14
- // no workaround to override event origin due to lack of support in existing test framework.
10
+ import env, { Environment } from "./env";
15
11
  class PostMessageClient {
16
12
  constructor(config) {
17
13
  this.channel = config.channel;
18
- this.fzEnv = process.env.NODE_ENV;
14
+ this.fzEnv = process.env.API_ENV;
15
+ this.domain = env[this.fzEnv].payNowUrl;
19
16
  this.target = config.target;
20
17
  }
21
18
  // Handle event messages that conform to PostMessage format.
22
19
  setEventListeners(handlers) {
23
20
  window.addEventListener("message", (event) => __awaiter(this, void 0, void 0, function* () {
24
- const validationEnabled = ![NODE_ENV.TEST, NODE_ENV.LOCALDEV].includes(this.fzEnv);
21
+ const validationEnabled = ![Environment.test, Environment.local, Environment.development].includes(this.fzEnv);
25
22
  const isChannelValid = event.data.channel === this.channel;
26
- const isOriginValid = event.origin === domain;
23
+ const isOriginValid = event.origin === this.domain;
27
24
  if (validationEnabled && (!isOriginValid || !isChannelValid)) {
28
25
  console.log('[WARNING] unmatched event origin or incorrect message channel');
29
26
  return;
@@ -44,8 +41,8 @@ class PostMessageClient {
44
41
  // Handle event messages that do not conform to PostMessage format.
45
42
  setEventListenersLegacy(handlers) {
46
43
  window.addEventListener("message", (event) => {
47
- const validationEnabled = ![NODE_ENV.TEST, NODE_ENV.LOCALDEV].includes(this.fzEnv);
48
- const isOriginValid = event.origin === domain;
44
+ const validationEnabled = ![Environment.test, Environment.local, Environment.development].includes(this.fzEnv);
45
+ const isOriginValid = event.origin === this.domain;
49
46
  if (validationEnabled && !isOriginValid) {
50
47
  console.log('[WARNING] unmatched event origin or incorrect message channel');
51
48
  return;
@@ -63,7 +60,7 @@ class PostMessageClient {
63
60
  });
64
61
  }
65
62
  send(message) {
66
- this.target.contentWindow.postMessage(message, domain);
63
+ this.target.contentWindow.postMessage(message, this.domain);
67
64
  }
68
65
  }
69
66
  export { PostMessageClient, };
@@ -1,12 +1,5 @@
1
1
  import { PayPalPaymentMethod } from '../paypal/types';
2
2
  import { Environment } from './env';
3
- declare enum NODE_ENV {
4
- LOCALDEV = "localdev",
5
- PRODUCTION = "production",
6
- SANDBOX = "sandbox",
7
- STAGING = "staging",
8
- TEST = "test"
9
- }
10
3
  declare enum PublicEvent {
11
4
  FORM_VALIDATION_ERROR = "fz.form_validation.error",
12
5
  FORM_VALIDATION_SUCCESS = "fz.form_validation.success",
@@ -98,6 +91,7 @@ export type PaymentConfig = {
98
91
  };
99
92
  export type OptionalUrlValues = {
100
93
  hide_card_holder?: boolean;
94
+ hide_button?: boolean;
101
95
  return_path?: string;
102
96
  card_types?: Array<string>;
103
97
  surcharge_enabled?: string;
@@ -105,7 +99,6 @@ export type OptionalUrlValues = {
105
99
  css?: string;
106
100
  css_signature?: string;
107
101
  tokenize_only?: boolean;
108
- hide_button?: boolean;
109
102
  };
110
103
  declare global {
111
104
  interface Window {
@@ -149,5 +142,5 @@ type TokenizeCardResponse = {
149
142
  token: string;
150
143
  errors?: Array<string>;
151
144
  };
152
- export { BridgeEvent, PublicEvent, NODE_ENV, PaymentMethodType, };
145
+ export { BridgeEvent, PublicEvent, PaymentMethodType, };
153
146
  export type { PaymentMethod, PaymentIntent, Payment, Card, CardOnFile, CustomerSnakeCase, Customer, Handlers, ValidationResult, TokenizeCardResponse, };