@fat-zebra/sdk 1.0.6 → 1.2.2

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 (72) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +162 -0
  3. package/dist/applepay/applepay.d.ts +20 -0
  4. package/dist/applepay/applepay.js +93 -0
  5. package/dist/applepay/clients/apple-pay-client.d.ts +24 -0
  6. package/dist/applepay/clients/apple-pay-client.js +29 -0
  7. package/dist/applepay/clients/paynow-client.d.ts +17 -0
  8. package/dist/applepay/clients/paynow-client.js +55 -0
  9. package/dist/applepay/index.d.ts +1 -0
  10. package/dist/applepay/index.js +1 -0
  11. package/dist/hpp/hpp.d.ts +61 -0
  12. package/dist/hpp/hpp.js +186 -0
  13. package/dist/hpp/index.d.ts +2 -0
  14. package/dist/hpp/index.js +1 -0
  15. package/dist/index.d.ts +5 -2
  16. package/dist/index.js +7 -1
  17. package/dist/main.d.ts +38 -0
  18. package/dist/main.js +148 -0
  19. package/dist/paypal/paypal-button.d.ts +31 -0
  20. package/dist/paypal/paypal-button.js +199 -0
  21. package/dist/paypal/paypal-checkout.d.ts +21 -0
  22. package/dist/paypal/paypal-checkout.js +100 -0
  23. package/dist/paypal/types.d.ts +188 -0
  24. package/dist/paypal/types.js +5 -0
  25. package/dist/paypal/validation.d.ts +4 -0
  26. package/dist/paypal/validation.js +65 -0
  27. package/dist/react/VerifyCard.d.ts +2 -4
  28. package/dist/react/VerifyCard.js +1 -2
  29. package/dist/react/url.d.ts +2 -11
  30. package/dist/react/useFatZebra.d.ts +2 -3
  31. package/dist/react/useFatZebra.js +7 -7
  32. package/dist/sca/cardinal.d.ts +1 -1
  33. package/dist/sca/cardinal.js +1 -1
  34. package/dist/sca/index.d.ts +8 -5
  35. package/dist/sca/index.js +26 -87
  36. package/dist/sca/scenarios/index.d.ts +3 -2
  37. package/dist/sca/types.d.ts +1 -1
  38. package/dist/sca/types.js +1 -1
  39. package/dist/shared/api-gateway-client.d.ts +7 -0
  40. package/dist/shared/api-gateway-client.js +37 -3
  41. package/dist/shared/env.d.ts +1 -1
  42. package/dist/shared/env.development.d.ts +5 -0
  43. package/dist/shared/env.development.js +5 -0
  44. package/dist/shared/env.js +1 -1
  45. package/dist/shared/event-manager.d.ts +1 -1
  46. package/dist/shared/event-manager.js +0 -1
  47. package/dist/shared/post-message-client.d.ts +1 -1
  48. package/dist/shared/post-message-client.js +2 -3
  49. package/dist/shared/types.d.ts +40 -33
  50. package/dist/shared/types.js +7 -1
  51. package/dist/validation/index.d.ts +3 -0
  52. package/dist/validation/index.js +3 -0
  53. package/dist/validation/schemas/customer.json +38 -0
  54. package/dist/validation/schemas/hpp-load-params.json +40 -0
  55. package/dist/validation/schemas/hpp-options.json +48 -0
  56. package/dist/validation/schemas/payment-intent.json +48 -0
  57. package/dist/validation/schemas/payment-method.json +83 -0
  58. package/dist/validation/schemas/verify-card-options.json +15 -0
  59. package/dist/validation/schemas/verify-card-params.json +24 -0
  60. package/dist/validation/validation-helper.d.ts +3 -0
  61. package/dist/validation/validation-helper.js +6 -0
  62. package/dist/validation/validators/hpp-load-params-validator.d.ts +3 -0
  63. package/dist/validation/validators/hpp-load-params-validator.js +14 -0
  64. package/dist/validation/validators/verify-card-params-validator.d.ts +3 -0
  65. package/dist/validation/validators/verify-card-params-validator.js +16 -0
  66. package/docker-compose.yml +16 -0
  67. package/package.json +44 -15
  68. package/tsconfig.json +8 -18
  69. package/tsconfig.package.json +25 -0
  70. package/index.js +0 -0
  71. package/jest.config.js +0 -16
  72. package/yarn-error.log +0 -2374
