@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.
- package/CHANGELOG.md +13 -0
- package/README.md +162 -0
- package/dist/applepay/applepay.d.ts +20 -0
- package/dist/applepay/applepay.js +93 -0
- package/dist/applepay/clients/apple-pay-client.d.ts +24 -0
- package/dist/applepay/clients/apple-pay-client.js +29 -0
- package/dist/applepay/clients/paynow-client.d.ts +17 -0
- package/dist/applepay/clients/paynow-client.js +55 -0
- package/dist/applepay/index.d.ts +1 -0
- package/dist/applepay/index.js +1 -0
- package/dist/hpp/hpp.d.ts +61 -0
- package/dist/hpp/hpp.js +186 -0
- package/dist/hpp/index.d.ts +2 -0
- package/dist/hpp/index.js +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +7 -1
- package/dist/main.d.ts +38 -0
- package/dist/main.js +148 -0
- package/dist/paypal/paypal-button.d.ts +31 -0
- package/dist/paypal/paypal-button.js +199 -0
- package/dist/paypal/paypal-checkout.d.ts +21 -0
- package/dist/paypal/paypal-checkout.js +100 -0
- package/dist/paypal/types.d.ts +188 -0
- package/dist/paypal/types.js +5 -0
- package/dist/paypal/validation.d.ts +4 -0
- package/dist/paypal/validation.js +65 -0
- package/dist/react/VerifyCard.d.ts +2 -4
- package/dist/react/VerifyCard.js +1 -2
- package/dist/react/url.d.ts +2 -11
- package/dist/react/useFatZebra.d.ts +2 -3
- package/dist/react/useFatZebra.js +7 -7
- package/dist/sca/cardinal.d.ts +1 -1
- package/dist/sca/cardinal.js +1 -1
- package/dist/sca/index.d.ts +8 -5
- package/dist/sca/index.js +26 -87
- package/dist/sca/scenarios/index.d.ts +3 -2
- package/dist/sca/types.d.ts +1 -1
- package/dist/sca/types.js +1 -1
- package/dist/shared/api-gateway-client.d.ts +7 -0
- package/dist/shared/api-gateway-client.js +37 -3
- package/dist/shared/env.d.ts +1 -1
- package/dist/shared/env.development.d.ts +5 -0
- package/dist/shared/env.development.js +5 -0
- package/dist/shared/env.js +1 -1
- package/dist/shared/event-manager.d.ts +1 -1
- package/dist/shared/event-manager.js +0 -1
- package/dist/shared/post-message-client.d.ts +1 -1
- package/dist/shared/post-message-client.js +2 -3
- package/dist/shared/types.d.ts +40 -33
- package/dist/shared/types.js +7 -1
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.js +3 -0
- package/dist/validation/schemas/customer.json +38 -0
- package/dist/validation/schemas/hpp-load-params.json +40 -0
- package/dist/validation/schemas/hpp-options.json +48 -0
- package/dist/validation/schemas/payment-intent.json +48 -0
- package/dist/validation/schemas/payment-method.json +83 -0
- package/dist/validation/schemas/verify-card-options.json +15 -0
- package/dist/validation/schemas/verify-card-params.json +24 -0
- package/dist/validation/validation-helper.d.ts +3 -0
- package/dist/validation/validation-helper.js +6 -0
- package/dist/validation/validators/hpp-load-params-validator.d.ts +3 -0
- package/dist/validation/validators/hpp-load-params-validator.js +14 -0
- package/dist/validation/validators/verify-card-params-validator.d.ts +3 -0
- package/dist/validation/validators/verify-card-params-validator.js +16 -0
- package/docker-compose.yml +16 -0
- package/package.json +44 -15
- package/tsconfig.json +8 -18
- package/tsconfig.package.json +25 -0
- package/index.js +0 -0
- package/jest.config.js +0 -16
- 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,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
|
-
|
|
6
|
-
accessToken: string;
|
|
7
|
-
config: FatZebra.VerificationConfig;
|
|
5
|
+
config: FatZebra.PaymentConfig;
|
|
8
6
|
};
|
|
9
|
-
declare const Frame: ({
|
|
7
|
+
declare const Frame: ({ handlers, config }: FrameProps) => React.JSX.Element;
|
|
10
8
|
export default Frame;
|
package/dist/react/VerifyCard.js
CHANGED
|
@@ -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 = ({
|
|
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,
|
package/dist/react/url.d.ts
CHANGED
|
@@ -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
|
|
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.
|
|
5
|
+
config: FatZebra.PaymentConfig;
|
|
7
6
|
bridge: React.MutableRefObject<HTMLIFrameElement>;
|
|
8
7
|
};
|
|
9
|
-
declare const useFatZebra: ({
|
|
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 = ({
|
|
7
|
-
const { options, accessToken, paymentIntent,
|
|
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
|
-
|
|
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.
|
|
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(
|
|
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;
|
package/dist/sca/cardinal.d.ts
CHANGED
package/dist/sca/cardinal.js
CHANGED
package/dist/sca/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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.
|
|
20
|
+
this.successCallback = successCallback || emit;
|
|
21
|
+
this.failureCallback = failureCallback || emit;
|
|
23
22
|
}
|
|
24
23
|
loadScript() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
48
|
-
|
|
39
|
+
reportFailure(message) {
|
|
40
|
+
this.failureCallback(PublicEvent.SCA_ERROR, { errors: [message] });
|
|
41
|
+
console.log(message);
|
|
49
42
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3
|
+
import type { EnrollmentScenario } from './enrollment';
|
|
4
|
+
import type { ValidationScenario } from './validation';
|
|
5
|
+
export type { EnrollmentScenario, ValidationScenario };
|
package/dist/sca/types.d.ts
CHANGED
|
@@ -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;
|