@fat-zebra/sdk 1.4.15 → 1.5.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/.idea/fatzebra-js.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/CHANGELOG.md +13 -0
- package/README.dev.md +1 -14
- package/build-styles.js +12 -0
- package/dist/click_to_pay/index.d.ts +1 -1
- package/dist/click_to_pay/index.js +45 -1
- package/dist/fatzebra.css +91 -0
- package/dist/local/fatzebra.js +18266 -0
- package/dist/local/fatzebra.js.map +1 -1
- package/dist/main.d.ts +4 -2
- package/dist/main.js +24 -20
- package/dist/react/VerifyCard.d.ts +2 -2
- package/dist/react/VerifyCard.js +4 -4
- package/dist/react/VerifyExistingCard.d.ts +10 -0
- package/dist/react/VerifyExistingCard.js +12 -0
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/useFatZebra.d.ts +4 -2
- package/dist/react/useFatZebra.js +6 -4
- package/dist/react/verifyUrl.d.ts +8 -0
- package/dist/react/verifyUrl.js +22 -0
- package/dist/sca/cardinal.d.ts +11 -10
- package/dist/sca/cardinal.js +29 -8
- package/dist/sca/index.d.ts +3 -0
- package/dist/sca/index.js +51 -46
- package/dist/shared/api-gateway-client.d.ts +0 -7
- package/dist/shared/api-gateway-client.js +1 -35
- package/dist/shared/event-manager.d.ts +3 -1
- package/dist/shared/event-manager.js +7 -1
- package/dist/shared/types.d.ts +7 -12
- package/dist/shared/types.js +3 -6
- package/dist/staging/fatzebra.css +91 -0
- package/dist/staging/fatzebra.js +18265 -0
- package/dist/staging/fatzebra.js.map +1 -0
- package/dist/staging/index.html +247 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +1 -0
- package/package.json +6 -7
- package/dist/production/fatzebra.js.LICENSE.txt +0 -1
- package/dist/src/applepay/applepay.js +0 -198
- package/dist/src/applepay/applepay.js.map +0 -1
- package/dist/src/applepay/clients/apple-pay-client.js +0 -66
- package/dist/src/applepay/clients/apple-pay-client.js.map +0 -1
- package/dist/src/applepay/clients/paynow-client.js +0 -96
- package/dist/src/applepay/clients/paynow-client.js.map +0 -1
- package/dist/src/applepay/index.js +0 -6
- package/dist/src/applepay/index.js.map +0 -1
- package/dist/src/click_to_pay/index.js +0 -88
- package/dist/src/click_to_pay/index.js.map +0 -1
- package/dist/src/click_to_pay/types.js +0 -3
- package/dist/src/click_to_pay/types.js.map +0 -1
- package/dist/src/hpp/hpp.js +0 -230
- package/dist/src/hpp/hpp.js.map +0 -1
- package/dist/src/hpp/hpp.test.js +0 -135
- package/dist/src/hpp/hpp.test.js.map +0 -1
- package/dist/src/hpp/index.js +0 -6
- package/dist/src/hpp/index.js.map +0 -1
- package/dist/src/index.js +0 -14
- package/dist/src/index.js.map +0 -1
- package/dist/src/main.js +0 -243
- package/dist/src/main.js.map +0 -1
- package/dist/src/main.test.js +0 -236
- package/dist/src/main.test.js.map +0 -1
- package/dist/src/paypal/paypal-button.js +0 -311
- package/dist/src/paypal/paypal-button.js.map +0 -1
- package/dist/src/paypal/paypal-button.test.js +0 -41
- package/dist/src/paypal/paypal-button.test.js.map +0 -1
- package/dist/src/paypal/paypal-checkout.js +0 -111
- package/dist/src/paypal/paypal-checkout.js.map +0 -1
- package/dist/src/paypal/paypal-checkout.test.js +0 -167
- package/dist/src/paypal/paypal-checkout.test.js.map +0 -1
- package/dist/src/paypal/types.js +0 -9
- package/dist/src/paypal/types.js.map +0 -1
- package/dist/src/paypal/validation.js +0 -73
- package/dist/src/paypal/validation.js.map +0 -1
- package/dist/src/react/VerifyCard.js +0 -29
- package/dist/src/react/VerifyCard.js.map +0 -1
- package/dist/src/react/index.js +0 -11
- package/dist/src/react/index.js.map +0 -1
- package/dist/src/react/submitForm.js +0 -13
- package/dist/src/react/submitForm.js.map +0 -1
- package/dist/src/react/url.js +0 -60
- package/dist/src/react/url.js.map +0 -1
- package/dist/src/react/url.test.js +0 -88
- package/dist/src/react/url.test.js.map +0 -1
- package/dist/src/react/useFatZebra.js +0 -119
- package/dist/src/react/useFatZebra.js.map +0 -1
- package/dist/src/sca/cardinal.js +0 -110
- package/dist/src/sca/cardinal.js.map +0 -1
- package/dist/src/sca/eci-mappings.js +0 -63
- package/dist/src/sca/eci-mappings.js.map +0 -1
- package/dist/src/sca/eci-mappings.test.js +0 -31
- package/dist/src/sca/eci-mappings.test.js.map +0 -1
- package/dist/src/sca/index.js +0 -363
- package/dist/src/sca/index.js.map +0 -1
- package/dist/src/sca/index.test.js +0 -620
- package/dist/src/sca/index.test.js.map +0 -1
- package/dist/src/sca/scenarios/enrollment.js +0 -161
- package/dist/src/sca/scenarios/enrollment.js.map +0 -1
- package/dist/src/sca/scenarios/index.js +0 -8
- package/dist/src/sca/scenarios/index.js.map +0 -1
- package/dist/src/sca/scenarios/validation.js +0 -139
- package/dist/src/sca/scenarios/validation.js.map +0 -1
- package/dist/src/sca/types.js +0 -57
- package/dist/src/sca/types.js.map +0 -1
- package/dist/src/shared/api-gateway-client.js +0 -184
- package/dist/src/shared/api-gateway-client.js.map +0 -1
- package/dist/src/shared/bridge-client.js +0 -24
- package/dist/src/shared/bridge-client.js.map +0 -1
- package/dist/src/shared/constants.js +0 -19
- package/dist/src/shared/constants.js.map +0 -1
- package/dist/src/shared/env.development.js +0 -12
- package/dist/src/shared/env.development.js.map +0 -1
- package/dist/src/shared/env.js +0 -46
- package/dist/src/shared/env.js.map +0 -1
- package/dist/src/shared/envs/local.js +0 -12
- package/dist/src/shared/envs/local.js.map +0 -1
- package/dist/src/shared/envs/production.js +0 -12
- package/dist/src/shared/envs/production.js.map +0 -1
- package/dist/src/shared/envs/sandbox.js +0 -12
- package/dist/src/shared/envs/sandbox.js.map +0 -1
- package/dist/src/shared/envs/staging.js +0 -12
- package/dist/src/shared/envs/staging.js.map +0 -1
- package/dist/src/shared/event-manager.js +0 -14
- package/dist/src/shared/event-manager.js.map +0 -1
- package/dist/src/shared/post-message-client.js +0 -107
- package/dist/src/shared/post-message-client.js.map +0 -1
- package/dist/src/shared/post-message-client.test.js +0 -58
- package/dist/src/shared/post-message-client.test.js.map +0 -1
- package/dist/src/shared/types.js +0 -47
- package/dist/src/shared/types.js.map +0 -1
- package/dist/src/shared/types.test.js +0 -55
- package/dist/src/shared/types.test.js.map +0 -1
- package/dist/src/shared/util.js +0 -96
- package/dist/src/shared/util.js.map +0 -1
- package/dist/src/shared/util.test.js +0 -148
- package/dist/src/shared/util.test.js.map +0 -1
- package/dist/src/validation/index.js +0 -12
- package/dist/src/validation/index.js.map +0 -1
- package/dist/src/validation/schemas/click-to-pay/load-params.json +0 -34
- package/dist/src/validation/schemas/click-to-pay/options.json +0 -23
- package/dist/src/validation/schemas/click-to-pay/payment-intent.json +0 -42
- package/dist/src/validation/schemas/customer.json +0 -38
- package/dist/src/validation/schemas/hpp-load-params.json +0 -40
- package/dist/src/validation/schemas/hpp-options.json +0 -48
- package/dist/src/validation/schemas/payment-intent.json +0 -48
- package/dist/src/validation/schemas/payment-method.json +0 -83
- package/dist/src/validation/schemas/verify-card-options.json +0 -15
- package/dist/src/validation/schemas/verify-card-params.json +0 -24
- package/dist/src/validation/validation-helper.js +0 -10
- package/dist/src/validation/validation-helper.js.map +0 -1
- package/dist/src/validation/validation-helper.test.js +0 -34
- package/dist/src/validation/validation-helper.test.js.map +0 -1
- package/dist/src/validation/validators/click-to-pay-load-params-validator.js +0 -19
- package/dist/src/validation/validators/click-to-pay-load-params-validator.js.map +0 -1
- package/dist/src/validation/validators/hpp-load-params-validator.js +0 -21
- package/dist/src/validation/validators/hpp-load-params-validator.js.map +0 -1
- package/dist/src/validation/validators/hpp-load-params-validator.test.js +0 -56
- package/dist/src/validation/validators/hpp-load-params-validator.test.js.map +0 -1
- package/dist/src/validation/validators/verify-card-params-validator.js +0 -23
- package/dist/src/validation/validators/verify-card-params-validator.js.map +0 -1
- package/dist/tests/helpers/api-gateway-mock.js +0 -37
- package/dist/tests/helpers/api-gateway-mock.js.map +0 -1
- /package/dist/react/{url.d.ts → paymentUrl.d.ts} +0 -0
- /package/dist/react/{url.js → paymentUrl.js} +0 -0
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
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
9
|
-
export default
|
|
8
|
+
declare const VerifyCard: ({ handlers, config, iframeProps }: FrameProps) => React.JSX.Element;
|
|
9
|
+
export default VerifyCard;
|
package/dist/react/VerifyCard.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import useFatZebra from "./useFatZebra";
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
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:
|
|
9
|
+
React.createElement("iframe", Object.assign({ src: paymentUrl, "data-test-id": "verify-card", title: "verification-form" }, iframeProps))));
|
|
10
10
|
};
|
|
11
|
-
export default
|
|
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;
|
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -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
|
-
|
|
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 "./
|
|
3
|
+
import { generatePaymentURL } from "./paymentUrl";
|
|
4
4
|
import Sca from "../sca";
|
|
5
5
|
import GatewayClient from "../shared/api-gateway-client";
|
|
6
|
-
|
|
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 });
|
|
@@ -70,7 +71,8 @@ const useFatZebra = ({ config, handlers }) => {
|
|
|
70
71
|
};
|
|
71
72
|
}, []);
|
|
72
73
|
const payment = paymentIntent.payment;
|
|
73
|
-
const
|
|
74
|
-
|
|
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 };
|
package/dist/sca/cardinal.d.ts
CHANGED
|
@@ -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
|
|
21
|
-
constructor(
|
|
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():
|
|
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
|
}
|
package/dist/sca/cardinal.js
CHANGED
|
@@ -17,7 +17,7 @@ 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: {
|
|
@@ -25,14 +25,36 @@ const defaultConfig = {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
export default class CardinalManager {
|
|
28
|
-
constructor(
|
|
29
|
-
|
|
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) {
|
|
32
53
|
window.Cardinal.setup(CardinalWorkflow.INIT, { jwt });
|
|
33
54
|
}
|
|
34
55
|
onPaymentValidated(handler) {
|
|
35
56
|
window.Cardinal.on('payments.validated', (data, jwt) => {
|
|
57
|
+
window.Cardinal.off('payments.validated');
|
|
36
58
|
if (data.ErrorDescription.toLowerCase() === 'success') {
|
|
37
59
|
handler({
|
|
38
60
|
processorTransactionId: data.Payment.ProcessorTransactionId,
|
|
@@ -44,11 +66,10 @@ export default class CardinalManager {
|
|
|
44
66
|
}
|
|
45
67
|
});
|
|
46
68
|
}
|
|
47
|
-
onPaymentSetupComplete() {
|
|
48
|
-
|
|
49
|
-
window.Cardinal.
|
|
50
|
-
|
|
51
|
-
});
|
|
69
|
+
onPaymentSetupComplete(callback) {
|
|
70
|
+
window.Cardinal.on(CardinalPaymentEvent.SETUP_COMPLETE, (data) => {
|
|
71
|
+
window.Cardinal.off(CardinalPaymentEvent.SETUP_COMPLETE);
|
|
72
|
+
callback(data);
|
|
52
73
|
});
|
|
53
74
|
}
|
|
54
75
|
processBin(bin) {
|
package/dist/sca/index.d.ts
CHANGED
|
@@ -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,57 @@ class Sca {
|
|
|
85
86
|
this.reportFailure('FatZebra.3DS: JWT creation failed.');
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
88
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
91
|
+
this.perform3DS({ sessionID: paymentsSetupCompleteResponse.sessionId });
|
|
92
|
+
}));
|
|
93
|
+
this._cardinal.setup(cardinalJwt);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
perform3DS({ sessionID }) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
this.sessionId = sessionID;
|
|
99
|
+
// Register handler. Called after OTP is entered on challenge prompt.
|
|
100
|
+
this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
var _a;
|
|
102
|
+
if (typeof error == 'string') {
|
|
103
|
+
this.reportFailure(`FatZebra.3DS: Validation failed. ${error}.`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const decodeSCASessionResponse = (yield this.gatewayClient.decodeSCASession({
|
|
107
|
+
token: data.jwt
|
|
108
|
+
})).data;
|
|
109
|
+
if (data.processorTransactionId !== decodeSCASessionResponse.processor_transaction_id) {
|
|
110
|
+
this.reportFailure("FatZebra.3DS: Validation failed. Invalid process transaction id.");
|
|
111
|
+
}
|
|
112
|
+
let validateSCAResponse;
|
|
113
|
+
try {
|
|
114
|
+
const requestParams = {
|
|
115
|
+
amount: this.paymentIntent.payment.amount,
|
|
116
|
+
authentication_transaction_id: this.enrollmentResult.authentication_transaction_id,
|
|
117
|
+
card_token: this.cardToken,
|
|
118
|
+
currency: this.paymentIntent.payment.currency,
|
|
119
|
+
pareq: this.enrollmentResult.pareq,
|
|
120
|
+
reference: this.paymentIntent.payment.reference,
|
|
121
|
+
};
|
|
122
|
+
validateSCAResponse = (yield this.gatewayClient.validateSCA(requestParams)).data;
|
|
123
|
+
}
|
|
124
|
+
catch (errorResponse) {
|
|
125
|
+
this.reportFailure('FatZebra.3DS: Validation failed. Server error.');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const threedsData = threedsResponseData(validateSCAResponse);
|
|
129
|
+
const scenario = getValidationResult(validateSCAResponse);
|
|
130
|
+
if (scenario.outcome.success) {
|
|
131
|
+
this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const failureMessage = [scenario.description, (_a = scenario.outcome) === null || _a === void 0 ? void 0 : _a.errorCode].filter(Boolean).join(' - ');
|
|
135
|
+
this.reportFailure(`FatZebra.3DS: 3DS error - ${failureMessage}`, {
|
|
136
|
+
errorCode: scenario.outcome.errorCode,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}));
|
|
135
140
|
// Cardinal processs BIN using directory server. This determines the 3DS version used.
|
|
136
141
|
try {
|
|
137
142
|
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,
|
|
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 };
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PayPalPaymentMethod } from '../paypal/types';
|
|
2
1
|
import { Environment } from './env';
|
|
3
2
|
declare enum PublicEvent {
|
|
4
3
|
FORM_VALIDATION_ERROR = "fz.form_validation.error",
|
|
@@ -10,11 +9,9 @@ declare enum PublicEvent {
|
|
|
10
9
|
TOKENIZATION_ERROR = "fz.tokenization.error",
|
|
11
10
|
PAYMENT_SUCCESS = "fz.payment.success",
|
|
12
11
|
PAYMENT_ERROR = "fz.payment.error",
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
PAYPAL_PROCESSESING = "fz.paypal.processing",
|
|
17
|
-
BIN_LOOKUP = "fz.bin.lookup"
|
|
12
|
+
BIN_LOOKUP = "fz.bin.lookup",
|
|
13
|
+
CLICK_TO_PAY_TOKENIZATION_SUCCESS = "fz.click_to_pay.tokenization.success",
|
|
14
|
+
CLICK_TO_PAY_TOKENIZATION_ERROR = "fz.click_to_pay.tokenization.error"
|
|
18
15
|
}
|
|
19
16
|
declare enum BridgeEvent {
|
|
20
17
|
TOKENIZE_CARD_REQUEST = "fzi.tc_req",
|
|
@@ -24,13 +21,12 @@ declare enum BridgeEvent {
|
|
|
24
21
|
TRIGGER_PAYNOW_BUTTON = "fzi.pn_btn",
|
|
25
22
|
FORM_VALIDATION_ERROR = "fzi.form_validation_error",
|
|
26
23
|
FORM_VALIDATION_SUCCESS = "fzi.form_validation_success",
|
|
27
|
-
BIN_LOOKUP = "fzi.bin_lookup"
|
|
24
|
+
BIN_LOOKUP = "fzi.bin_lookup",
|
|
25
|
+
CLICK_TO_PAY_TOKENIZATION = "fzi.c2p.tc_res"
|
|
28
26
|
}
|
|
29
27
|
declare enum PaymentMethodType {
|
|
30
28
|
CARD = "card",
|
|
31
|
-
CARD_ON_FILE = "card_on_file"
|
|
32
|
-
PAYPAL_ORDER = "paypal_order",
|
|
33
|
-
PAYPAL_BILLING = "paypal_billing"
|
|
29
|
+
CARD_ON_FILE = "card_on_file"
|
|
34
30
|
}
|
|
35
31
|
interface Card {
|
|
36
32
|
number: string;
|
|
@@ -74,7 +70,7 @@ interface PaymentIntent {
|
|
|
74
70
|
}
|
|
75
71
|
interface PaymentMethod {
|
|
76
72
|
type?: PaymentMethodType;
|
|
77
|
-
data: Card | CardOnFile
|
|
73
|
+
data: Card | CardOnFile;
|
|
78
74
|
}
|
|
79
75
|
interface ValidationResult {
|
|
80
76
|
valid: boolean;
|
|
@@ -105,7 +101,6 @@ declare global {
|
|
|
105
101
|
ApplePaySession: any;
|
|
106
102
|
Cardinal: any;
|
|
107
103
|
FatZebra: any;
|
|
108
|
-
paypal: any;
|
|
109
104
|
HPP: any;
|
|
110
105
|
MerchantUsername: string;
|
|
111
106
|
}
|
package/dist/shared/types.js
CHANGED
|
@@ -9,11 +9,9 @@ var PublicEvent;
|
|
|
9
9
|
PublicEvent["TOKENIZATION_ERROR"] = "fz.tokenization.error";
|
|
10
10
|
PublicEvent["PAYMENT_SUCCESS"] = "fz.payment.success";
|
|
11
11
|
PublicEvent["PAYMENT_ERROR"] = "fz.payment.error";
|
|
12
|
-
PublicEvent["PAYPAL_CANCEL"] = "fz.paypal.cancel";
|
|
13
|
-
PublicEvent["PAYPAL_SUCCESS"] = "fz.paypal.success";
|
|
14
|
-
PublicEvent["PAYPAL_ERROR"] = "fz.paypal.error";
|
|
15
|
-
PublicEvent["PAYPAL_PROCESSESING"] = "fz.paypal.processing";
|
|
16
12
|
PublicEvent["BIN_LOOKUP"] = "fz.bin.lookup";
|
|
13
|
+
PublicEvent["CLICK_TO_PAY_TOKENIZATION_SUCCESS"] = "fz.click_to_pay.tokenization.success";
|
|
14
|
+
PublicEvent["CLICK_TO_PAY_TOKENIZATION_ERROR"] = "fz.click_to_pay.tokenization.error";
|
|
17
15
|
})(PublicEvent || (PublicEvent = {}));
|
|
18
16
|
var BridgeEvent;
|
|
19
17
|
(function (BridgeEvent) {
|
|
@@ -25,12 +23,11 @@ var BridgeEvent;
|
|
|
25
23
|
BridgeEvent["FORM_VALIDATION_ERROR"] = "fzi.form_validation_error";
|
|
26
24
|
BridgeEvent["FORM_VALIDATION_SUCCESS"] = "fzi.form_validation_success";
|
|
27
25
|
BridgeEvent["BIN_LOOKUP"] = "fzi.bin_lookup";
|
|
26
|
+
BridgeEvent["CLICK_TO_PAY_TOKENIZATION"] = "fzi.c2p.tc_res";
|
|
28
27
|
})(BridgeEvent || (BridgeEvent = {}));
|
|
29
28
|
var PaymentMethodType;
|
|
30
29
|
(function (PaymentMethodType) {
|
|
31
30
|
PaymentMethodType["CARD"] = "card";
|
|
32
31
|
PaymentMethodType["CARD_ON_FILE"] = "card_on_file";
|
|
33
|
-
PaymentMethodType["PAYPAL_ORDER"] = "paypal_order";
|
|
34
|
-
PaymentMethodType["PAYPAL_BILLING"] = "paypal_billing";
|
|
35
32
|
})(PaymentMethodType || (PaymentMethodType = {}));
|
|
36
33
|
export { BridgeEvent, PublicEvent, PaymentMethodType, };
|