@fat-zebra/sdk 1.5.10-beta.2 → 1.5.11-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.
@@ -0,0 +1 @@
1
+ export declare function logMethod(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
@@ -0,0 +1,35 @@
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 axios from 'axios';
11
+ import { getLoggerUsername, getTransactionReference } from "./logger-context";
12
+ export function logMethod(target, propertyKey, descriptor) {
13
+ const originalMethod = descriptor.value;
14
+ const LOGGING_ENDPOINT = `${process.env.PAYNOW_BASE_URL}/log_sdk`;
15
+ descriptor.value = function (...args) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ try {
18
+ const username = getLoggerUsername();
19
+ const reference = getTransactionReference();
20
+ axios.post(LOGGING_ENDPOINT, {
21
+ username,
22
+ reference,
23
+ method: propertyKey,
24
+ arguments: args,
25
+ timestamp: new Date().toISOString(),
26
+ });
27
+ }
28
+ catch (error) {
29
+ console.warn('Logging failed for sdk:', error);
30
+ }
31
+ return originalMethod.apply(this, args);
32
+ });
33
+ };
34
+ return descriptor;
35
+ }
package/dist/hpp/hpp.d.ts CHANGED
@@ -49,6 +49,7 @@ declare class Hpp {
49
49
  private headlessLoaded;
50
50
  private headlessPreviouslyLoaded;
51
51
  private iframeLoaded;
52
+ private newThreedsFlow;
52
53
  constructor(config: HppModuleConfig);
53
54
  setListenersAndEmitReady(): void;
54
55
  load(config: HppLoadParams): void;
package/dist/hpp/hpp.js CHANGED
@@ -1,9 +1,17 @@
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, 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 "../decorators";
14
+ import { setTransactionReference } from "../logger-context";
7
15
  const HPP_DEFAULT_OPTIONS = {
8
16
  enableSca: false,
9
17
  hideButton: false,
@@ -11,6 +19,7 @@ const HPP_DEFAULT_OPTIONS = {
11
19
  };
12
20
  class Hpp {
13
21
  constructor(config) {
22
+ this.newThreedsFlow = false;
14
23
  this.paymentIntent = config.paymentIntent;
15
24
  this.customer = config.customer;
16
25
  this.username = config.username;
@@ -26,19 +35,27 @@ class Hpp {
26
35
  });
27
36
  }
28
37
  setListenersAndEmitReady() {
38
+ const message = {
39
+ channel: 'sca',
40
+ subject: BridgeEvent.READY,
41
+ data: {}
42
+ };
29
43
  if (this.headlessLoaded && this.iframeLoaded) {
30
44
  // initial headless load
31
45
  this.setCrossFramesEventListeners();
32
46
  this.setPublicEventListeners();
33
47
  emit(PublicEvent.HPP_READY);
48
+ this.iframe.contentWindow.postMessage(message, '*');
34
49
  }
35
50
  else if (this.headlessPreviouslyLoaded && this.iframeLoaded) {
51
+ this.iframe.contentWindow.postMessage(message, '*');
36
52
  // subsequent iframe loads after headless has been previously loaded
37
53
  // this caters for the SPA scenario
38
54
  emit(PublicEvent.HPP_READY);
39
55
  }
40
56
  }
41
57
  load(config) {
58
+ setTransactionReference(config.paymentIntent.payment.reference);
42
59
  this.hppOptions = config.options;
43
60
  const { el, isExisting } = bridge.load2(process.env.PAYNOW_BRIDGE_URL);
44
61
  this.headless = el;
@@ -112,6 +129,10 @@ class Hpp {
112
129
  if (this.hppOptions.tokenizeOnly)
113
130
  return;
114
131
  if (this.hppOptions.enableSca) {
132
+ if (this.newThreedsFlow) {
133
+ console.log("New threeds flow for setCrossFramesEventListeners"); // call the newSca class from here
134
+ // I do not want to put a return statement here while this branch is not implemented yet.
135
+ }
115
136
  this.sca.run({
116
137
  cardToken: data.token,
117
138
  customer: this.customer,
@@ -171,6 +192,9 @@ class Hpp {
171
192
  data: data,
172
193
  });
173
194
  };
195
+ handlers[BridgeEvent.NEW_THREEDS_ENABLED] = (data) => {
196
+ this.newThreedsFlow = typeof data === "boolean" ? data : false;
197
+ };
174
198
  this.postMessageClient.setEventListeners(handlers);
175
199
  }
176
200
  setPublicEventListeners() {
@@ -184,6 +208,11 @@ class Hpp {
184
208
  on(PublicEvent.SCA_SUCCESS, handler);
185
209
  }
186
210
  createPurchase(extra = null) {
211
+ if (this.newThreedsFlow) {
212
+ // insert new functionality
213
+ console.log("New threeds flow for createPurchase");
214
+ // I do not want to put a return statement here while this branch is not implemented yet.
215
+ }
187
216
  const message = {
188
217
  channel: 'sca',
189
218
  subject: BridgeEvent.CREATE_PAYMENT_REQUEST,
@@ -204,4 +233,7 @@ class Hpp {
204
233
  this.headless.contentWindow.postMessage(message, '*');
205
234
  }
206
235
  }
236
+ __decorate([
237
+ logMethod
238
+ ], Hpp.prototype, "createPurchase", null);
207
239
  export { Hpp, HPP_DEFAULT_OPTIONS, };
@@ -0,0 +1,4 @@
1
+ export declare function setLoggerUsername(username: string): void;
2
+ export declare function setTransactionReference(reference: string): void;
3
+ export declare function getLoggerUsername(): string | undefined;
4
+ export declare function getTransactionReference(): string | undefined;
@@ -0,0 +1,14 @@
1
+ let globalLoggerUsername;
2
+ let globalTransactionReference;
3
+ export function setLoggerUsername(username) {
4
+ globalLoggerUsername = username;
5
+ }
6
+ export function setTransactionReference(reference) {
7
+ globalTransactionReference = reference;
8
+ }
9
+ export function getLoggerUsername() {
10
+ return globalLoggerUsername;
11
+ }
12
+ export function getTransactionReference() {
13
+ return globalTransactionReference;
14
+ }
package/dist/main.js CHANGED
@@ -19,8 +19,10 @@ import { Hpp } from './hpp';
19
19
  import ClickToPay from './click_to_pay';
20
20
  import { validateApplePayLoadParams } from "./validation/validators/apple-pay-load-params-button-validator";
21
21
  import { ApplePay } from "./applepay";
22
+ import { setLoggerUsername } from "./logger-context";
22
23
  export default class FatZebra {
23
24
  constructor(config) {
25
+ setLoggerUsername(config.username);
24
26
  this.fzConfig = config;
25
27
  window.MerchantUsername = config.username;
26
28
  this.gatewayClient = new GatewayClient({
@@ -32,7 +32,9 @@ declare enum BridgeEvent {
32
32
  FORM_VALIDATION_ERROR = "fzi.form_validation_error",
33
33
  FORM_VALIDATION_SUCCESS = "fzi.form_validation_success",
34
34
  BIN_LOOKUP = "fzi.bin_lookup",
35
- CLICK_TO_PAY_TOKENIZATION = "fzi.c2p.tc_res"
35
+ CLICK_TO_PAY_TOKENIZATION = "fzi.c2p.tc_res",
36
+ NEW_THREEDS_ENABLED = "fzi.new_threeds_enabled",
37
+ READY = "fzi.ready"
36
38
  }
37
39
  declare enum PaymentMethodType {
38
40
  CARD = "card",
@@ -34,6 +34,8 @@ var BridgeEvent;
34
34
  BridgeEvent["FORM_VALIDATION_SUCCESS"] = "fzi.form_validation_success";
35
35
  BridgeEvent["BIN_LOOKUP"] = "fzi.bin_lookup";
36
36
  BridgeEvent["CLICK_TO_PAY_TOKENIZATION"] = "fzi.c2p.tc_res";
37
+ BridgeEvent["NEW_THREEDS_ENABLED"] = "fzi.new_threeds_enabled";
38
+ BridgeEvent["READY"] = "fzi.ready";
37
39
  })(BridgeEvent || (BridgeEvent = {}));
38
40
  var PaymentMethodType;
39
41
  (function (PaymentMethodType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fat-zebra/sdk",
3
- "version": "1.5.10-beta.2",
3
+ "version": "1.5.11-beta.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "noImplicitAny": true,
7
7
  "module": "commonjs",
8
8
  "esModuleInterop": true,
9
+ "experimentalDecorators": true,
9
10
  "resolveJsonModule": true,
10
11
  "jsx": "react",
11
12
  "target": "es5",
@@ -10,6 +10,7 @@
10
10
  "module": "esnext",
11
11
  "moduleResolution": "node",
12
12
  "resolveJsonModule": true,
13
+ "experimentalDecorators": true,
13
14
  "target": "es6",
14
15
  "lib": [
15
16
  "esnext",