@fat-zebra/sdk 2.0.1-beta.5 → 2.0.1-beta.8

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/dist/hpp/hpp.d.ts CHANGED
@@ -13,7 +13,7 @@ interface HppModuleConfig {
13
13
  username: string;
14
14
  sca: Sca;
15
15
  threeDSecure: ThreeDSecure;
16
- isThreeDSecureEnabled: () => boolean;
16
+ requestThreeDSEnabled: () => Promise<boolean>;
17
17
  test?: boolean;
18
18
  }
19
19
  interface HppLoadParams {
@@ -54,12 +54,13 @@ declare class Hpp {
54
54
  private headlessPreviouslyLoaded;
55
55
  private iframeLoaded;
56
56
  private isThreeDSecureEnabled;
57
+ private requestThreeDSEnabled;
57
58
  private challengeWindowSize;
58
59
  private scaHandler;
59
60
  private crossFrameListenersBound;
60
61
  private publicEventListenersBound;
61
62
  constructor(config: HppModuleConfig);
62
- setListenersAndEmitReady(): void;
63
+ setListenersAndEmitReady(): Promise<void>;
63
64
  load(config: HppLoadParams): void;
64
65
  purchase(): void;
65
66
  getPayNowUrl(options?: {
package/dist/hpp/hpp.js CHANGED
@@ -4,6 +4,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
7
16
  import * as bridge from '../shared/bridge-client';
8
17
  import { LocalStorageAccessTokenKey } from '../shared/constants';
9
18
  import { emit, off, on } from '../shared/event-manager';
@@ -21,6 +30,7 @@ const HPP_DEFAULT_OPTIONS = {
21
30
  };
22
31
  class Hpp {
23
32
  constructor(config) {
33
+ this.isThreeDSecureEnabled = false;
24
34
  this.paymentIntent = config.paymentIntent;
25
35
  this.customer = config.customer;
26
36
  this.username = config.username;
@@ -31,7 +41,7 @@ class Hpp {
31
41
  this.headlessPreviouslyLoaded = false;
32
42
  this.iframeLoaded = false;
33
43
  this.threeDSecure = config.threeDSecure;
34
- this.isThreeDSecureEnabled = config.isThreeDSecureEnabled;
44
+ this.requestThreeDSEnabled = config.requestThreeDSEnabled;
35
45
  this.crossFrameListenersBound = false;
36
46
  this.publicEventListenersBound = false;
37
47
  configureLogger({
@@ -39,26 +49,30 @@ class Hpp {
39
49
  });
40
50
  }
41
51
  setListenersAndEmitReady() {
42
- if (!this.crossFrameListenersBound) {
43
- this.setCrossFramesEventListeners();
44
- this.crossFrameListenersBound = true;
45
- }
46
- if (this.headlessLoaded && this.iframeLoaded) {
47
- if (!this.publicEventListenersBound && !this.isThreeDSecureEnabled()) {
48
- this.setPublicEventListeners();
49
- this.publicEventListenersBound = true;
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ if (!this.crossFrameListenersBound) {
54
+ this.setCrossFramesEventListeners();
55
+ this.crossFrameListenersBound = true;
50
56
  }
51
- emit(PublicEvent.HPP_READY);
52
- }
53
- else if (this.headlessPreviouslyLoaded && this.iframeLoaded) {
54
- // subsequent iframe loads after headless has been previously loaded
55
- // this caters for the SPA scenario
56
- if (!this.publicEventListenersBound && !this.isThreeDSecureEnabled()) {
57
- this.setPublicEventListeners();
58
- this.publicEventListenersBound = true;
57
+ if (this.headlessLoaded && this.iframeLoaded) {
58
+ this.isThreeDSecureEnabled = yield this.requestThreeDSEnabled();
59
+ if (!this.publicEventListenersBound && !this.isThreeDSecureEnabled) {
60
+ this.setPublicEventListeners();
61
+ this.publicEventListenersBound = true;
62
+ }
63
+ emit(PublicEvent.HPP_READY);
59
64
  }
60
- emit(PublicEvent.HPP_READY);
61
- }
65
+ else if (this.headlessPreviouslyLoaded && this.iframeLoaded) {
66
+ this.isThreeDSecureEnabled = yield this.requestThreeDSEnabled();
67
+ // subsequent iframe loads after headless has been previously loaded
68
+ // this caters for the SPA scenario
69
+ if (!this.publicEventListenersBound && !this.isThreeDSecureEnabled) {
70
+ this.setPublicEventListeners();
71
+ this.publicEventListenersBound = true;
72
+ }
73
+ emit(PublicEvent.HPP_READY);
74
+ }
75
+ });
62
76
  }
63
77
  load(config) {
64
78
  var _a;
@@ -74,10 +88,10 @@ class Hpp {
74
88
  channel: 'sca',
75
89
  target: this.iframe
76
90
  });
77
- this.headless.onload = () => {
91
+ this.headless.addEventListener('load', () => {
78
92
  this.headlessLoaded = true;
79
93
  this.setListenersAndEmitReady();
80
- };
94
+ });
81
95
  this.iframe.onload = () => {
82
96
  this.iframeLoaded = true;
83
97
  this.setListenersAndEmitReady();
@@ -145,7 +159,7 @@ class Hpp {
145
159
  if (this.hppOptions.tokenizeOnly)
146
160
  return;
147
161
  if (this.hppOptions.enableSca) {
148
- if (this.isThreeDSecureEnabled()) {
162
+ if (this.isThreeDSecureEnabled) {
149
163
  this.threeDSecure.run({
150
164
  paymentIntent: this.paymentIntent,
151
165
  merchantUsername: this.username,
package/dist/main.d.ts CHANGED
@@ -29,7 +29,6 @@ export default class FatZebra {
29
29
  private gatewayClient;
30
30
  private headless;
31
31
  private threeDSecure;
32
- private threeDSEnabled;
33
32
  private threeDSecureListenersBound;
34
33
  constructor(config: FZConfig);
35
34
  tokenizeCard(card: Card): void;
@@ -37,7 +36,7 @@ export default class FatZebra {
37
36
  private requestThreeDSEnabled;
38
37
  verifyCard(params: VerifyCardParams): Promise<void>;
39
38
  setThreeDSecureListeners(): void;
40
- renderPaymentsPage(params: HppLoadParams): Promise<void>;
39
+ renderPaymentsPage(params: HppLoadParams): void;
41
40
  renderApplePayButton(params: ApplePayParams): void;
42
41
  renderClickToPay(params: HppClickToPayParams): void;
43
42
  reportThreeDSecureFetchedOnInit(data: any): void;
package/dist/main.js CHANGED
@@ -30,7 +30,6 @@ import { logMethod } from './logging/logMethod';
30
30
  import ThreeDSecure from './three_d_secure';
31
31
  export default class FatZebra {
32
32
  constructor(config) {
33
- this.threeDSEnabled = false;
34
33
  this.threeDSecureListenersBound = false;
35
34
  setLoggerUsername(config.username);
36
35
  this.fzConfig = config;
@@ -53,9 +52,9 @@ export default class FatZebra {
53
52
  this.setThreeDSecureListeners();
54
53
  }
55
54
  else {
56
- this.headless.onload = () => {
55
+ this.headless.addEventListener('load', () => {
57
56
  this.setThreeDSecureListeners();
58
- };
57
+ });
59
58
  }
60
59
  const message = {
61
60
  channel: 'sca',
@@ -106,7 +105,6 @@ export default class FatZebra {
106
105
  if (!resolved) {
107
106
  this.reportThreeDSecureFetched(data, paymentIntent);
108
107
  resolved = true;
109
- this.threeDSEnabled = enabled;
110
108
  resolve(enabled);
111
109
  }
112
110
  },
@@ -124,15 +122,17 @@ export default class FatZebra {
124
122
  if (!resolved) {
125
123
  this.reportRequestThreedsEnabledTimeout(paymentIntent);
126
124
  resolved = true;
127
- this.threeDSEnabled = false;
128
125
  resolve(false);
129
126
  }
130
- }, 5000);
127
+ }, 1000);
131
128
  });
132
129
  }
133
130
  verifyCard(params) {
134
131
  return __awaiter(this, void 0, void 0, function* () {
135
132
  var _a, _b;
133
+ if (!this.threeDSecureListenersBound) {
134
+ this.setThreeDSecureListeners();
135
+ }
136
136
  const valid = validateVerifyCardParams(params);
137
137
  if (!valid) {
138
138
  emit(PublicEvent.VALIDATION_ERROR, {
@@ -213,49 +213,33 @@ export default class FatZebra {
213
213
  target: this.headless,
214
214
  });
215
215
  const handlers = this.threeDSecure.messageHandlers();
216
- handlers[BridgeEvent.THREE_D_SECURE_ENABLED] = (data) => {
217
- this.reportThreeDSecureFetchedOnInit(data);
218
- this.threeDSEnabled = typeof data === 'boolean' ? data : false;
219
- };
220
216
  postMessageClient.setEventListeners(handlers);
221
- const message = {
222
- channel,
223
- subject: 'fzi.is-enabled-three-d-secure-req',
224
- data: {
225
- merchant: this.fzConfig.username,
226
- access_token: window.localStorage.getItem(LocalStorageAccessTokenKey),
227
- },
228
- };
229
- postMessageClient.send(message);
230
217
  }
231
218
  renderPaymentsPage(params) {
232
- return __awaiter(this, void 0, void 0, function* () {
233
- var _a;
234
- console.log('renderPaymentsPage');
235
- const valid = validateHppLoadParams(params);
236
- if (!valid) {
237
- emit(PublicEvent.VALIDATION_ERROR, {
238
- errors: toHumanizedErrors(validateHppLoadParams.errors),
239
- data: null,
240
- });
241
- return;
242
- }
243
- yield this.requestThreeDSEnabled(params.paymentIntent);
244
- if ((_a = window.HPP) === null || _a === void 0 ? void 0 : _a.destroy) {
245
- window.HPP.destroy();
246
- }
247
- window.HPP = new Hpp({
248
- version: params.version,
249
- paymentIntent: params.paymentIntent,
250
- customer: params.customer,
251
- username: this.fzConfig.username,
252
- sca: this.sca,
253
- test: this.fzConfig.test,
254
- threeDSecure: this.threeDSecure,
255
- isThreeDSecureEnabled: () => this.threeDSEnabled,
219
+ var _a;
220
+ console.log('renderPaymentsPage');
221
+ const valid = validateHppLoadParams(params);
222
+ if (!valid) {
223
+ emit(PublicEvent.VALIDATION_ERROR, {
224
+ errors: toHumanizedErrors(validateHppLoadParams.errors),
225
+ data: null,
256
226
  });
257
- window.HPP.load(params);
227
+ return;
228
+ }
229
+ if ((_a = window.HPP) === null || _a === void 0 ? void 0 : _a.destroy) {
230
+ window.HPP.destroy();
231
+ }
232
+ window.HPP = new Hpp({
233
+ version: params.version,
234
+ paymentIntent: params.paymentIntent,
235
+ customer: params.customer,
236
+ username: this.fzConfig.username,
237
+ sca: this.sca,
238
+ test: this.fzConfig.test,
239
+ threeDSecure: this.threeDSecure,
240
+ requestThreeDSEnabled: () => this.requestThreeDSEnabled(),
258
241
  });
242
+ window.HPP.load(params);
259
243
  }
260
244
  renderApplePayButton(params) {
261
245
  const valid = validateApplePayLoadParams(params);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fat-zebra/sdk",
3
- "version": "2.0.1-beta.5",
3
+ "version": "2.0.1-beta.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -63,7 +63,7 @@
63
63
  "ajv": "^8.17.1",
64
64
  "ajv-formats": "^3.0.1",
65
65
  "ajv-keywords": "^5.1.0",
66
- "axios": "1.15.0",
66
+ "axios": "1.16.0",
67
67
  "custom-event-polyfill": "^1.0.7",
68
68
  "glob": "^13.0.6",
69
69
  "ts-polyfill": "^3.8.2",