@fat-zebra/sdk 2.0.0 → 2.0.1-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/dist/hpp/hpp.js CHANGED
@@ -1,9 +1,16 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
1
7
  import * as bridge from '../shared/bridge-client';
2
8
  import { LocalStorageAccessTokenKey } from '../shared/constants';
3
9
  import { emit, off, on } from '../shared/event-manager';
4
10
  import { PostMessageClient } from '../shared/post-message-client';
5
11
  import { BridgeEvent, PublicEvent, } from '../shared/types';
6
12
  import * as util from '../shared/util';
13
+ import { logMethod } from "../logging/logMethod";
7
14
  import { setTransactionReference } from "../logging/logger-context";
8
15
  import ThreeDSecure from "../three_d_secure";
9
16
  const HPP_DEFAULT_OPTIONS = {
@@ -140,7 +147,8 @@ class Hpp {
140
147
  merchantUsername: this.username,
141
148
  cardToken: this.cardToken,
142
149
  test: this.test,
143
- challengeWindowSize: this.challengeWindowSize
150
+ challengeWindowSize: this.challengeWindowSize,
151
+ tokenizeOnly: false
144
152
  });
145
153
  return; // do not continue execution to old 3DS
146
154
  }
@@ -245,4 +253,7 @@ class Hpp {
245
253
  this.headless.contentWindow.postMessage(message, '*');
246
254
  }
247
255
  }
256
+ __decorate([
257
+ logMethod()
258
+ ], Hpp.prototype, "createPurchase", null);
248
259
  export { Hpp, HPP_DEFAULT_OPTIONS, };
