@fat-zebra/sdk 1.0.6 → 1.2.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/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/env.d.ts +5 -0
- package/dist/env.development.d.ts +5 -0
- package/dist/env.development.js +5 -0
- package/dist/env.js +5 -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 +6 -2
- package/dist/local/fatzebra.js +17728 -0
- package/dist/local/fatzebra.js.map +1 -0
- package/dist/local/index.html +247 -0
- 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/sca.d.ts +42 -0
- package/dist/sca/sca.js +273 -0
- 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/src/applepay/applepay.js +198 -0
- package/dist/src/applepay/applepay.js.map +1 -0
- package/dist/src/applepay/clients/apple-pay-client.js +66 -0
- package/dist/src/applepay/clients/apple-pay-client.js.map +1 -0
- package/dist/src/applepay/clients/paynow-client.js +96 -0
- package/dist/src/applepay/clients/paynow-client.js.map +1 -0
- package/dist/src/applepay/index.js +6 -0
- package/dist/src/applepay/index.js.map +1 -0
- package/dist/src/hpp/hpp.js +230 -0
- package/dist/src/hpp/hpp.js.map +1 -0
- package/dist/src/hpp/hpp.test.js +135 -0
- package/dist/src/hpp/hpp.test.js.map +1 -0
- package/dist/src/hpp/index.js +6 -0
- package/dist/src/hpp/index.js.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/main.js +225 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/main.test.js +236 -0
- package/dist/src/main.test.js.map +1 -0
- package/dist/src/paypal/paypal-button.js +311 -0
- package/dist/src/paypal/paypal-button.js.map +1 -0
- package/dist/src/paypal/paypal-button.test.js +41 -0
- package/dist/src/paypal/paypal-button.test.js.map +1 -0
- package/dist/src/paypal/paypal-checkout.js +111 -0
- package/dist/src/paypal/paypal-checkout.js.map +1 -0
- package/dist/src/paypal/paypal-checkout.test.js +167 -0
- package/dist/src/paypal/paypal-checkout.test.js.map +1 -0
- package/dist/src/paypal/types.js +9 -0
- package/dist/src/paypal/types.js.map +1 -0
- package/dist/src/paypal/validation.js +73 -0
- package/dist/src/paypal/validation.js.map +1 -0
- package/dist/src/sca/__tests__/eci-mappings.test.js +31 -0
- package/dist/src/sca/__tests__/eci-mappings.test.js.map +1 -0
- package/dist/src/sca/__tests__/index.test.js +558 -0
- package/dist/src/sca/__tests__/index.test.js.map +1 -0
- package/dist/src/sca/cardinal.js +110 -0
- package/dist/src/sca/cardinal.js.map +1 -0
- package/dist/src/sca/eci-mappings.js +63 -0
- package/dist/src/sca/eci-mappings.js.map +1 -0
- package/dist/src/sca/eci-mappings.test.js +31 -0
- package/dist/src/sca/eci-mappings.test.js.map +1 -0
- package/dist/src/sca/index.js +388 -0
- package/dist/src/sca/index.js.map +1 -0
- package/dist/src/sca/index.test.js +558 -0
- package/dist/src/sca/index.test.js.map +1 -0
- package/dist/src/sca/scenarios/enrollment.js +150 -0
- package/dist/src/sca/scenarios/enrollment.js.map +1 -0
- package/dist/src/sca/scenarios/index.js +8 -0
- package/dist/src/sca/scenarios/index.js.map +1 -0
- package/dist/src/sca/scenarios/validation.js +128 -0
- package/dist/src/sca/scenarios/validation.js.map +1 -0
- package/dist/src/sca/types.js +57 -0
- package/dist/src/sca/types.js.map +1 -0
- package/dist/src/shared/api-gateway-client.js +150 -0
- package/dist/src/shared/api-gateway-client.js.map +1 -0
- package/dist/src/shared/bridge-client.js +24 -0
- package/dist/src/shared/bridge-client.js.map +1 -0
- package/dist/src/shared/constants.js +19 -0
- package/dist/src/shared/constants.js.map +1 -0
- package/dist/src/shared/event-manager.js +15 -0
- package/dist/src/shared/event-manager.js.map +1 -0
- package/dist/src/shared/post-message-client.js +107 -0
- package/dist/src/shared/post-message-client.js.map +1 -0
- package/dist/src/shared/post-message-client.test.js +58 -0
- package/dist/src/shared/post-message-client.test.js.map +1 -0
- package/dist/src/shared/types.js +47 -0
- package/dist/src/shared/types.js.map +1 -0
- package/dist/src/shared/types.test.js +55 -0
- package/dist/src/shared/types.test.js.map +1 -0
- package/dist/src/shared/util.js +96 -0
- package/dist/src/shared/util.js.map +1 -0
- package/dist/src/shared/util.test.js +148 -0
- package/dist/src/shared/util.test.js.map +1 -0
- package/dist/src/validation/index.js +10 -0
- package/dist/src/validation/index.js.map +1 -0
- package/dist/src/validation/validation-helper.js +10 -0
- package/dist/src/validation/validation-helper.js.map +1 -0
- package/dist/src/validation/validation-helper.test.js +34 -0
- package/dist/src/validation/validation-helper.test.js.map +1 -0
- package/dist/src/validation/validators/hpp-load-params-validator.js +17 -0
- package/dist/src/validation/validators/hpp-load-params-validator.js.map +1 -0
- package/dist/src/validation/validators/hpp-load-params-validator.test.js +56 -0
- package/dist/src/validation/validators/hpp-load-params-validator.test.js.map +1 -0
- package/dist/src/validation/validators/verify-card-params-validator.js +18 -0
- package/dist/src/validation/validators/verify-card-params-validator.js.map +1 -0
- package/dist/tests/helpers/api-gateway-mock.js +36 -0
- package/dist/tests/helpers/api-gateway-mock.js.map +1 -0
- 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
package/dist/hpp/hpp.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import * as bridge from '../shared/bridge-client';
|
|
2
|
+
import { LocalStorageAccessTokenKey } from '../shared/constants';
|
|
3
|
+
import { emit, on } from '../shared/event-manager';
|
|
4
|
+
import { PostMessageClient } from '../shared/post-message-client';
|
|
5
|
+
import { BridgeEvent, PublicEvent, } from '../shared/types';
|
|
6
|
+
import * as util from '../shared/util';
|
|
7
|
+
const HPP_DEFAULT_OPTIONS = {
|
|
8
|
+
enableSca: false,
|
|
9
|
+
hideButton: false,
|
|
10
|
+
tokenizeOnly: false,
|
|
11
|
+
};
|
|
12
|
+
class Hpp {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.paymentIntent = config.paymentIntent;
|
|
15
|
+
this.customer = config.customer;
|
|
16
|
+
this.username = config.username;
|
|
17
|
+
this.sca = config.sca;
|
|
18
|
+
this.test = config.test;
|
|
19
|
+
this.version = config.version || 2;
|
|
20
|
+
this.postMessageClient = new PostMessageClient({
|
|
21
|
+
channel: 'sca',
|
|
22
|
+
target: this.iframe
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
load(config) {
|
|
26
|
+
this.hppOptions = config.options;
|
|
27
|
+
this.headless = bridge.load(process.env.PAYNOW_BRIDGE_URL);
|
|
28
|
+
this.iframe = document.createElement('iframe');
|
|
29
|
+
document.getElementById(config.containerId).appendChild(this.iframe);
|
|
30
|
+
this.headless.onload = () => {
|
|
31
|
+
this.iframe.onload = () => {
|
|
32
|
+
this.setCrossFramesEventListeners();
|
|
33
|
+
this.setPublicEventListeners();
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const payNowUrl = this.getPayNowUrl(config.options);
|
|
37
|
+
this.iframe.setAttribute("src", payNowUrl);
|
|
38
|
+
}
|
|
39
|
+
purchase() {
|
|
40
|
+
const message = {
|
|
41
|
+
channel: 'sca',
|
|
42
|
+
subject: BridgeEvent.TRIGGER_PAYNOW_BUTTON,
|
|
43
|
+
data: {}
|
|
44
|
+
};
|
|
45
|
+
this.iframe.contentWindow.postMessage(message, '*');
|
|
46
|
+
}
|
|
47
|
+
getPayNowUrl(options) {
|
|
48
|
+
const { payment } = this.paymentIntent;
|
|
49
|
+
const base = [
|
|
50
|
+
process.env.PAYNOW_BASE_URL,
|
|
51
|
+
'sdk',
|
|
52
|
+
this.version == 3 ? 'v3' : null,
|
|
53
|
+
this.username,
|
|
54
|
+
payment.reference,
|
|
55
|
+
payment.currency,
|
|
56
|
+
payment.amount,
|
|
57
|
+
this.paymentIntent.verification
|
|
58
|
+
].filter(part => part).join('/');
|
|
59
|
+
let queryString;
|
|
60
|
+
if (options) {
|
|
61
|
+
const _options = Object.assign(Object.assign({}, HPP_DEFAULT_OPTIONS), options);
|
|
62
|
+
queryString = Object.keys(_options).map(key => util.toSnakeCase(key) + '=' + _options[key]).join('&');
|
|
63
|
+
}
|
|
64
|
+
let searchParams = new URLSearchParams(queryString);
|
|
65
|
+
if (payment.hide_card_holder) {
|
|
66
|
+
searchParams.append('hide_card_holder', 'true');
|
|
67
|
+
}
|
|
68
|
+
return queryString ? `${base}?${searchParams.toString()}` : `${base}`;
|
|
69
|
+
}
|
|
70
|
+
setCrossFramesEventListeners() {
|
|
71
|
+
const handlers = {};
|
|
72
|
+
handlers[BridgeEvent.TOKENIZE_CARD_RESPONSE] = (data) => {
|
|
73
|
+
var _a;
|
|
74
|
+
if (data.errors) {
|
|
75
|
+
emit(PublicEvent.TOKENIZATION_ERROR, {
|
|
76
|
+
message: 'Card tokenization failed.',
|
|
77
|
+
errors: data.errors,
|
|
78
|
+
data: null,
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
emit(PublicEvent.TOKENIZATION_SUCCESS, {
|
|
84
|
+
message: 'Card tokenization success.',
|
|
85
|
+
data: {
|
|
86
|
+
token: data.token
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Required for payment later
|
|
91
|
+
this.cardToken = data.token;
|
|
92
|
+
// Halt entire HPP operation
|
|
93
|
+
if (this.hppOptions.tokenizeOnly)
|
|
94
|
+
return;
|
|
95
|
+
if (this.hppOptions.enableSca) {
|
|
96
|
+
this.sca.run({
|
|
97
|
+
cardToken: data.token,
|
|
98
|
+
customer: this.customer,
|
|
99
|
+
paymentIntent: this.paymentIntent,
|
|
100
|
+
bin: data.bin,
|
|
101
|
+
challengeWindowSize: (_a = this.hppOptions) === null || _a === void 0 ? void 0 : _a.challengeWindowSize,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this.createPurchase();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
handlers[BridgeEvent.CREATE_PAYMENT_RESPONSE] = (data) => {
|
|
109
|
+
const transactionPayload = {
|
|
110
|
+
transactionId: data.transaction_id,
|
|
111
|
+
responseCode: data.response_code,
|
|
112
|
+
message: data.message,
|
|
113
|
+
amount: data.amount,
|
|
114
|
+
currency: data.currency,
|
|
115
|
+
reference: data.reference,
|
|
116
|
+
cardNumber: data.card_number,
|
|
117
|
+
cardHolder: data.card_holder,
|
|
118
|
+
cardExpiry: data.card_expiry,
|
|
119
|
+
cardType: data.card_type,
|
|
120
|
+
verification: data.v,
|
|
121
|
+
};
|
|
122
|
+
if (data.errors) {
|
|
123
|
+
emit(PublicEvent.PAYMENT_ERROR, {
|
|
124
|
+
message: 'Payment failed.',
|
|
125
|
+
errors: data.errors,
|
|
126
|
+
data: transactionPayload,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
emit(PublicEvent.PAYMENT_SUCCESS, {
|
|
131
|
+
message: 'Payment successful.',
|
|
132
|
+
data: transactionPayload,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
handlers[BridgeEvent.FORM_VALIDATION_ERROR] = (data) => {
|
|
137
|
+
emit(PublicEvent.FORM_VALIDATION_ERROR, {
|
|
138
|
+
message: "Form was not valid",
|
|
139
|
+
errors: data.full_error_messages,
|
|
140
|
+
data: data.errors,
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
handlers[BridgeEvent.FORM_VALIDATION_SUCCESS] = (data) => {
|
|
144
|
+
emit(PublicEvent.FORM_VALIDATION_SUCCESS, {
|
|
145
|
+
message: "Form was valid",
|
|
146
|
+
data: null,
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
handlers[BridgeEvent.BIN_LOOKUP] = (data) => {
|
|
150
|
+
emit(PublicEvent.BIN_LOOKUP, {
|
|
151
|
+
message: "BIN Lookup complete",
|
|
152
|
+
data: data,
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
this.postMessageClient.setEventListeners(handlers);
|
|
156
|
+
}
|
|
157
|
+
setPublicEventListeners() {
|
|
158
|
+
const handler = (event) => {
|
|
159
|
+
const threedsData = event.detail.data;
|
|
160
|
+
const extra = util.toObjectWithSnakeCaseKeys(threedsData);
|
|
161
|
+
this.createPurchase(extra);
|
|
162
|
+
};
|
|
163
|
+
on(PublicEvent.SCA_SUCCESS, handler);
|
|
164
|
+
}
|
|
165
|
+
createPurchase(extra = null) {
|
|
166
|
+
const message = {
|
|
167
|
+
channel: 'sca',
|
|
168
|
+
subject: BridgeEvent.CREATE_PAYMENT_REQUEST,
|
|
169
|
+
data: {
|
|
170
|
+
access_token: window.localStorage.getItem(LocalStorageAccessTokenKey),
|
|
171
|
+
amount: this.paymentIntent.payment.amount,
|
|
172
|
+
card_token: this.cardToken,
|
|
173
|
+
currency: this.paymentIntent.payment.currency,
|
|
174
|
+
hide_card_holder: this.paymentIntent.payment.hide_card_holder,
|
|
175
|
+
hash: this.paymentIntent.verification,
|
|
176
|
+
invoice: this.paymentIntent.payment.reference,
|
|
177
|
+
test: this.test,
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
if (extra) {
|
|
181
|
+
message.data.extra = extra;
|
|
182
|
+
}
|
|
183
|
+
this.headless.contentWindow.postMessage(message, '*');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
export { Hpp, HPP_DEFAULT_OPTIONS, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Hpp } from './hpp';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "ts-polyfill";
|
|
2
|
+
import "custom-event-polyfill";
|
|
3
|
+
import { type PaymentIntent, type Payment, type PublicEvent, type PaymentConfig, type Handlers } from "./shared/types";
|
|
4
|
+
export type { PaymentIntent, Payment, PaymentConfig, Handlers };
|
|
5
|
+
export { PublicEvent };
|
package/dist/index.js
CHANGED