@fat-zebra/sdk 1.5.16-beta.0 → 1.5.16-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hpp/hpp.d.ts +1 -0
- package/dist/hpp/hpp.js +12 -16
- package/dist/react/VerifyCard.js +1 -1
- package/dist/react/useFatZebra.js +2 -1
- package/dist/react/useMessage.d.ts +2 -1
- package/dist/react/useMessage.js +49 -2
- package/dist/shared/types.d.ts +2 -1
- package/dist/shared/types.js +1 -0
- package/dist/three_d_secure/index.d.ts +5 -2
- package/dist/three_d_secure/index.js +15 -3
- package/dist/three_d_secure/utility/index.js +1 -1
- package/package.json +11 -2
package/dist/hpp/hpp.d.ts
CHANGED
package/dist/hpp/hpp.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
1
|
import * as bridge from '../shared/bridge-client';
|
|
8
2
|
import { LocalStorageAccessTokenKey } from '../shared/constants';
|
|
9
3
|
import { emit, off, on } from '../shared/event-manager';
|
|
10
4
|
import { PostMessageClient } from '../shared/post-message-client';
|
|
11
5
|
import { BridgeEvent, PublicEvent, } from '../shared/types';
|
|
12
6
|
import * as util from '../shared/util';
|
|
13
|
-
import { logMethod } from "../logging/logMethod";
|
|
14
7
|
import { setTransactionReference } from "../logging/logger-context";
|
|
15
8
|
import ThreeDSecure from "../three_d_secure";
|
|
16
9
|
const HPP_DEFAULT_OPTIONS = {
|
|
@@ -45,7 +38,8 @@ class Hpp {
|
|
|
45
38
|
// initial headless load
|
|
46
39
|
this.ThreeDSecure = new ThreeDSecure({
|
|
47
40
|
bridge: this.headless,
|
|
48
|
-
environment: process.env.API_ENV
|
|
41
|
+
environment: process.env.API_ENV,
|
|
42
|
+
iframe: this.iframe
|
|
49
43
|
});
|
|
50
44
|
this.setCrossFramesEventListeners();
|
|
51
45
|
this.setPublicEventListeners();
|
|
@@ -53,6 +47,11 @@ class Hpp {
|
|
|
53
47
|
this.iframe.contentWindow.postMessage(message, '*');
|
|
54
48
|
}
|
|
55
49
|
else if (this.headlessPreviouslyLoaded && this.iframeLoaded) {
|
|
50
|
+
this.ThreeDSecure = new ThreeDSecure({
|
|
51
|
+
bridge: this.headless,
|
|
52
|
+
environment: process.env.API_ENV,
|
|
53
|
+
iframe: this.iframe
|
|
54
|
+
});
|
|
56
55
|
this.iframe.contentWindow.postMessage(message, '*');
|
|
57
56
|
// subsequent iframe loads after headless has been previously loaded
|
|
58
57
|
// this caters for the SPA scenario
|
|
@@ -60,6 +59,7 @@ class Hpp {
|
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
load(config) {
|
|
62
|
+
this.challengeWindowSize = config.options.challengeWindowSize;
|
|
63
63
|
setTransactionReference(config.paymentIntent.payment.reference);
|
|
64
64
|
this.hppOptions = config.options;
|
|
65
65
|
const { el, isExisting } = bridge.load2(process.env.PAYNOW_BRIDGE_URL);
|
|
@@ -113,7 +113,7 @@ class Hpp {
|
|
|
113
113
|
setCrossFramesEventListeners() {
|
|
114
114
|
const handlers = {};
|
|
115
115
|
handlers[BridgeEvent.TOKENIZE_CARD_RESPONSE] = (data) => {
|
|
116
|
-
var _a
|
|
116
|
+
var _a;
|
|
117
117
|
if (data.errors) {
|
|
118
118
|
emit(PublicEvent.TOKENIZATION_ERROR, {
|
|
119
119
|
message: 'Card tokenization failed.',
|
|
@@ -139,8 +139,8 @@ class Hpp {
|
|
|
139
139
|
paymentIntent: this.paymentIntent,
|
|
140
140
|
merchantUsername: this.username,
|
|
141
141
|
cardToken: this.cardToken,
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
test: this.test,
|
|
143
|
+
challengeWindowSize: this.challengeWindowSize
|
|
144
144
|
});
|
|
145
145
|
return; // do not continue execution to old 3DS
|
|
146
146
|
}
|
|
@@ -149,7 +149,7 @@ class Hpp {
|
|
|
149
149
|
customer: this.customer,
|
|
150
150
|
paymentIntent: this.paymentIntent,
|
|
151
151
|
bin: data.bin,
|
|
152
|
-
challengeWindowSize: (
|
|
152
|
+
challengeWindowSize: (_a = this.hppOptions) === null || _a === void 0 ? void 0 : _a.challengeWindowSize,
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
@@ -206,7 +206,6 @@ class Hpp {
|
|
|
206
206
|
handlers[BridgeEvent.THREE_D_SECURE_ENABLED] = (data) => {
|
|
207
207
|
this.threeDSecureEnabled = typeof data === "boolean" ? data : false;
|
|
208
208
|
if (this.threeDSecureEnabled) {
|
|
209
|
-
console.log("this is a three_d_secure enabled page: ", this.threeDSecureEnabled);
|
|
210
209
|
// setPublicEventListeners is set before this feature flag is returned.
|
|
211
210
|
// we need to therefore unset the scaHandler (for the old implementation or we will get two purchase requests
|
|
212
211
|
off(PublicEvent.SCA_SUCCESS, this.scaHandler);
|
|
@@ -246,7 +245,4 @@ class Hpp {
|
|
|
246
245
|
this.headless.contentWindow.postMessage(message, '*');
|
|
247
246
|
}
|
|
248
247
|
}
|
|
249
|
-
__decorate([
|
|
250
|
-
logMethod()
|
|
251
|
-
], Hpp.prototype, "createPurchase", null);
|
|
252
248
|
export { Hpp, HPP_DEFAULT_OPTIONS, };
|
package/dist/react/VerifyCard.js
CHANGED
|
@@ -6,6 +6,6 @@ const VerifyCard = ({ handlers, config, iframeProps }) => {
|
|
|
6
6
|
handlers: handlers,
|
|
7
7
|
});
|
|
8
8
|
return (React.createElement("div", null,
|
|
9
|
-
React.createElement("iframe", Object.assign({ src: paymentUrl, "data-test-id": "verify-card", title: "verification-form" }, iframeProps))));
|
|
9
|
+
React.createElement("iframe", Object.assign({ src: paymentUrl, name: 'renderIframe', "data-test-id": "verify-card", title: "verification-form" }, iframeProps))));
|
|
10
10
|
};
|
|
11
11
|
export default VerifyCard;
|
|
@@ -5,6 +5,7 @@ type UseMessageProps = {
|
|
|
5
5
|
handlers: FatZebra.Handlers;
|
|
6
6
|
options?: FatZebra.OptionalUrlValues;
|
|
7
7
|
sca?: InstanceType<typeof Sca>;
|
|
8
|
+
config?: FatZebra.PaymentConfig;
|
|
8
9
|
};
|
|
9
|
-
declare const useMessage: ({ paymentIntent, options, handlers, sca }: UseMessageProps) => void;
|
|
10
|
+
declare const useMessage: ({ paymentIntent, options, handlers, sca, config }: UseMessageProps) => void;
|
|
10
11
|
export default useMessage;
|
package/dist/react/useMessage.js
CHANGED
|
@@ -7,9 +7,16 @@ 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 { useEffect } from 'react';
|
|
10
|
+
import { useEffect, useRef, useState } from 'react';
|
|
11
11
|
import * as FatZebra from "../shared/types";
|
|
12
|
-
|
|
12
|
+
import ThreeDSecure from "../three_d_secure";
|
|
13
|
+
import * as bridge from "../shared/bridge-client";
|
|
14
|
+
import env, { Environment } from "../shared/env";
|
|
15
|
+
const useMessage = ({ paymentIntent, options, handlers, sca, config }) => {
|
|
16
|
+
const [threeDSecureEnabled, setThreeDSecureEnabled] = useState(false);
|
|
17
|
+
const threeDSecureRef = useRef(null);
|
|
18
|
+
const successCallback = handlers[FatZebra.PublicEvent.SCA_SUCCESS];
|
|
19
|
+
const failureCallback = handlers[FatZebra.PublicEvent.SCA_ERROR];
|
|
13
20
|
const emit = (event, data) => {
|
|
14
21
|
const handler = handlers[event];
|
|
15
22
|
if (handler) {
|
|
@@ -31,6 +38,15 @@ const useMessage = ({ paymentIntent, options, handlers, sca }) => {
|
|
|
31
38
|
data,
|
|
32
39
|
});
|
|
33
40
|
}
|
|
41
|
+
if (options && options.sca_enabled && threeDSecureEnabled) {
|
|
42
|
+
threeDSecureRef.current.run({
|
|
43
|
+
paymentIntent,
|
|
44
|
+
cardToken: data.token,
|
|
45
|
+
merchantUsername: config.username,
|
|
46
|
+
test: config.environment !== Environment.production
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
34
50
|
if (options && sca && options.sca_enabled) {
|
|
35
51
|
yield sca.run({ paymentIntent, bin: data.bin, cardToken: data.token });
|
|
36
52
|
}
|
|
@@ -42,6 +58,37 @@ const useMessage = ({ paymentIntent, options, handlers, sca }) => {
|
|
|
42
58
|
return;
|
|
43
59
|
if (event.data.subject === FatZebra.BridgeEvent.BIN_LOOKUP)
|
|
44
60
|
return;
|
|
61
|
+
if (event.data.subject === FatZebra.BridgeEvent.THREE_D_SECURE_ENABLED) {
|
|
62
|
+
setThreeDSecureEnabled(event.data.data);
|
|
63
|
+
if (event.data.data) {
|
|
64
|
+
const { el } = bridge.load2(env[config.environment].bridgeUrl);
|
|
65
|
+
const headless = el;
|
|
66
|
+
let onMessage;
|
|
67
|
+
headless.onload = () => {
|
|
68
|
+
const iframe = document.querySelector('[name="renderIframe"]');
|
|
69
|
+
const threeDS = new ThreeDSecure({
|
|
70
|
+
successCallback,
|
|
71
|
+
failureCallback,
|
|
72
|
+
bridge: headless,
|
|
73
|
+
environment: config.environment,
|
|
74
|
+
iframe: iframe
|
|
75
|
+
});
|
|
76
|
+
threeDSecureRef.current = threeDS;
|
|
77
|
+
const messages = threeDS.messageHandlers(); // { [subject]: (payload) => void }
|
|
78
|
+
onMessage = (ev) => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
const subject = (_a = ev === null || ev === void 0 ? void 0 : ev.data) === null || _a === void 0 ? void 0 : _a.subject;
|
|
81
|
+
const payload = (_b = ev === null || ev === void 0 ? void 0 : ev.data) === null || _b === void 0 ? void 0 : _b.data;
|
|
82
|
+
if (!subject)
|
|
83
|
+
return;
|
|
84
|
+
const handler = messages[subject];
|
|
85
|
+
if (handler)
|
|
86
|
+
handler(payload);
|
|
87
|
+
};
|
|
88
|
+
window.addEventListener("message", onMessage);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
45
92
|
if (event.data.subject === FatZebra.BridgeEvent.FORM_VALIDATION_ERROR) {
|
|
46
93
|
emit(FatZebra.PublicEvent.FORM_VALIDATION_ERROR, {
|
|
47
94
|
errors: event.data.data,
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -43,7 +43,8 @@ declare enum BridgeEvent {
|
|
|
43
43
|
VALIDATE_THREE_D_SECURE_REQUEST = "fzi.3ds_val8_req",
|
|
44
44
|
VALIDATE_THREE_D_SECURE_RESPONSE = "fzi.3ds_val8_res",
|
|
45
45
|
THREE_D_SECURE_FAILURE_RESPONSE = "fzi.3ds_fail",
|
|
46
|
-
THREE_D_SECURE_CHALLENGE_COMPLETE = "fzi.3ds_chlnge_cmplte"
|
|
46
|
+
THREE_D_SECURE_CHALLENGE_COMPLETE = "fzi.3ds_chlnge_cmplte",
|
|
47
|
+
LOADING_THREE_D_SECURE = "fzi.loading_three_d_secure"
|
|
47
48
|
}
|
|
48
49
|
declare enum PaymentMethodType {
|
|
49
50
|
CARD = "card",
|
package/dist/shared/types.js
CHANGED
|
@@ -45,6 +45,7 @@ var BridgeEvent;
|
|
|
45
45
|
BridgeEvent["VALIDATE_THREE_D_SECURE_RESPONSE"] = "fzi.3ds_val8_res";
|
|
46
46
|
BridgeEvent["THREE_D_SECURE_FAILURE_RESPONSE"] = "fzi.3ds_fail";
|
|
47
47
|
BridgeEvent["THREE_D_SECURE_CHALLENGE_COMPLETE"] = "fzi.3ds_chlnge_cmplte";
|
|
48
|
+
BridgeEvent["LOADING_THREE_D_SECURE"] = "fzi.loading_three_d_secure";
|
|
48
49
|
})(BridgeEvent || (BridgeEvent = {}));
|
|
49
50
|
var PaymentMethodType;
|
|
50
51
|
(function (PaymentMethodType) {
|
|
@@ -7,6 +7,7 @@ interface ThreeDSecureConfig {
|
|
|
7
7
|
failureCallback?: EventCallback | null;
|
|
8
8
|
environment?: Environment;
|
|
9
9
|
bridge: HTMLIFrameElement;
|
|
10
|
+
iframe?: HTMLIFrameElement;
|
|
10
11
|
}
|
|
11
12
|
declare class ThreeDSecure {
|
|
12
13
|
private headlessBridge;
|
|
@@ -19,12 +20,13 @@ declare class ThreeDSecure {
|
|
|
19
20
|
private challengeWindowSize;
|
|
20
21
|
private successCallback;
|
|
21
22
|
private failureCallback;
|
|
22
|
-
|
|
23
|
+
private iframe?;
|
|
24
|
+
constructor({ successCallback, failureCallback, environment, bridge, iframe }: ThreeDSecureConfig);
|
|
23
25
|
run({ paymentIntent, cardToken, merchantUsername, challengeWindowSize, test }: {
|
|
24
26
|
paymentIntent: PaymentIntent;
|
|
25
27
|
cardToken: string;
|
|
26
28
|
merchantUsername: string;
|
|
27
|
-
challengeWindowSize
|
|
29
|
+
challengeWindowSize?: ChallengeWindowSize;
|
|
28
30
|
test: boolean;
|
|
29
31
|
}): void;
|
|
30
32
|
setupResponse(data: DeviceDataCollectionMessage): void;
|
|
@@ -39,5 +41,6 @@ declare class ThreeDSecure {
|
|
|
39
41
|
private validateAuthentication;
|
|
40
42
|
private validationAuthenticationResponse;
|
|
41
43
|
private createPurchase;
|
|
44
|
+
private setLoading;
|
|
42
45
|
}
|
|
43
46
|
export default ThreeDSecure;
|
|
@@ -18,14 +18,16 @@ import { getThreeDSecureValidationResult } from "./utility/getValidationResult";
|
|
|
18
18
|
import { ChallengeWindowSize } from "../sca/types";
|
|
19
19
|
import * as util from "../shared/util";
|
|
20
20
|
class ThreeDSecure {
|
|
21
|
-
constructor({ successCallback, failureCallback, environment, bridge }) {
|
|
21
|
+
constructor({ successCallback, failureCallback, environment, bridge, iframe }) {
|
|
22
22
|
this.headlessBridge = bridge;
|
|
23
23
|
this.environment = environment;
|
|
24
24
|
this.successCallback = successCallback;
|
|
25
25
|
this.failureCallback = failureCallback;
|
|
26
|
+
this.iframe = iframe;
|
|
26
27
|
DeviceDataCollection.listenDataCollectionResponse(environment);
|
|
27
28
|
}
|
|
28
29
|
run({ paymentIntent, cardToken, merchantUsername, challengeWindowSize, test }) {
|
|
30
|
+
this.setLoading();
|
|
29
31
|
this.paymentIntent = paymentIntent;
|
|
30
32
|
this.test = test;
|
|
31
33
|
this.cardToken = cardToken;
|
|
@@ -71,7 +73,7 @@ class ThreeDSecure {
|
|
|
71
73
|
else {
|
|
72
74
|
emit(PublicEvent.SCA_SUCCESS, { message, data });
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
this.setLoading(false);
|
|
75
77
|
}
|
|
76
78
|
reportFailure(message, data) {
|
|
77
79
|
if (this.failureCallback) {
|
|
@@ -81,7 +83,7 @@ class ThreeDSecure {
|
|
|
81
83
|
else {
|
|
82
84
|
emit(PublicEvent.SCA_ERROR, { errors: [message], data: data });
|
|
83
85
|
}
|
|
84
|
-
|
|
86
|
+
this.setLoading(false);
|
|
85
87
|
}
|
|
86
88
|
setup() {
|
|
87
89
|
const message = {
|
|
@@ -174,6 +176,16 @@ class ThreeDSecure {
|
|
|
174
176
|
message.data.extra = Object.assign(Object.assign({}, extra), { sli: toFzSli(extra.eci) });
|
|
175
177
|
this.headlessBridge.contentWindow.postMessage(message, '*');
|
|
176
178
|
}
|
|
179
|
+
setLoading(loading = true) {
|
|
180
|
+
var _a;
|
|
181
|
+
if ((_a = this === null || this === void 0 ? void 0 : this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) {
|
|
182
|
+
this.iframe.contentWindow.postMessage({
|
|
183
|
+
channel: 'sca',
|
|
184
|
+
subject: BridgeEvent.LOADING_THREE_D_SECURE,
|
|
185
|
+
data: loading
|
|
186
|
+
}, '*');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
177
189
|
}
|
|
178
190
|
__decorate([
|
|
179
191
|
logMethod()
|
|
@@ -8,7 +8,7 @@ const threeDResponseData = (response) => {
|
|
|
8
8
|
sli: toFzSli(response.eci),
|
|
9
9
|
eci: response.eci,
|
|
10
10
|
xid: response.xid,
|
|
11
|
-
ver:
|
|
11
|
+
ver: response === null || response === void 0 ? void 0 : response.veres,
|
|
12
12
|
directoryServerTxnId: response.directory_server_txn_id,
|
|
13
13
|
threedsVersion: response.threeds_version,
|
|
14
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fat-zebra/sdk",
|
|
3
|
-
"version": "1.5.16-beta.
|
|
3
|
+
"version": "1.5.16-beta.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -48,7 +48,16 @@
|
|
|
48
48
|
},
|
|
49
49
|
"overrides": {
|
|
50
50
|
"test-exclude": "^7.0.1",
|
|
51
|
-
"minimatch": "^10.2.2"
|
|
51
|
+
"minimatch": "^10.2.2",
|
|
52
|
+
"jest-util": {
|
|
53
|
+
"picomatch": "^4.0.4"
|
|
54
|
+
},
|
|
55
|
+
"micromatch": {
|
|
56
|
+
"picomatch": "^2.3.2"
|
|
57
|
+
},
|
|
58
|
+
"anymatch": {
|
|
59
|
+
"picomatch": "^2.3.2"
|
|
60
|
+
}
|
|
52
61
|
},
|
|
53
62
|
"dependencies": {
|
|
54
63
|
"ajv": "^8.17.1",
|