@@ -0,0 +1,188 @@
1
+ import { PaymentMethod, PaymentIntent } from '../shared/types';
2
+ export interface PayPalConfig {
3
+ currency: string;
4
+ payment: PayPalOrderParams;
5
+ containerId: string;
6
+ style?: {
7
+ [key: string]: any;
8
+ };
9
+ }
10
+ export interface PayPalOrderParams {
11
+ paymentIntent?: PaymentIntent;
12
+ paymentMethod: PaymentMethod;
13
+ }
14
+ export declare enum PayPalIntent {
15
+ CAPTURE = "CAPTURE",
16
+ AUTHORIZE = "AUTHORIZE"
17
+ }
18
+ export type PayPalPaymentMethod = PayPalOrderRequest | PayPalBillingAgreementRequest;
19
+ /***************** PayPal Order Object ******************/
20
+ export interface PayPalOrderRequest {
21
+ intent: 'capture' | 'authorize';
22
+ options?: {
23
+ brandName?: string;
24
+ landingPage?: string;
25
+ payeePreferredPayment?: string;
26
+ shippingPreference?: string;
27
+ };
28
+ purchases: Purchases[];
29
+ }
30
+ interface Purchases {
31
+ description?: string;
32
+ softDescriptor?: string;
33
+ amount: Amount;
34
+ items?: Item[];
35
+ shippingAddress: {
36
+ name?: string;
37
+ method?: string;
38
+ address: Address;
39
+ };
40
+ payee?: {
41
+ emailAddress: string;
42
+ merchantId: string;
43
+ };
44
+ }
45
+ interface Amount {
46
+ itemTotal?: number;
47
+ shipping?: number;
48
+ handling?: number;
49
+ taxTotal?: number;
50
+ shippingDiscount?: number;
51
+ insurance?: number;
52
+ discount?: number;
53
+ }
54
+ interface Address {
55
+ firstName?: string;
56
+ lastName?: string;
57
+ address_1?: string;
58
+ address_2?: string;
59
+ city?: string;
60
+ state?: string;
61
+ postcode?: string;
62
+ country: string;
63
+ }
64
+ interface Item {
65
+ name: string;
66
+ description?: string;
67
+ sku?: string;
68
+ unitAmount: number;
69
+ tax?: number;
70
+ qty: string;
71
+ category?: string;
72
+ }
73
+ export interface CreatePayPalOrderRequest {
74
+ order: PayPalOrderRequest;
75
+ }
76
+ export interface PayPalOrderResponse {
77
+ id: string;
78
+ intent: PayPalIntent;
79
+ }
80
+ /***************** PayPal Capture Object ******************/
81
+ export interface CapturePayPalOrderRequest {
82
+ id: string;
83
+ }
84
+ export interface CapturePayPalOrderResponse {
85
+ id: string;
86
+ intent: string;
87
+ reference: string;
88
+ paypal_reference: string;
89
+ invoice_id: string;
90
+ amount: number;
91
+ decimal_amount: number;
92
+ captured_amount: number;
93
+ captured: boolean;
94
+ successful: boolean;
95
+ status: string;
96
+ message: string;
97
+ currency: string;
98
+ transaction_id: string;
99
+ transaction_date: Date;
100
+ response_code: string;
101
+ paypal_fee: number;
102
+ seller_receivable_net_amount: number;
103
+ note_to_payer: string;
104
+ is_final_capture: boolean;
105
+ refunded_amount: number;
106
+ balance_available_for_refund: number;
107
+ balance_available_for_capture: number;
108
+ authorization: string;
109
+ order: string;
110
+ }
111
+ /***************** PayPal Authorize Object ******************/
112
+ export interface AuthorizePayPalOrderRequest {
113
+ id: string;
114
+ }
115
+ export interface AuthorizePayPalOrderResponse {
116
+ id: string;
117
+ intent: string;
118
+ reference: string;
119
+ paypal_reference: string;
120
+ invoice_id: string;
121
+ amount: number;
122
+ decimal_amount: number;
123
+ captured_amount: number;
124
+ captured: boolean;
125
+ successful: boolean;
126
+ status: string;
127
+ message: string;
128
+ currency: string;
129
+ transaction_id: string;
130
+ transaction_date: Date;
131
+ response_code: string;
132
+ refunded_amount: number;
133
+ balance_available_for_capture: number;
134
+ order: string;
135
+ }
136
+ /***************** PayPal Billing Agreement Object ******************/
137
+ export interface PayPalBillingAgreementRequest {
138
+ name?: string;
139
+ description?: string;
140
+ shippingAddress: BillingAddress;
141
+ merchantCustomData?: string;
142
+ }
143
+ export interface CreatePayPalBillingAgreementRequest {
144
+ billing: PayPalBillingAgreementRequest;
145
+ }
146
+ interface BillingAddress {
147
+ firstName?: string;
148
+ lastName?: string;
149
+ address_1: string;
150
+ address_2?: string;
151
+ city: string;
152
+ state: string;
153
+ postcode: string;
154
+ country: string;
155
+ }
156
+ export interface PayPalBillingAgreementResponse {
157
+ token_id: string;
158
+ }
159
+ export interface ApprovePayPalBillingAgreementRequest {
160
+ id: string;
161
+ }
162
+ export interface ApprovePayPalBillingAgreementResponse {
163
+ token: string;
164
+ name?: string;
165
+ description?: string;
166
+ state: string;
167
+ payer?: {
168
+ payer_info: {
169
+ email: string;
170
+ first_name: string;
171
+ last_name: string;
172
+ payer_id: string;
173
+ };
174
+ };
175
+ shipping_address?: {
176
+ first_name?: string;
177
+ last_name?: string;
178
+ address_1: string;
179
+ address_2?: string;
180
+ city: string;
181
+ state: string;
182
+ postcode: string;
183
+ country: string;
184
+ };
185
+ merchant_custom_data?: string;
186
+ created_at: Date;
187
+ }
188
+ export {};
@@ -0,0 +1,5 @@
1
+ export var PayPalIntent;
2
+ (function (PayPalIntent) {
3
+ PayPalIntent["CAPTURE"] = "CAPTURE";
4
+ PayPalIntent["AUTHORIZE"] = "AUTHORIZE";
5
+ })(PayPalIntent || (PayPalIntent = {}));
@@ -0,0 +1,4 @@
1
+ import { PayPalConfig, PayPalOrderParams } from './types';
2
+ import { ValidationResult } from '../shared/types';
3
+ export declare const validatePayPalSetup: (props: PayPalConfig) => ValidationResult;
4
+ export declare const validatePayPalRequest: (props: PayPalOrderParams, billing?: boolean) => ValidationResult;
@@ -0,0 +1,65 @@
1
+ import { PayPalIntent } from './types';
2
+ const PaypalConfigRequiredProps = ['currency', 'containerId', 'payment'];
3
+ const PaypalOrderRequiredProps = ['intent', 'purchases'];
4
+ const PaypalBillingRequiredProps = ['shippingAddress'];
5
+ export const validatePayPalSetup = (props) => {
6
+ let errors = [];
7
+ const keys = Object.keys(props);
8
+ for (let requiredProp of PaypalConfigRequiredProps) {
9
+ // @ts-ignore
10
+ if (!keys.includes(requiredProp) || props[requiredProp] === undefined) {
11
+ errors.push(`${requiredProp} is missing.`);
12
+ }
13
+ }
14
+ return {
15
+ valid: errors.length == 0,
16
+ errors
17
+ };
18
+ };
19
+ export const validatePayPalRequest = (props, billing) => {
20
+ let errors = [];
21
+ const keys = Object.keys(props);
22
+ if (!keys.includes('paymentMethod')) {
23
+ errors.push(`paymentMethod is missing.`);
24
+ }
25
+ if (!keys.includes('paymentIntent') && !billing) {
26
+ errors.push(`paymentIntent is missing.`);
27
+ }
28
+ if (props.paymentMethod) {
29
+ const orderKeys = Object.keys(props.paymentMethod.data);
30
+ if (orderKeys.includes('intent')) {
31
+ const intent = props.paymentMethod.data.intent.toLowerCase();
32
+ const intents = Object.values(PayPalIntent).map(v => v.toLowerCase());
33
+ if (!intents.includes(intent)) {
34
+ errors.push(`intent is invalid, must be one of [${intents.join(', ')}].`);
35
+ }
36
+ }
37
+ if (!props.paymentMethod.type) {
38
+ errors.push(`paymentMethod.type is missing.`);
39
+ }
40
+ }
41
+ if (errors.length > 0) {
42
+ return {
43
+ valid: errors.length == 0,
44
+ errors
45
+ };
46
+ }
47
+ const paymentMethod = props.paymentMethod.data;
48
+ const providedKeys = Object.keys(paymentMethod);
49
+ let requiredProps;
50
+ if (billing === true) {
51
+ requiredProps = PaypalBillingRequiredProps;
52
+ }
53
+ else {
54
+ requiredProps = PaypalOrderRequiredProps;
55
+ }
56
+ for (let requiredProp of requiredProps) {
57
+ if (!providedKeys.includes(requiredProp)) {
58
+ errors.push(`${requiredProp} is missing.`);
59
+ }
60
+ }
61
+ return {
62
+ valid: errors.length == 0,
63
+ errors
64
+ };
65
+ };
@@ -2,9 +2,7 @@ import React from "react";
2
2
  import * as FatZebra from "../shared/types";