package/dist/main.d.ts CHANGED
@@ -27,9 +27,10 @@ export default class FatZebra {
27
27
  private sca;
28
28
  private fzConfig;
29
29
  private gatewayClient;
30
+ private headless;
30
31
  constructor(config: FZConfig);
31
- tokenizeCard(card: Card, headless: HTMLIFrameElement): void;
32
- cardDidTokenize(headless: HTMLIFrameElement, callback: (data: any) => void): void;
32
+ tokenizeCard(card: Card): void;
33
+ cardDidTokenize(callback: (data: any) => void): void;
33
34
  verifyCard(params: VerifyCardParams): Promise<void>;
34
35
  renderPaymentsPage(params: HppLoadParams): void;
35
36
  renderApplePayButton(params: ApplePayParams): void;
package/dist/main.js CHANGED
@@ -27,6 +27,7 @@ import { validateApplePayLoadParams } from "./validation/validators/apple-pay-lo
27
27
  import { ApplePay } from "./applepay";
28
28
  import { setLoggerUsername } from "./logging/logger-context";
29
29
  import { logMethod } from "./logging/logMethod";
30
+ import ThreeDSecure from "./three_d_secure";
30
31
  export default class FatZebra {
31
32
  constructor(config) {
32
33
  setLoggerUsername(config.username);
@@ -40,29 +41,28 @@ export default class FatZebra {
40
41
  gatewayClient: this.gatewayClient,
41
42
  });
42
43
  this.sca.loadScript();
44
+ this.headless = bridge.load(process.env.PAYNOW_BRIDGE_URL);
43
45
  }
44
- tokenizeCard(card, headless) {
46
+ tokenizeCard(card) {
45
47
  const channel = 'sca';
46
- headless.onload = () => {
47
- const message = {
48
- channel,
49
- subject: BridgeEvent.TOKENIZE_CARD_REQUEST,
50
- data: {
51
- access_token: window.localStorage.getItem(LocalStorageAccessTokenKey),
52
- card_holder: card.holder,
53
- card_number: card.number,
54
- card_expiry: `${card.expiryMonth}/${card.expiryYear}`,
55
- cvv: card.cvv,
56
- }
57
- };
58
- headless.contentWindow.postMessage(message, '*');
48
+ const message = {
49
+ channel,
50
+ subject: BridgeEvent.TOKENIZE_CARD_REQUEST,
51
+ data: {
52
+ access_token: window.localStorage.getItem(LocalStorageAccessTokenKey),
53
+ card_holder: card.holder,
54
+ card_number: card.number,
55
+ card_expiry: `${card.expiryMonth}/${card.expiryYear}`,
56
+ cvv: card.cvv,
57
+ }
59
58
  };
59
+ this.headless.contentWindow.postMessage(message, '*');
60
60
  }
61
- cardDidTokenize(headless, callback) {
61
+ cardDidTokenize(callback) {
62
62
  const channel = 'sca';
63
63
  const postMessageClient = new PostMessageClient({
64
64
  channel,
65
- target: headless
65
+ target: this.headless
66
66
  });
67
67
  const handlers = {};
68
68
  handlers[BridgeEvent.TOKENIZE_CARD_RESPONSE] = (data) => {
@@ -81,35 +81,44 @@ export default class FatZebra {
81
81
  });
82
82
  return;
83
83
  }
84
+ const threeDSecure = new ThreeDSecure({
85
+ bridge: this.headless,
86
+ environment: process.env.API_ENV
87
+ });
84
88
  switch (params.paymentMethod.type) {
85
89
  case PaymentMethodType.CARD:
86
- const headless = bridge.load(process.env.PAYNOW_BRIDGE_URL);
87
90
  const card = params.paymentMethod.data;
88
- this.cardDidTokenize(headless, (data) => __awaiter(this, void 0, void 0, function* () {
91
+ this.cardDidTokenize((data) => __awaiter(this, void 0, void 0, function* () {
89
92
  var _a;
90
- const bin = card.number.substr(0, 6);
91
- this.sca.run({
92
- cardToken: data.token,
93
- customer: params.customer,
93
+ threeDSecure.run({
94
94
  paymentIntent: params.paymentIntent,
95
- bin,
95
+ cardToken: data.token,
96
+ merchantUsername: this.fzConfig.username,
96
97
  challengeWindowSize: (_a = params.options) === null || _a === void 0 ? void 0 : _a.challengeWindowSize,
98
+ test: this.fzConfig.test,
99
+ tokenizeOnly: true
97
100
  });
98
101
  }));
99
- this.tokenizeCard(card, headless);
102
+ this.tokenizeCard(card);
100
103
  break;
101
104
  case PaymentMethodType.CARD_ON_FILE:
102
105
  const cardToken = params.paymentMethod.data.token;
103
- const bin = (yield this.gatewayClient.getCard({ card_token: cardToken })).data.bin;
104
- this.sca.run({
105
- cardToken,
106
- customer: params.customer,
106
+ threeDSecure.run({
107
107
  paymentIntent: params.paymentIntent,
108
- bin,
108
+ cardToken: cardToken,
109
+ merchantUsername: this.fzConfig.username,
109
110
  challengeWindowSize: (_a = params.options) === null || _a === void 0 ? void 0 : _a.challengeWindowSize,
111
+ test: this.fzConfig.test,
112
+ tokenizeOnly: true
110
113
  });
111
114
  break;
112
115
  }
116
+ const channel = 'sca';
117
+ const postMessageClient = new PostMessageClient({
118
+ channel,
119
+ target: this.headless
120
+ });
121
+ postMessageClient.setEventListeners(threeDSecure.messageHandlers());
113
122
  });
114
123
  }
115
124
  renderPaymentsPage(params) {
@@ -44,7 +44,8 @@ const useMessage = ({ paymentIntent, options, handlers, sca, config }) => {
44
44
  paymentIntent,
45
45
  cardToken: data.token,
46
46
  merchantUsername: config.username,
47
- test: config.environment !== Environment.production
47
+ test: config.environment !== Environment.production,
48
+ tokenizeOnly: config.options.tokenize_only
48
49
  });
49
50
  return;
50
51
  }
@@ -20,14 +20,16 @@ declare class ThreeDSecure {
20
20
  private challengeWindowSize;
21
21
  private successCallback;
22
22
  private failureCallback;
23
+ private tokenizeOnly;
23
24
  private iframe?;
24
25
  constructor({ successCallback, failureCallback, environment, bridge, iframe }: ThreeDSecureConfig);
25
- run({ paymentIntent, cardToken, merchantUsername, challengeWindowSize, test }: {
26
+ run({ paymentIntent, cardToken, merchantUsername, challengeWindowSize, test, tokenizeOnly }: {
26
27
  paymentIntent: PaymentIntent;
27
28
  cardToken: string;
28
29
  merchantUsername: string;
29
30
  challengeWindowSize?: ChallengeWindowSize;
30
31
  test: boolean;
32
+ tokenizeOnly?: boolean;
31
33
  }): void;
32
34
  setupResponse(data: DeviceDataCollectionMessage): void;
33
35
  messageHandlers(): {
@@ -19,6 +19,7 @@ import { ChallengeWindowSize } from "../sca/types";
19
19
  import * as util from "../shared/util";
20
20
  class ThreeDSecure {
21
21
  constructor({ successCallback, failureCallback, environment, bridge, iframe }) {
22
+ this.tokenizeOnly = false;
22
23
  this.headlessBridge = bridge;
23
24
  this.environment = environment;
24
25
  this.successCallback = successCallback;
@@ -26,7 +27,8 @@ class ThreeDSecure {
26
27
  this.iframe = iframe;
27
28
  DeviceDataCollection.listenDataCollectionResponse(environment);
28
29
  }
29
- run({ paymentIntent, cardToken, merchantUsername, challengeWindowSize, test }) {
30
+ run({ paymentIntent, cardToken, merchantUsername, challengeWindowSize, test, tokenizeOnly }) {
31
+ this.tokenizeOnly = tokenizeOnly;
30
32
  this.setLoading();
31
33
  this.paymentIntent = paymentIntent;
32
34
  this.test = test;
@@ -124,6 +126,8 @@ class ThreeDSecure {
124
126
  if (scenario.outcome.success) {
125
127
  this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threeDSecureData);
126
128
  const extra = util.toObjectWithSnakeCaseKeys(threeDSecureData);
129
+ if (this.tokenizeOnly)
130
+ return; // DO NO process purchase if tokenizing only.
127
131
  this.createPurchase(extra);
128
132
  return;
129
133
  }
@@ -149,6 +153,8 @@ class ThreeDSecure {
149
153
  const extra = util.toObjectWithSnakeCaseKeys(threeDSecureData);
150
154
  if (scenario.outcome.success) {
151
155
  this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threeDSecureData);
156
+ if (this.tokenizeOnly)
157
+ return; // DO NO process purchase if tokenizing only.
152
158
  this.createPurchase(extra);
153
159
  }
154
160
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fat-zebra/sdk",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-beta.0",
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.13.5",
66
+ "axios": "1.15.0",
67
67
  "custom-event-polyfill": "^1.0.7",
68
68
  "glob": "^13.0.6",
69
69
  "ts-polyfill": "^3.8.2",