@fat-zebra/sdk 1.4.15 → 1.5.1

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/main.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Customer, PaymentIntent, PaymentMethod, PublicEvent } from './shared/types';
2
2
  import { HppLoadParams } from './hpp';
3
- import { PayPalConfig } from './paypal/types';
4
3
  import { ChallengeWindowSize } from './sca/types';
4
+ import { HppClickToPayParams } from './click_to_pay/types';
5
5
  export interface FZConfig {
6
6
  username: string;
7
7
  test?: boolean;
@@ -31,8 +31,10 @@ export default class FatZebra {
31
31
  cardDidTokenize(headless: HTMLIFrameElement, callback: (data: any) => void): void;
32
32
  verifyCard(params: VerifyCardParams): Promise<void>;
33
33
  renderPaymentsPage(params: HppLoadParams): void;
34
+ renderClickToPay(params: HppClickToPayParams): void;
34
35
  checkout(): void;
35
- setupPayPal(config: PayPalConfig): void;
36
36
  on(event: PublicEvent, callback: (e: any) => void): void;
37
+ off(event: PublicEvent, callback: (e: any) => void): void;
38
+ onOnce(event: PublicEvent, callback: (e: any) => void): void;
37
39
  }
38
40
  export { type HppLoadParams, FatZebra, };
package/dist/main.js CHANGED
@@ -11,12 +11,12 @@ import Sca from './sca';
11
11
  import { PostMessageClient, } from './shared/post-message-client';
12
12
  import { BridgeEvent, PaymentMethodType, PublicEvent, } from './shared/types';
13
13
  import { LocalStorageAccessTokenKey } from './shared/constants';
14
- import { emit, on } from './shared/event-manager';
14
+ import { emit, on, off, onOnce } from './shared/event-manager';
15
15
  import * as bridge from './shared/bridge-client';
16
- import { validateHppLoadParams, validateVerifyCardParams, toHumanizedErrors, } from './validation';
16
+ import { validateHppLoadParams, validateVerifyCardParams, toHumanizedErrors, validateClickToPayLoadParams, } from './validation';
17
17
  import GatewayClient from './shared/api-gateway-client';
18
18
  import { Hpp } from './hpp';
19
- import { PayPalCheckout } from './paypal/paypal-checkout';
19
+ import ClickToPay from './click_to_pay';
20
20
  export default class FatZebra {
21
21
  constructor(config) {
22
22
  this.fzConfig = config;
@@ -120,29 +120,33 @@ export default class FatZebra {
120
120
  });
121
121
  window.HPP.load(params);
122
122
  }
123
- checkout() {
124
- window.HPP.purchase();
125
- }
126
- setupPayPal(config) {
127
- const paypalCheckout = new PayPalCheckout({
128
- currency: config.currency,
129
- payment: config.payment,
130
- containerId: config.containerId,
131
- style: config.style
132
- });
133
- paypalCheckout.load()
134
- .then(function () {
135
- paypalCheckout.render();
136
- })
137
- .catch(function (error) {
138
- emit(PublicEvent.PAYPAL_ERROR, {
139
- errors: [error].flat(),
123
+ renderClickToPay(params) {
124
+ const valid = validateClickToPayLoadParams(params);
125
+ if (!valid) {
126
+ emit(PublicEvent.VALIDATION_ERROR, {
127
+ errors: toHumanizedErrors(validateClickToPayLoadParams.errors),
140
128
  data: null
141
129
  });
130
+ return;
131
+ }
132
+ window.HPP = new ClickToPay({
133
+ paymentIntent: params.paymentIntent,
134
+ username: this.fzConfig.username,
135
+ test: this.fzConfig.test,
142
136
  });
137
+ window.HPP.load(params);
138
+ }
139
+ checkout() {
140
+ window.HPP.purchase();
143
141
  }
144
142
  on(event, callback) {
145
143
  on(event, callback);
146
144
  }
145
+ off(event, callback) {
146
+ off(event, callback);
147
+ }
148
+ onOnce(event, callback) {
149
+ onOnce(event, callback);
150
+ }
147
151
  }
148
152
  export { FatZebra, };
@@ -5,5 +5,5 @@ type FrameProps = {
5
5
  config: FatZebra.PaymentConfig;
6
6
  iframeProps?: HTMLProps<HTMLIFrameElement>;
7
7
  };
8
- declare const Frame: ({ handlers, config, iframeProps }: FrameProps) => React.JSX.Element;
9
- export default Frame;
8
+ declare const VerifyCard: ({ handlers, config, iframeProps }: FrameProps) => React.JSX.Element;
9
+ export default VerifyCard;
@@ -1,11 +1,11 @@
1
1
  import React from "react";
2
2
  import useFatZebra from "./useFatZebra";
3
- const Frame = ({ handlers, config, iframeProps }) => {
4
- const { url } = useFatZebra({
3
+ const VerifyCard = ({ handlers, config, iframeProps }) => {
4
+ const { paymentUrl } = useFatZebra({
5
5
  config,
6
6
  handlers: handlers,
7
7
  });
8
8
  return (React.createElement("div", null,
9
- React.createElement("iframe", Object.assign({ src: url, title: "verification-form" }, iframeProps))));
9
+ React.createElement("iframe", Object.assign({ src: paymentUrl, "data-test-id": "verify-card", title: "verification-form" }, iframeProps))));
10
10
  };
11
- export default Frame;
11
+ export default VerifyCard;
@@ -0,0 +1,10 @@
1
+ import React, { HTMLProps } from "react";
2
+ import * as FatZebra from "../shared/types";
3
+ type FrameProps = {
4
+ handlers: FatZebra.Handlers;
5
+ config: FatZebra.PaymentConfig;
6
+ iframeProps?: HTMLProps<HTMLIFrameElement>;
7
+ cardToken: string;
8
+ };
9
+ declare const VerifyExistingCard: ({ handlers, cardToken, config, iframeProps }: FrameProps) => React.JSX.Element;
10
+ export default VerifyExistingCard;
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import useFatZebra from "./useFatZebra";
3
+ const VerifyExistingCard = ({ handlers, cardToken, config, iframeProps }) => {
4
+ const { verifyUrl } = useFatZebra({
5
+ config,
6
+ cardToken,
7
+ handlers: handlers,
8
+ });
9
+ return (React.createElement("div", null,
10
+ React.createElement("iframe", Object.assign({ src: verifyUrl, "data-test-id": "verify-existing-card", title: "verification-form" }, iframeProps))));
11
+ };
12
+ export default VerifyExistingCard;
@@ -1,3 +1,4 @@
1
1
  import VerifyCard from "./VerifyCard";
2
+ import VerifyExistingCard from "./VerifyExistingCard";
2
3
  import submitForm from "./submitForm";
3
- export { VerifyCard, submitForm };
4
+ export { VerifyCard, VerifyExistingCard, submitForm };
@@ -1,3 +1,4 @@
1
1
  import VerifyCard from "./VerifyCard";
2
+ import VerifyExistingCard from "./VerifyExistingCard";
2
3
  import submitForm from "./submitForm";
3
- export { VerifyCard, submitForm };
4
+ export { VerifyCard, VerifyExistingCard, submitForm };
@@ -0,0 +1,12 @@
1
+ import { Environment } from "../shared/env";
2
+ import { OptionalUrlValues } from '../shared/types';
3
+ type RequiredURLValues = {
4
+ merchant: string;
5
+ hash: string;
6
+ reference: string;
7
+ amount: number;
8
+ currency: string;
9
+ };
10
+ type UrlValues = RequiredURLValues & OptionalUrlValues;
11
+ declare const generatePaymentURL: (values: UrlValues, environment?: Environment) => string;
12
+ export { generatePaymentURL };
@@ -0,0 +1,33 @@
1
+ import { parseTemplate } from 'url-template';
2
+ import env, { Environment } from "../shared/env";
3
+ const generatePaymentURL = (values, environment) => {
4
+ const queryParts = [
5
+ "tokenize_only",
6
+ "css",
7
+ "css_signature",
8
+ "iframe",
9
+ "postmessage",
10
+ "hide_card_holder",
11
+ "hide_button",
12
+ "sca_enabled",
13
+ ];
14
+ const environmentConfig = env[environment || Environment.sandbox];
15
+ const urlTemplate = parseTemplate(`${environmentConfig.payNowUrl}/sdk/v3/{merchant}/{reference}/{currency}/{amount}/{verification}{?${queryParts.join(",")}}`);
16
+ const url = urlTemplate.expand({
17
+ merchant: values.merchant,
18
+ reference: values.reference,
19
+ currency: values.currency,
20
+ amount: values.amount,
21
+ verification: values.hash,
22
+ sca_enabled: values.sca_enabled,
23
+ css: values.css,
24
+ css_signature: values.css_signature,
25
+ iframe: true,
26
+ postmessage: true,
27
+ tokenize_only: values.tokenize_only,
28
+ hide_card_holder: values.hide_card_holder,
29
+ hide_button: values.hide_button,
30
+ });
31
+ return url;
32
+ };
33
+ export { generatePaymentURL };
@@ -2,8 +2,10 @@ import * as FatZebra from "../shared/types";
2
2
  type UseFatZebraProps = {
3
3
  handlers: FatZebra.Handlers;
4
4
  config: FatZebra.PaymentConfig;
5
+ cardToken?: string;
5
6
  };
6
- declare const useFatZebra: ({ config, handlers }: UseFatZebraProps) => {
7
- url: string;
7
+ declare const useFatZebra: ({ config, handlers, cardToken }: UseFatZebraProps) => {
8
+ paymentUrl: string;
9
+ verifyUrl: string;
8
10
  };
9
11
  export default useFatZebra;
@@ -1,9 +1,10 @@
1
1
  import { useEffect, useMemo } from "react";
2
2
  import * as FatZebra from "../shared/types";
3
- import { generatePaymentURL } from "./url";
3
+ import { generatePaymentURL } from "./paymentUrl";
4
4
  import Sca from "../sca";
5
5
  import GatewayClient from "../shared/api-gateway-client";
6
- const useFatZebra = ({ config, handlers }) => {
6
+ import { generateVerifyURL } from "./verifyUrl";
7
+ const useFatZebra = ({ config, handlers, cardToken }) => {
7
8
  const { options, accessToken, paymentIntent, username } = config;
8
9
  const sca = useMemo(() => {
9
10
  const gatewayClient = new GatewayClient({ accessToken, username, environment: config.environment });
@@ -68,9 +69,10 @@ const useFatZebra = ({ config, handlers }) => {
68
69
  return () => {
69
70
  window.removeEventListener("message", messageHandler);
70
71
  };
71
- }, []);
72
+ }, [paymentIntent]);
72
73
  const payment = paymentIntent.payment;
73
- const url = generatePaymentURL(Object.assign({ merchant: username, reference: payment.reference, amount: payment.amount, currency: payment.currency, hash: paymentIntent.verification }, options), config.environment);
74
- return { url };
74
+ const verifyUrl = generateVerifyURL(Object.assign({ token: cardToken, verification: paymentIntent.verification, merchant: username }, options), config.environment);
75
+ const paymentUrl = generatePaymentURL(Object.assign({ merchant: username, reference: payment.reference, amount: payment.amount, currency: payment.currency, hash: paymentIntent.verification }, options), config.environment);
76
+ return { paymentUrl, verifyUrl };
75
77
  };
76
78
  export default useFatZebra;
@@ -0,0 +1,8 @@
1
+ import { Environment } from "../shared/env";
2
+ type RequiredURLValues = {
3
+ token: string;
4
+ verification: string;
5
+ merchant: string;
6
+ };
7
+ declare const generateVerifyURL: (values: RequiredURLValues, environment?: Environment) => string;
8
+ export { generateVerifyURL };
@@ -0,0 +1,22 @@
1
+ import { parseTemplate } from 'url-template';
2
+ import env, { Environment } from "../shared/env";
3
+ const generateVerifyURL = (values, environment) => {
4
+ const queryParts = [
5
+ "hide_button",
6
+ "iframe",
7
+ "verification",
8
+ "username",
9
+ "cardToken"
10
+ ];
11
+ const environmentConfig = env[environment || Environment.sandbox];
12
+ const urlTemplate = parseTemplate(`${environmentConfig.payNowUrl}/sdk/v3/verify{?${queryParts.join(",")}}`);
13
+ const url = urlTemplate.expand({
14
+ cardToken: values.token,
15
+ verification: values.verification,
16
+ username: values.merchant,
17
+ iframe: true,
18
+ hide_button: true
19
+ });
20
+ return url;
21
+ };
22
+ export { generateVerifyURL };
@@ -1,10 +1,3 @@
1
- interface CardinalConfig {
2
- timeout?: number;
3
- maxRequestRetries?: number;
4
- logging?: {
5
- level: 'on' | 'off' | 'verbose';
6
- };
7
- }
8
1
  interface CardinalSetupCompleteResponseData {
9
2
  sessionId: string;
10
3
  modules: {
@@ -16,12 +9,20 @@ interface PaymentValidatedDTO {
16
9
  processorTransactionId: string;
17
10
  jwt: string;
18
11
  }
12
+ export declare const defaultConfig: {
13
+ timeout: number;
14
+ maxRequestRetries: number;
15
+ logging: {
16
+ level: string;
17
+ };
18
+ };
19
19
  export default class CardinalManager {
20
- private cardinal;
21
- constructor(config?: CardinalConfig);
20
+ private retries;
21
+ constructor(retries?: Array<number>);
22
+ configure(retryCount?: number, lastError?: string): Promise<any>;
22
23
  setup(jwt: any): void;
23
24
  onPaymentValidated(handler: (data: PaymentValidatedDTO, error: string) => void): void;
24
- onPaymentSetupComplete(): Promise<CardinalSetupCompleteResponseData>;
25
+ onPaymentSetupComplete(callback: (data: CardinalSetupCompleteResponseData) => void): void;
25
26
  processBin(bin: string): Promise<any>;
26
27
  continue(acsUrl: string, pareq: string, transactionId: string): void;
27
28
  }
@@ -17,22 +17,45 @@ var CardinalPaymentEvent;
17
17
  CardinalPaymentEvent["SETUP_COMPLETE"] = "payments.setupComplete";
18
18
  CardinalPaymentEvent["VALIDATED"] = "payments.validated";
19
19
  })(CardinalPaymentEvent || (CardinalPaymentEvent = {}));
20
- const defaultConfig = {
20
+ export const defaultConfig = {
21
21
  timeout: 8000,
22
22
  maxRequestRetries: 3,
23
23
  logging: {
24
- level: 'on'
24
+ level: 'verbose'
25
25
  }
26
26
  };
27
27
  export default class CardinalManager {
28
- constructor(config) {
29
- window.Cardinal.configure((config ? config : defaultConfig));
28
+ constructor(retries) {
29
+ this.retries = retries || [10, 100, 1000, 5000, 10000];
30
+ }
31
+ // https://www.bayanbennett.com/posts/retrying-and-exponential-backoff-with-promises/
32
+ // Attempts 5 times to setup Cardinal.
33
+ // 10ms, 100ms, 1s, 5s, 10s.
34
+ // Cardinal may take a while to load, for example if the user is on a slow connection (train in a tunnel, for example)
35
+ configure(retryCount, lastError) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ retryCount || (retryCount = 1);
38
+ const delayMs = this.retries[retryCount - 1];
39
+ const delay = (delayMs) => new Promise(resolve => setTimeout(resolve, delayMs));
40
+ if (retryCount > 5)
41
+ throw new Error(lastError);
42
+ try {
43
+ console.log("Attempting to load Cardinal", { retryCount, delay: delayMs });
44
+ window.Cardinal.configure(defaultConfig);
45
+ }
46
+ catch (error) {
47
+ yield delay(delayMs);
48
+ yield this.configure(retryCount + 1, error);
49
+ }
50
+ });
30
51
  }
31
52
  setup(jwt) {
53
+ console.log("CARDINAL SETUP", jwt);
32
54
  window.Cardinal.setup(CardinalWorkflow.INIT, { jwt });
33
55
  }
34
56
  onPaymentValidated(handler) {
35
57
  window.Cardinal.on('payments.validated', (data, jwt) => {
58
+ window.Cardinal.off('payments.validated');
36
59
  if (data.ErrorDescription.toLowerCase() === 'success') {
37
60
  handler({
38
61
  processorTransactionId: data.Payment.ProcessorTransactionId,
@@ -44,11 +67,10 @@ export default class CardinalManager {
44
67
  }
45
68
  });
46
69
  }
47
- onPaymentSetupComplete() {
48
- return new Promise((resolve, reject) => {
49
- window.Cardinal.on(CardinalPaymentEvent.SETUP_COMPLETE, (data) => {
50
- resolve(data);
51
- });
70
+ onPaymentSetupComplete(callback) {
71
+ window.Cardinal.on(CardinalPaymentEvent.SETUP_COMPLETE, (data) => {
72
+ window.Cardinal.off(CardinalPaymentEvent.SETUP_COMPLETE);
73
+ callback(data);
52
74
  });
53
75
  }
54
76
  processBin(bin) {
@@ -36,6 +36,9 @@ declare class Sca {
36
36
  reportFailure(message: string, data?: any): void;
37
37
  reportSuccess(message: string, data: any): void;
38
38
  run(config: ScaRunProps): Promise<void>;
39
+ perform3DS({ sessionID }: {
40
+ sessionID: string;
41
+ }): Promise<void>;
39
42
  createCardinalJWT(): Promise<string>;
40
43
  check3DSEnrollment(): Promise<void>;
41
44
  customerProperties(customer: Customer): CustomerSnakeCase;
package/dist/sca/index.js CHANGED
@@ -64,6 +64,7 @@ class Sca {
64
64
  try {
65
65
  if (!this._cardinal) {
66
66
  this._cardinal = new CardinalManager();
67
+ yield this._cardinal.configure();
67
68
  }
68
69
  }
69
70
  catch (error) {
@@ -85,53 +86,58 @@ class Sca {
85
86
  this.reportFailure('FatZebra.3DS: JWT creation failed.');
86
87
  return;
87
88
  }
88
- // Init cardinal
89
- this._cardinal.setup(cardinalJwt);
90
- if (!this.sessionId) {
91
- const paymentsSetupCompleteResponse = yield this._cardinal.onPaymentSetupComplete();
89
+ this._cardinal.onPaymentSetupComplete((paymentsSetupCompleteResponse) => __awaiter(this, void 0, void 0, function* () {
92
90
  this.sessionId = paymentsSetupCompleteResponse.sessionId;
93
- // Register handler. Called after OTP is entered on challenge prompt.
94
- this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
95
- var _a;
96
- if (typeof error == 'string') {
97
- this.reportFailure(`FatZebra.3DS: Validation failed. ${error}.`);
98
- return;
99
- }
100
- const decodeSCASessionResponse = (yield this.gatewayClient.decodeSCASession({
101
- token: data.jwt
102
- })).data;
103
- if (data.processorTransactionId !== decodeSCASessionResponse.processor_transaction_id) {
104
- this.reportFailure("FatZebra.3DS: Validation failed. Invalid process transaction id.");
105
- }
106
- let validateSCAResponse;
107
- try {
108
- const requestParams = {
109
- amount: this.paymentIntent.payment.amount,
110
- authentication_transaction_id: this.enrollmentResult.authentication_transaction_id,
111
- card_token: this.cardToken,
112
- currency: this.paymentIntent.payment.currency,
113
- pareq: this.enrollmentResult.pareq,
114
- reference: this.paymentIntent.payment.reference,
115
- };
116
- validateSCAResponse = (yield this.gatewayClient.validateSCA(requestParams)).data;
117
- }
118
- catch (errorResponse) {
119
- this.reportFailure('FatZebra.3DS: Validation failed. Server error.');
120
- return;
121
- }
122
- const threedsData = threedsResponseData(validateSCAResponse);
123
- const scenario = getValidationResult(validateSCAResponse);
124
- if (scenario.outcome.success) {
125
- this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
126
- }
127
- else {
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}`, {
130
- errorCode: scenario.outcome.errorCode,
131
- });
132
- }
133
- }));
134
- }
91
+ this.perform3DS({ sessionID: paymentsSetupCompleteResponse.sessionId });
92
+ }));
93
+ console.log("CARDINAL SETUP GOES HERE");
94
+ this._cardinal.setup(cardinalJwt);
95
+ });
96
+ }
97
+ perform3DS({ sessionID }) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ this.sessionId = sessionID;
100
+ // Register handler. Called after OTP is entered on challenge prompt.
101
+ this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
102
+ var _a;
103
+ if (typeof error == 'string') {
104
+ this.reportFailure(`FatZebra.3DS: Validation failed. ${error}.`);
105
+ return;
106
+ }
107
+ const decodeSCASessionResponse = (yield this.gatewayClient.decodeSCASession({
108
+ token: data.jwt
109
+ })).data;
110
+ if (data.processorTransactionId !== decodeSCASessionResponse.processor_transaction_id) {
111
+ this.reportFailure("FatZebra.3DS: Validation failed. Invalid process transaction id.");
112
+ }
113
+ let validateSCAResponse;
114
+ try {
115
+ const requestParams = {
116
+ amount: this.paymentIntent.payment.amount,
117
+ authentication_transaction_id: this.enrollmentResult.authentication_transaction_id,
118
+ card_token: this.cardToken,
119
+ currency: this.paymentIntent.payment.currency,
120
+ pareq: this.enrollmentResult.pareq,
121
+ reference: this.paymentIntent.payment.reference,
122
+ };
123
+ validateSCAResponse = (yield this.gatewayClient.validateSCA(requestParams)).data;
124
+ }
125
+ catch (errorResponse) {
126
+ this.reportFailure('FatZebra.3DS: Validation failed. Server error.');
127
+ return;
128
+ }
129
+ const threedsData = threedsResponseData(validateSCAResponse);
130
+ const scenario = getValidationResult(validateSCAResponse);
131
+ if (scenario.outcome.success) {
132
+ this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
133
+ }
134
+ else {
135
+ const failureMessage = [scenario.description, (_a = scenario.outcome) === null || _a === void 0 ? void 0 : _a.errorCode].filter(Boolean).join(' - ');
136
+ this.reportFailure(`FatZebra.3DS: 3DS error - ${failureMessage}`, {
137
+ errorCode: scenario.outcome.errorCode,
138
+ });
139
+ }
140
+ }));
135
141
  // Cardinal processs BIN using directory server. This determines the 3DS version used.
136
142
  try {
137
143
  yield this._cardinal.processBin(this.bin);
@@ -1,7 +1,6 @@
1
1
  import { AxiosResponse, AxiosInstance } from "axios";
2
2
  import { Environment } from "../shared/env";
3
3
  import * as sca from "../sca/types";
4
- import * as paypal from "../paypal/types";
5
4
  export type GatewayClientProps = {
6
5
  username: string;
7
6
  environment?: Environment;
@@ -18,11 +17,5 @@ declare class GatewayClient {
18
17
  enrolSCA(data: sca.EnrollSCARequest): Promise<AxiosResponse>;
19
18
  validateSCA(data: sca.ValidateSCARequest): Promise<AxiosResponse>;
20
19
  getCard(data: sca.GetCardRequest): Promise<AxiosResponse>;
21
- /**************** PayPal /****************/
22
- createPayPalOrder(data: paypal.CreatePayPalOrderRequest): Promise<AxiosResponse>;
23
- capturePayPalOrder(data: paypal.CapturePayPalOrderRequest): Promise<AxiosResponse>;
24
- authorizePayPalOrder(data: paypal.AuthorizePayPalOrderRequest): Promise<AxiosResponse>;
25
- createPayPalBillingAgreement(data: paypal.CreatePayPalBillingAgreementRequest): Promise<AxiosResponse>;
26
- approvePayPalBillingAgreement(data: paypal.ApprovePayPalBillingAgreementRequest): Promise<AxiosResponse>;
27
20
  }
28
21
  export default GatewayClient;
@@ -7,7 +7,7 @@ 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, LocalStorageAccessTokenKey, } from "./constants";
10
+ import { RequestHeaderSdkVersion, RequestHeaderMerchantUsername, RequestTimeout, LocalStorageAccessTokenKey, } from "./constants";
11
11
  import axios from "axios";
12
12
  import { getSdkVersionNumber } from "./util";
13
13
  import env, { Environment } from "../shared/env";
@@ -76,39 +76,5 @@ class GatewayClient {
76
76
  return this.client.get(`/credit_cards/${data.card_token}`);
77
77
  });
78
78
  }
79
- /**************** PayPal /****************/
80
- createPayPalOrder(data) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- return this.client.post("/paypal/orders", data, {
83
- timeout: LongRequestTimeout,
84
- });
85
- });
86
- }
87
- capturePayPalOrder(data) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- return this.client.post(`/paypal/orders/${data.id}/capture`, null, {
90
- timeout: LongRequestTimeout,
91
- });
92
- });
93
- }
94
- authorizePayPalOrder(data) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- return this.client.post(`/paypal/orders/${data.id}/authorize`, null, {
97
- timeout: LongRequestTimeout,
98
- });
99
- });
100
- }
101
- createPayPalBillingAgreement(data) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- return this.client.post("/paypal/billing_agreements", data, {
104
- timeout: LongRequestTimeout,
105
- });
106
- });
107
- }
108
- approvePayPalBillingAgreement(data) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- return this.client.post(`/paypal/billing_agreements/${data.id}/approve`, null, { timeout: LongRequestTimeout });
111
- });
112
- }
113
79
  }
114
80
  export default GatewayClient;
@@ -24,6 +24,8 @@ interface ErrorEventDetail {
24
24
  data: any;
25
25
  }
26
26
  declare const emit: (event: PublicEvent, data: SuccessEventDetail | ErrorEventDetail, target?: HTMLElement | Window) => void;
27
+ declare const off: (event: PublicEvent, callback: (e: any) => void, target?: HTMLElement | Window) => void;
28
+ declare const onOnce: (event: PublicEvent, callback: (e: any) => void, target?: HTMLElement | Window) => void;
27
29
  declare const on: (event: PublicEvent, callback: (e: any) => void, target?: HTMLElement | Window) => void;
28
- export { emit, on };
30
+ export { emit, on, onOnce, off };
29
31
  export type { EventData, SuccessEventDetail, ErrorEventDetail };
@@ -1,7 +1,13 @@
1
1
  const emit = (event, data, target = window) => {
2
2
  target.dispatchEvent(new CustomEvent(event, { detail: data }));
3
3
  };
4
+ const off = (event, callback, target = window) => {
5
+ target.removeEventListener(event, callback);
6
+ };
7
+ const onOnce = (event, callback, target = window) => {
8
+ target.addEventListener(event, callback, { once: true });
9
+ };
4
10
  const on = (event, callback, target = window) => {
5
11
  target.addEventListener(event, callback);
6
12
  };
7
- export { emit, on };
13
+ export { emit, on, onOnce, off };