3
3
  type FrameProps = {
4
4
  handlers: FatZebra.Handlers;
5
- username: string;
6
- accessToken: string;
7
- config: FatZebra.VerificationConfig;
5
+ config: FatZebra.PaymentConfig;
8
6
  };
9
- declare const Frame: ({ username, handlers, config }: FrameProps) => React.JSX.Element;
7
+ declare const Frame: ({ handlers, config }: FrameProps) => React.JSX.Element;
10
8
  export default Frame;
@@ -1,10 +1,9 @@
1
1
  import React from "react";
2
2
  import useFatZebra from "./useFatZebra";
3
3
  import * as env from "../shared/env";
4
- const Frame = ({ username, handlers, config }) => {
4
+ const Frame = ({ handlers, config }) => {
5
5
  const bridgeRef = React.useRef(null);
6
6
  const { url } = useFatZebra({
7
- username: username,
8
7
  config,
9
8
  handlers: handlers,
10
9
  bridge: bridgeRef,
@@ -1,3 +1,4 @@
1
+ import { OptionalUrlValues } from '../shared/types';
1
2
  type RequiredURLValues = {
2
3
  merchant: string;
3
4
  hash: string;
@@ -5,16 +6,6 @@ type RequiredURLValues = {
5
6
  amount: number;
6
7
  currency: string;
7
8
  };
8
- type OptionalURLValues = Partial<{
9
- hide_card_holder: string;
10
- return_path: string;
11
- card_types: Array<string>;
12
- surcharge_enabled: string;
13
- sca_enabled: boolean;
14
- css: string;
15
- css_signature: string;
16
- tokenize_only: boolean;
17
- }>;
18
- type UrlValues = RequiredURLValues & OptionalURLValues;
9
+ type UrlValues = RequiredURLValues & OptionalUrlValues;
19
10
  declare const generatePaymentURL: (values: UrlValues) => string;
20
11
  export { generatePaymentURL };
@@ -1,12 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import * as FatZebra from "../shared/types";
3
3
  type UseFatZebraProps = {
4
- username: string;
5
4
  handlers: FatZebra.Handlers;
6
- config: FatZebra.VerificationConfig;
5
+ config: FatZebra.PaymentConfig;
7
6
  bridge: React.MutableRefObject<HTMLIFrameElement>;
8
7
  };
9
- declare const useFatZebra: ({ username, config, handlers, bridge }: UseFatZebraProps) => {
8
+ declare const useFatZebra: ({ config, handlers, bridge }: UseFatZebraProps) => {
10
9
  url: string;
11
10
  };
12
11
  export default useFatZebra;
@@ -3,11 +3,13 @@ import * as FatZebra from "../shared/types";
3
3
  import { generatePaymentURL } from "./url";
4
4
  import Sca from "../sca";
5
5
  import GatewayClient from "../shared/api-gateway-client";
6
- const useFatZebra = ({ username, config, handlers, bridge }) => {
7
- const { options, accessToken, paymentIntent, verification } = config;
6
+ const useFatZebra = ({ config, handlers, bridge }) => {
7
+ const { options, accessToken, paymentIntent, username } = config;
8
8
  const sca = useMemo(() => {
9
9
  const gatewayClient = new GatewayClient({ accessToken, username });
10
- return new Sca({ gatewayClient });
10
+ const successCallback = handlers[FatZebra.PublicEvent.SCA_SUCCESS];
11
+ const failureCallback = handlers[FatZebra.PublicEvent.SCA_ERROR];
12
+ return new Sca({ gatewayClient, successCallback, failureCallback });
11
13
  }, [config, username]);
12
14
  const emit = (event, data) => {
13
15
  const handler = handlers[event];
@@ -60,9 +62,7 @@ const useFatZebra = ({ username, config, handlers, bridge }) => {
60
62
  },
61
63
  });
62
64
  }
63
- if (options.tokenizeOnly)
64
- return;
65
- if (options.enableSca) {
65
+ if (options.sca_enabled) {
66
66
  sca.run({ paymentIntent, bin: data.bin, cardToken: data.token });
67
67
  }
68
68
  };
@@ -101,7 +101,7 @@ const useFatZebra = ({ username, config, handlers, bridge }) => {
101
101
  };
102
102
  }, []);
103
103
  const payment = paymentIntent.payment;
104
- const url = generatePaymentURL(Object.assign(Object.assign({}, options), { merchant: username, reference: payment.reference, amount: payment.amount, currency: payment.currency, hash: verification }));
104
+ const url = generatePaymentURL(Object.assign({ merchant: username, reference: payment.reference, amount: payment.amount, currency: payment.currency, hash: paymentIntent.verification }, options));
105
105
  return { url };
106
106
  };
107
107
  export default useFatZebra;
@@ -25,5 +25,5 @@ export default class CardinalManager {
25
25
  processBin(bin: string): Promise<any>;
26
26
  continue(acsUrl: string, pareq: string, transactionId: string): void;
27
27
  }
28
- export { CardinalManager };
28
+ export { CardinalManager, };
29
29
  export type { PaymentValidatedDTO };
@@ -67,4 +67,4 @@ export default class CardinalManager {
67
67
  });
68
68
  }
69
69
  }
70
- export { CardinalManager };
70
+ export { CardinalManager, };
@@ -1,5 +1,5 @@
1
1
  import * as t from './types';
2
- import { Customer, CustomerSnakeCase, PaymentIntent } from '../shared/types';
2
+ import { Customer, CustomerSnakeCase, PaymentIntent, PublicEvent } from '../shared/types';
3
3
  import { CardinalManager } from './cardinal';
4
4
  import GatewayClient from '../shared/api-gateway-client';
5
5
  export interface ScaRunProps {
@@ -11,10 +11,11 @@ export interface ScaRunProps {
11
11
  }
12
12
  export interface ScaConfig {
13
13
  gatewayClient: GatewayClient;
14
+ successCallback?: (event: PublicEvent.SCA_SUCCESS, detail: any) => void;
15
+ failureCallback?: (event: PublicEvent.SCA_ERROR, detail: any) => void;
14
16
  }
15
17
  declare class Sca {
16
18
  private _cardinal;
17
- private _eventEmitTarget;
18
19
  private enrollmentResult;
19
20
  private paymentIntent;
20
21
  private bin;
@@ -23,12 +24,14 @@ declare class Sca {
23
24
  private challengeWindowSize;
24
25
  private sessionId;
25
26
  private gatewayClient;
26
- constructor({ gatewayClient }: ScaConfig);
27
+ private successCallback;
28
+ private failureCallback;
29
+ constructor({ gatewayClient, successCallback, failureCallback }: ScaConfig);
27
30
  loadScript(): void;
28
31
  get cardinal(): CardinalManager;
29
32
  set cardinal(cardinal: CardinalManager);
30
- get eventEmitTarget(): HTMLDivElement | Window;
31
- set eventEmitTarget(target: HTMLDivElement | Window);
33
+ reportFailure(message: string): void;
34
+ reportSuccess(message: string, data: any): void;
32
35
  run(config: ScaRunProps): Promise<void>;
33
36
  createCardinalJWT(): Promise<string>;
34
37
  check3DSEnrollment(): Promise<void>;
package/dist/sca/index.js CHANGED
@@ -13,30 +13,22 @@ import { PublicEvent, } from '../shared/types';
13
13
  import { CardinalManager, } from './cardinal';
14
14
  import { emit, } from '../shared/event-manager';
15
15
  import { toFzSli } from './eci-mappings';
16
- import * as env from "../shared/env";
17
16
  class Sca {
18
- constructor({ gatewayClient }) {
19
- this._eventEmitTarget = window;
17
+ constructor({ gatewayClient, successCallback, failureCallback }) {
20
18
  this.sessionId = null;
21
19
  this.gatewayClient = gatewayClient;
22
- this.loadScript();
20
+ this.successCallback = successCallback || emit;
21
+ this.failureCallback = failureCallback || emit;
23
22
  }
24
23
  loadScript() {
25
- if (!document.getElementById("songbird-script")) {
26
- console.log(env);
27
- const script = document.createElement('script');
28
- script.type = 'text/javascript';
29
- script.id = "songbird-script";
30
- script.src = env.songbirdUrl;
31
- script.async = true;
32
- script.onload = () => {
33
- this._cardinal = new CardinalManager();
34
- };
35
- document.body.appendChild(script);
36
- }
37
- else {
24
+ const script = document.createElement('script');
25
+ script.type = 'text/javascript';
26
+ script.src = process.env.SONGBIRD_URL;
27
+ script.async = true;
28
+ script.onload = () => {
38
29
  this._cardinal = new CardinalManager();
39
- }
30
+ };
31
+ document.body.appendChild(script);
40
32
  }
41
33
  get cardinal() {
42
34
  return this._cardinal;
@@ -44,12 +36,13 @@ class Sca {
44
36
  set cardinal(cardinal) {
45
37
  this._cardinal = cardinal;
46
38
  }
47
- get eventEmitTarget() {
48
- return this._eventEmitTarget;
39
+ reportFailure(message) {
40
+ this.failureCallback(PublicEvent.SCA_ERROR, { errors: [message] });
41
+ console.log(message);
49
42
  }
50
- // Specify the DOM element to which the SCA results are outputted.
51
- set eventEmitTarget(target) {
52
- this._eventEmitTarget = target;
43
+ reportSuccess(message, data) {
44
+ this.successCallback(PublicEvent.SCA_SUCCESS, { data, message });
45
+ console.log(message);
53
46
  }
54
47
  run(config) {
55
48
  return __awaiter(this, void 0, void 0, function* () {
@@ -65,12 +58,7 @@ class Sca {
65
58
  cardinalJwt = yield this.createCardinalJWT();
66
59
  }
67
60
  catch (error) {
68
- const message = 'FatZebra.3DS: JWT creation failed.';
69
- emit(PublicEvent.SCA_ERROR, {
70
- errors: [message],
71
- data: null
72
- });
73
- console.log(message);
61
+ this.reportFailure('FatZebra.3DS: JWT creation failed.');
74
62
  return;
75
63
  }
76
64
  // Init cardinal
@@ -81,24 +69,14 @@ class Sca {
81
69
  // Register handler. Called after OTP is entered on challenge prompt.
82
70
  this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
83
71
  if (typeof error == 'string') {
84
- const message = `FatZebra.3DS: Validation failed. ${error}.`;
85
- emit(PublicEvent.SCA_ERROR, {
86
- errors: [message],
87
- data: null,
88
- });
89
- console.log(message);
72
+ this.reportFailure(`FatZebra.3DS: Validation failed. ${error}.`);
90
73
  return;
91
74
  }
92
75
  const decodeSCASessionResponse = (yield this.gatewayClient.decodeSCASession({
93
76
  token: data.jwt
94
77
  })).data;
95
78
  if (data.processorTransactionId !== decodeSCASessionResponse.processor_transaction_id) {
96
- const message = 'FatZebra.3DS: Validation failed. Invalid process transaction id.';
97
- emit(PublicEvent.SCA_ERROR, {
98
- errors: [message],
99
- data: null
100
- });
101
- console.log(message);
79
+ this.reportFailure("FatZebra.3DS: Validation failed. Invalid process transaction id.");
102
80
  }
103
81
  let validateSCAResponse;
104
82
  try {
@@ -113,33 +91,16 @@ class Sca {
113
91
  validateSCAResponse = (yield this.gatewayClient.validateSCA(requestParams)).data;
114
92
  }
115
93
  catch (errorResponse) {
116
- const message = 'FatZebra.3DS: Validation failed. Server error.';
117
- emit(PublicEvent.SCA_ERROR, {
118
- errors: [message],
119
- data: null,
120
- });
121
- console.log(message);
94
+ this.reportFailure('FatZebra.3DS: Validation failed. Server error.');
122
95
  return;
123
96
  }
124
97
  const threedsData = threedsResponseData(validateSCAResponse);
125
98
  const scenario = getValidationResult(validateSCAResponse);
126
99
  if (scenario.outcome.success) {
127
- const message = `FatZebra.3DS: 3DS success - ${scenario.description}.`;
128
- emit(PublicEvent.SCA_SUCCESS, {
129
- message,
130
- data: threedsData,
131
- });
132
- console.log(message);
100
+ this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
133
101
  }
134
102
  else {
135
- const message = `FatZebra.3DS: 3DS error - ${scenario.description}`;
136
- emit(PublicEvent.SCA_ERROR, {
137
- errors: [message],
138
- data: {
139
- errorCode: scenario.outcome.errorCode
140
- },
141
- });
142
- console.log(message);
103
+ this.reportFailure(`FatZebra.3DS: 3DS error - ${scenario.description} - ${scenario.outcome.errorCode}`);
143
104
  }
144
105
  }));
145
106
  }
@@ -148,24 +109,14 @@ class Sca {
148
109
  yield this._cardinal.processBin(this.bin);
149
110
  }
150
111
  catch (err) {
151
- const message = 'FatZebra.3DS: BIN verification failed.';
152
- emit(PublicEvent.SCA_ERROR, {
153
- errors: [message],
154
- data: null
155
- });
156
- console.log(message);
112
+ this.reportFailure('FatZebra.3DS: BIN verification failed.');
157
113
  return;
158
114
  }
159
115
  try {
160
116
  yield this.check3DSEnrollment();
161
117
  }
162
118
  catch (err) {
163
- const message = 'FatZebra.3DS: Enrollment failed. Server error.';
164
- emit(PublicEvent.SCA_ERROR, {
165
- errors: [message],
166
- data: null
167
- });
168
- console.log(message);
119
+ this.reportFailure('FatZebra.3DS: Enrollment failed. Server error.');
169
120
  return;
170
121
  }
171
122
  this.handleEnrollmentResult(this.enrollmentResult);
@@ -228,22 +179,10 @@ class Sca {
228
179
  return;
229
180
  }
230
181
  if (scenario.outcome.success) {
231
- const message = `FatZebra.3DS: 3DS success - ${scenario.description}.`;
232
- emit(PublicEvent.SCA_SUCCESS, {
233
- message,
234
- data: threedsData,
235
- });
236
- console.log(message);
182
+ this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
237
183
  }
238
184
  else {
239
- const message = `FatZebra.3DS: 3DS error - ${scenario.description}`;
240
- emit(PublicEvent.SCA_ERROR, {
241
- errors: [message],
242
- data: {
243
- errorCode: scenario.outcome.errorCode
244
- },
245
- });
246
- console.log(message);
185
+ this.reportFailure(`FatZebra.3DS: 3DS error - ${scenario.description} - ${scenario.outcome.errorCode}`);
247
186
  }
248
187
  }
249
188
  }
@@ -1,4 +1,5 @@
1
1
  export { enrollmentScenarios } from './enrollment';
2
- export type { EnrollmentScenario } from './enrollment';
3
2
  export { validationScenarios } from './validation';
4
- export type { ValidationScenario } from './validation';
3
+ import type { EnrollmentScenario } from './enrollment';
4
+ import type { ValidationScenario } from './validation';
5
+ export type { EnrollmentScenario, ValidationScenario };
@@ -155,5 +155,5 @@ interface GetCardRequest {
155
155
  interface GetCardResponse {
156
156
  bin: string;
157
157
  }
158
- export { ScaErrorCode, ChallengeWindowSize, CommerceIndicator, VEResEnrolled, PARes };
158
+ export { ScaErrorCode, ChallengeWindowSize, CommerceIndicator, VEResEnrolled, PARes, };
159
159
  export type { CreateSCASessionRequest, CreateSCASessionResponse, EnrollSCARequest, EnrollSCAResponse, ValidateSCARequest, ValidateSCAResponse, DecodeSCASessionRequest, DecodeSCASessionResponse, GetCardRequest, GetCardResponse, ThreedsData };
package/dist/sca/types.js CHANGED
@@ -51,4 +51,4 @@ var PARes;
51
51
  PARes["NOT_COMPLETED"] = "U";
52
52
  PARes["SUCCESS"] = "Y";
53
53
  })(PARes || (PARes = {}));
54
- export { ScaErrorCode, ChallengeWindowSize, CommerceIndicator, VEResEnrolled, PARes };
54
+ export { ScaErrorCode, ChallengeWindowSize, CommerceIndicator, VEResEnrolled, PARes, };
@@ -1,5 +1,6 @@
1
1
  import { AxiosResponse, AxiosInstance } from "axios";
2
2
  import * as sca from "../sca/types";
3
+ import * as paypal from "../paypal/types";
3
4
  export type GatewayClientProps = {
4
5
  accessToken: string;
5
6
  username: string;
@@ -13,5 +14,11 @@ declare class GatewayClient {
13
14
  enrolSCA(data: sca.EnrollSCARequest): Promise<AxiosResponse>;
14
15
  validateSCA(data: sca.ValidateSCARequest): Promise<AxiosResponse>;
15
16
  getCard(data: sca.GetCardRequest): Promise<AxiosResponse>;
17
+ /**************** PayPal /****************/
18
+ createPayPalOrder(data: paypal.CreatePayPalOrderRequest): Promise<AxiosResponse>;
19
+ capturePayPalOrder(data: paypal.CapturePayPalOrderRequest): Promise<AxiosResponse>;
20
+ authorizePayPalOrder(data: paypal.AuthorizePayPalOrderRequest): Promise<AxiosResponse>;
21
+ createPayPalBillingAgreement(data: paypal.CreatePayPalBillingAgreementRequest): Promise<AxiosResponse>;
22
+ approvePayPalBillingAgreement(data: paypal.ApprovePayPalBillingAgreementRequest): Promise<AxiosResponse>;
16
23
  }
17
24
  export default GatewayClient;