@fat-zebra/sdk 1.0.1 → 1.0.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/dist/index.d.ts +1 -1
- package/dist/index.js +2 -5
- package/dist/react/VerifyCard.js +11 -17
- package/dist/react/index.js +2 -8
- package/dist/react/url.js +10 -14
- package/dist/react/useFatZebra.js +23 -63
- package/dist/sca/cardinal.d.ts +2 -1
- package/dist/sca/cardinal.js +22 -61
- package/dist/sca/eci-mappings.js +4 -8
- package/dist/sca/index.js +182 -296
- package/dist/sca/scenarios/enrollment.d.ts +2 -1
- package/dist/sca/scenarios/enrollment.js +25 -28
- package/dist/sca/scenarios/index.d.ts +4 -2
- package/dist/sca/scenarios/index.js +2 -7
- package/dist/sca/scenarios/validation.d.ts +2 -1
- package/dist/sca/scenarios/validation.js +16 -19
- package/dist/sca/types.d.ts +2 -1
- package/dist/sca/types.js +6 -8
- package/dist/shared/api-gateway-client.js +37 -81
- package/dist/shared/bridge-client.js +5 -8
- package/dist/shared/constants.js +6 -13
- package/dist/shared/event-manager.d.ts +2 -1
- package/dist/shared/event-manager.js +3 -9
- package/dist/shared/post-message-client.d.ts +2 -1
- package/dist/shared/post-message-client.js +38 -75
- package/dist/shared/types.d.ts +2 -1
- package/dist/shared/types.js +5 -7
- package/dist/shared/util.js +18 -31
- package/package.json +2 -2
- package/src/index.ts +4 -4
- package/src/sca/cardinal.ts +5 -5
- package/src/sca/scenarios/enrollment.ts +4 -4
- package/src/sca/scenarios/index.ts +4 -2
- package/src/sca/scenarios/validation.ts +3 -3
- package/src/sca/types.ts +8 -5
- package/src/shared/event-manager.ts +2 -1
- package/src/shared/post-message-client.ts +4 -2
- package/src/shared/types.ts +3 -3
- package/tsconfig.json +6 -4
- package/dist/index.js.map +0 -1
- package/dist/react/VerifyCard.js.map +0 -1
- package/dist/react/index.js.map +0 -1
- package/dist/react/url.js.map +0 -1
- package/dist/react/useFatZebra.js.map +0 -1
- package/dist/sca/cardinal.js.map +0 -1
- package/dist/sca/eci-mappings.js.map +0 -1
- package/dist/sca/index.js.map +0 -1
- package/dist/sca/scenarios/enrollment.js.map +0 -1
- package/dist/sca/scenarios/index.js.map +0 -1
- package/dist/sca/scenarios/validation.js.map +0 -1
- package/dist/sca/types.js.map +0 -1
- package/dist/shared/api-gateway-client.js.map +0 -1
- package/dist/shared/bridge-client.js.map +0 -1
- package/dist/shared/constants.js.map +0 -1
- package/dist/shared/event-manager.js.map +0 -1
- package/dist/shared/post-message-client.js.map +0 -1
- package/dist/shared/types.js.map +0 -1
- package/dist/shared/util.js.map +0 -1
package/dist/sca/index.js
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -31,286 +7,197 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
8
|
});
|
|
33
9
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
var t = __importStar(require("./types"));
|
|
63
|
-
var scenarios_1 = require("./scenarios");
|
|
64
|
-
var types_1 = require("../shared/types");
|
|
65
|
-
var cardinal_1 = require("./cardinal");
|
|
66
|
-
var event_manager_1 = require("../shared/event-manager");
|
|
67
|
-
var eci_mappings_1 = require("./eci-mappings");
|
|
68
|
-
var Sca = /** @class */ (function () {
|
|
69
|
-
function Sca(_a) {
|
|
70
|
-
var gatewayClient = _a.gatewayClient;
|
|
10
|
+
import * as t from './types';
|
|
11
|
+
import { enrollmentScenarios, validationScenarios, } from './scenarios';
|
|
12
|
+
import { PublicEvent, } from '../shared/types';
|
|
13
|
+
import { CardinalManager, } from './cardinal';
|
|
14
|
+
import { emit, } from '../shared/event-manager';
|
|
15
|
+
import { toFzSli } from './eci-mappings';
|
|
16
|
+
class Sca {
|
|
17
|
+
constructor({ gatewayClient }) {
|
|
71
18
|
this._eventEmitTarget = window;
|
|
72
19
|
this.sessionId = null;
|
|
73
20
|
this.gatewayClient = gatewayClient;
|
|
74
21
|
this.loadScript();
|
|
75
22
|
}
|
|
76
|
-
|
|
77
|
-
var _this = this;
|
|
23
|
+
loadScript() {
|
|
78
24
|
if (!document.getElementById("songbird-script")) {
|
|
79
|
-
|
|
25
|
+
const script = document.createElement('script');
|
|
80
26
|
script.type = 'text/javascript';
|
|
81
27
|
script.id = "songbird-script";
|
|
82
28
|
script.src = process.env.SONGBIRD_URL;
|
|
83
29
|
script.async = true;
|
|
84
|
-
script.onload =
|
|
85
|
-
|
|
30
|
+
script.onload = () => {
|
|
31
|
+
this._cardinal = new CardinalManager();
|
|
86
32
|
};
|
|
87
33
|
document.body.appendChild(script);
|
|
88
34
|
}
|
|
89
35
|
else {
|
|
90
|
-
this._cardinal = new
|
|
36
|
+
this._cardinal = new CardinalManager();
|
|
91
37
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
message =
|
|
137
|
-
|
|
38
|
+
}
|
|
39
|
+
get cardinal() {
|
|
40
|
+
return this._cardinal;
|
|
41
|
+
}
|
|
42
|
+
set cardinal(cardinal) {
|
|
43
|
+
this._cardinal = cardinal;
|
|
44
|
+
}
|
|
45
|
+
get eventEmitTarget() {
|
|
46
|
+
return this._eventEmitTarget;
|
|
47
|
+
}
|
|
48
|
+
// Specify the DOM element to which the SCA results are outputted.
|
|
49
|
+
set eventEmitTarget(target) {
|
|
50
|
+
this._eventEmitTarget = target;
|
|
51
|
+
}
|
|
52
|
+
run(config) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
// Persist states until next 3DS run.
|
|
55
|
+
this.paymentIntent = config.paymentIntent;
|
|
56
|
+
this.bin = config.bin;
|
|
57
|
+
this.cardToken = config.cardToken;
|
|
58
|
+
this.customer = config.customer;
|
|
59
|
+
this.challengeWindowSize = config.challengeWindowSize || t.ChallengeWindowSize.SIZE_FULL_PAGE;
|
|
60
|
+
let cardinalJwt;
|
|
61
|
+
// Generate Cardinal JWT
|
|
62
|
+
try {
|
|
63
|
+
cardinalJwt = yield this.createCardinalJWT();
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const message = 'FatZebra.3DS: JWT creation failed.';
|
|
67
|
+
emit(PublicEvent.SCA_ERROR, {
|
|
68
|
+
errors: [message],
|
|
69
|
+
data: null
|
|
70
|
+
});
|
|
71
|
+
console.log(message);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// Init cardinal
|
|
75
|
+
this._cardinal.setup(cardinalJwt);
|
|
76
|
+
if (!this.sessionId) {
|
|
77
|
+
const paymentsSetupCompleteResponse = yield this._cardinal.onPaymentSetupComplete();
|
|
78
|
+
this.sessionId = paymentsSetupCompleteResponse.sessionId;
|
|
79
|
+
// Register handler. Called after OTP is entered on challenge prompt.
|
|
80
|
+
this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (typeof error == 'string') {
|
|
82
|
+
const message = `FatZebra.3DS: Validation failed. ${error}.`;
|
|
83
|
+
emit(PublicEvent.SCA_ERROR, {
|
|
138
84
|
errors: [message],
|
|
139
|
-
data: null
|
|
85
|
+
data: null,
|
|
140
86
|
});
|
|
141
87
|
console.log(message);
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.sessionId = paymentsSetupCompleteResponse.sessionId;
|
|
151
|
-
// Register handler. Called after OTP is entered on challenge prompt.
|
|
152
|
-
this._cardinal.onPaymentValidated(function (data, error) { return __awaiter(_this, void 0, void 0, function () {
|
|
153
|
-
var message, decodeSCASessionResponse, message, validateSCAResponse, requestParams, errorResponse_1, message, threedsData, scenario, message, message;
|
|
154
|
-
return __generator(this, function (_a) {
|
|
155
|
-
switch (_a.label) {
|
|
156
|
-
case 0:
|
|
157
|
-
if (typeof error == 'string') {
|
|
158
|
-
message = "FatZebra.3DS: Validation failed. ".concat(error, ".");
|
|
159
|
-
(0, event_manager_1.emit)(types_1.PublicEvent.SCA_ERROR, {
|
|
160
|
-
errors: [message],
|
|
161
|
-
data: null,
|
|
162
|
-
});
|
|
163
|
-
console.log(message);
|
|
164
|
-
return [2 /*return*/];
|
|
165
|
-
}
|
|
166
|
-
return [4 /*yield*/, this.gatewayClient.decodeSCASession({
|
|
167
|
-
token: data.jwt
|
|
168
|
-
})];
|
|
169
|
-
case 1:
|
|
170
|
-
decodeSCASessionResponse = (_a.sent()).data;
|
|
171
|
-
if (data.processorTransactionId !== decodeSCASessionResponse.processor_transaction_id) {
|
|
172
|
-
message = 'FatZebra.3DS: Validation failed. Invalid process transaction id.';
|
|
173
|
-
(0, event_manager_1.emit)(types_1.PublicEvent.SCA_ERROR, {
|
|
174
|
-
errors: [message],
|
|
175
|
-
data: null
|
|
176
|
-
});
|
|
177
|
-
console.log(message);
|
|
178
|
-
}
|
|
179
|
-
_a.label = 2;
|
|
180
|
-
case 2:
|
|
181
|
-
_a.trys.push([2, 4, , 5]);
|
|
182
|
-
requestParams = {
|
|
183
|
-
amount: this.paymentIntent.payment.amount,
|
|
184
|
-
authentication_transaction_id: this.enrollmentResult.authentication_transaction_id,
|
|
185
|
-
card_token: this.cardToken,
|
|
186
|
-
currency: this.paymentIntent.payment.currency,
|
|
187
|
-
pareq: this.enrollmentResult.pareq,
|
|
188
|
-
reference: this.paymentIntent.payment.reference,
|
|
189
|
-
};
|
|
190
|
-
return [4 /*yield*/, this.gatewayClient.validateSCA(requestParams)];
|
|
191
|
-
case 3:
|
|
192
|
-
validateSCAResponse = (_a.sent()).data;
|
|
193
|
-
return [3 /*break*/, 5];
|
|
194
|
-
case 4:
|
|
195
|
-
errorResponse_1 = _a.sent();
|
|
196
|
-
message = 'FatZebra.3DS: Validation failed. Server error.';
|
|
197
|
-
(0, event_manager_1.emit)(types_1.PublicEvent.SCA_ERROR, {
|
|
198
|
-
errors: [message],
|
|
199
|
-
data: null,
|
|
200
|
-
});
|
|
201
|
-
console.log(message);
|
|
202
|
-
return [2 /*return*/];
|
|
203
|
-
case 5:
|
|
204
|
-
threedsData = threedsResponseData(validateSCAResponse);
|
|
205
|
-
scenario = getValidationResult(validateSCAResponse);
|
|
206
|
-
if (scenario.outcome.success) {
|
|
207
|
-
message = "FatZebra.3DS: 3DS success - ".concat(scenario.description, ".");
|
|
208
|
-
(0, event_manager_1.emit)(types_1.PublicEvent.SCA_SUCCESS, {
|
|
209
|
-
message: message,
|
|
210
|
-
data: threedsData,
|
|
211
|
-
});
|
|
212
|
-
console.log(message);
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
message = "FatZebra.3DS: 3DS error - ".concat(scenario.description);
|
|
216
|
-
(0, event_manager_1.emit)(types_1.PublicEvent.SCA_ERROR, {
|
|
217
|
-
errors: [message],
|
|
218
|
-
data: {
|
|
219
|
-
errorCode: scenario.outcome.errorCode
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
console.log(message);
|
|
223
|
-
}
|
|
224
|
-
return [2 /*return*/];
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}); });
|
|
228
|
-
_a.label = 6;
|
|
229
|
-
case 6:
|
|
230
|
-
_a.trys.push([6, 8, , 9]);
|
|
231
|
-
return [4 /*yield*/, this._cardinal.processBin(this.bin)];
|
|
232
|
-
case 7:
|
|
233
|
-
_a.sent();
|
|
234
|
-
return [3 /*break*/, 9];
|
|
235
|
-
case 8:
|
|
236
|
-
err_1 = _a.sent();
|
|
237
|
-
message = 'FatZebra.3DS: BIN verification failed.';
|
|
238
|
-
(0, event_manager_1.emit)(types_1.PublicEvent.SCA_ERROR, {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const decodeSCASessionResponse = (yield this.gatewayClient.decodeSCASession({
|
|
91
|
+
token: data.jwt
|
|
92
|
+
})).data;
|
|
93
|
+
if (data.processorTransactionId !== decodeSCASessionResponse.processor_transaction_id) {
|
|
94
|
+
const message = 'FatZebra.3DS: Validation failed. Invalid process transaction id.';
|
|
95
|
+
emit(PublicEvent.SCA_ERROR, {
|
|
239
96
|
errors: [message],
|
|
240
97
|
data: null
|
|
241
98
|
});
|
|
242
99
|
console.log(message);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
100
|
+
}
|
|
101
|
+
let validateSCAResponse;
|
|
102
|
+
try {
|
|
103
|
+
const requestParams = {
|
|
104
|
+
amount: this.paymentIntent.payment.amount,
|
|
105
|
+
authentication_transaction_id: this.enrollmentResult.authentication_transaction_id,
|
|
106
|
+
card_token: this.cardToken,
|
|
107
|
+
currency: this.paymentIntent.payment.currency,
|
|
108
|
+
pareq: this.enrollmentResult.pareq,
|
|
109
|
+
reference: this.paymentIntent.payment.reference,
|
|
110
|
+
};
|
|
111
|
+
validateSCAResponse = (yield this.gatewayClient.validateSCA(requestParams)).data;
|
|
112
|
+
}
|
|
113
|
+
catch (errorResponse) {
|
|
114
|
+
const message = 'FatZebra.3DS: Validation failed. Server error.';
|
|
115
|
+
emit(PublicEvent.SCA_ERROR, {
|
|
254
116
|
errors: [message],
|
|
255
|
-
data: null
|
|
117
|
+
data: null,
|
|
256
118
|
});
|
|
257
119
|
console.log(message);
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const threedsData = threedsResponseData(validateSCAResponse);
|
|
123
|
+
const scenario = getValidationResult(validateSCAResponse);
|
|
124
|
+
if (scenario.outcome.success) {
|
|
125
|
+
const message = `FatZebra.3DS: 3DS success - ${scenario.description}.`;
|
|
126
|
+
emit(PublicEvent.SCA_SUCCESS, {
|
|
127
|
+
message,
|
|
128
|
+
data: threedsData,
|
|
129
|
+
});
|
|
130
|
+
console.log(message);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const message = `FatZebra.3DS: 3DS error - ${scenario.description}`;
|
|
134
|
+
emit(PublicEvent.SCA_ERROR, {
|
|
135
|
+
errors: [message],
|
|
136
|
+
data: {
|
|
137
|
+
errorCode: scenario.outcome.errorCode
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
console.log(message);
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
// Cardinal processs BIN using directory server. This determines the 3DS version used.
|
|
145
|
+
try {
|
|
146
|
+
yield this._cardinal.processBin(this.bin);
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
const message = 'FatZebra.3DS: BIN verification failed.';
|
|
150
|
+
emit(PublicEvent.SCA_ERROR, {
|
|
151
|
+
errors: [message],
|
|
152
|
+
data: null
|
|
153
|
+
});
|
|
154
|
+
console.log(message);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
yield this.check3DSEnrollment();
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
const message = 'FatZebra.3DS: Enrollment failed. Server error.';
|
|
162
|
+
emit(PublicEvent.SCA_ERROR, {
|
|
163
|
+
errors: [message],
|
|
164
|
+
data: null
|
|
165
|
+
});
|
|
166
|
+
console.log(message);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.handleEnrollmentResult(this.enrollmentResult);
|
|
264
170
|
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
currency: payment.currency,
|
|
276
|
-
hide_card_holder: payment.hide_card_holder,
|
|
277
|
-
})];
|
|
278
|
-
case 1:
|
|
279
|
-
response = (_a.sent()).data;
|
|
280
|
-
return [2 /*return*/, response.jwt];
|
|
281
|
-
}
|
|
282
|
-
});
|
|
171
|
+
}
|
|
172
|
+
createCardinalJWT() {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const { payment } = this.paymentIntent;
|
|
175
|
+
const response = (yield this.gatewayClient.createSCASession({
|
|
176
|
+
amount: payment.amount,
|
|
177
|
+
currency: payment.currency,
|
|
178
|
+
hide_card_holder: payment.hide_card_holder,
|
|
179
|
+
})).data;
|
|
180
|
+
return response.jwt;
|
|
283
181
|
});
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
session_id: this.sessionId,
|
|
300
|
-
challenge_window_size: this.challengeWindowSize,
|
|
301
|
-
hide_card_holder: this.paymentIntent.payment.hide_card_holder,
|
|
302
|
-
customer: this.customerProperties(this.customer),
|
|
303
|
-
})];
|
|
304
|
-
case 1:
|
|
305
|
-
// Persist enrollResult state in memory for handlePaymentValidation handler
|
|
306
|
-
_a.enrollmentResult = (_b.sent()).data;
|
|
307
|
-
return [2 /*return*/];
|
|
308
|
-
}
|
|
309
|
-
});
|
|
182
|
+
}
|
|
183
|
+
check3DSEnrollment() {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
// Persist enrollResult state in memory for handlePaymentValidation handler
|
|
186
|
+
this.enrollmentResult = (yield this.gatewayClient.enrolSCA({
|
|
187
|
+
amount: this.paymentIntent.payment.amount,
|
|
188
|
+
card_token: this.cardToken,
|
|
189
|
+
currency: this.paymentIntent.payment.currency,
|
|
190
|
+
reference: this.paymentIntent.payment.reference,
|
|
191
|
+
verification: this.paymentIntent.verification,
|
|
192
|
+
session_id: this.sessionId,
|
|
193
|
+
challenge_window_size: this.challengeWindowSize,
|
|
194
|
+
hide_card_holder: this.paymentIntent.payment.hide_card_holder,
|
|
195
|
+
customer: this.customerProperties(this.customer),
|
|
196
|
+
})).data;
|
|
310
197
|
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
198
|
+
}
|
|
199
|
+
customerProperties(customer) {
|
|
200
|
+
let properties = {};
|
|
314
201
|
if (!customer)
|
|
315
202
|
return properties;
|
|
316
203
|
if (customer.firstName)
|
|
@@ -330,25 +217,25 @@ var Sca = /** @class */ (function () {
|
|
|
330
217
|
if (customer.country)
|
|
331
218
|
properties.country = customer.country;
|
|
332
219
|
return properties;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
220
|
+
}
|
|
221
|
+
handleEnrollmentResult(enrollSCAResponse) {
|
|
222
|
+
const threedsData = threedsResponseData(enrollSCAResponse);
|
|
223
|
+
const scenario = getEnrollmentResult(enrollSCAResponse);
|
|
337
224
|
if (scenario.outcome.authenticationType === 'challenge') {
|
|
338
225
|
this._cardinal.continue(enrollSCAResponse.acs_url, enrollSCAResponse.pareq, enrollSCAResponse.authentication_transaction_id);
|
|
339
226
|
return;
|
|
340
227
|
}
|
|
341
228
|
if (scenario.outcome.success) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
message
|
|
229
|
+
const message = `FatZebra.3DS: 3DS success - ${scenario.description}.`;
|
|
230
|
+
emit(PublicEvent.SCA_SUCCESS, {
|
|
231
|
+
message,
|
|
345
232
|
data: threedsData,
|
|
346
233
|
});
|
|
347
234
|
console.log(message);
|
|
348
235
|
}
|
|
349
236
|
else {
|
|
350
|
-
|
|
351
|
-
|
|
237
|
+
const message = `FatZebra.3DS: 3DS error - ${scenario.description}`;
|
|
238
|
+
emit(PublicEvent.SCA_ERROR, {
|
|
352
239
|
errors: [message],
|
|
353
240
|
data: {
|
|
354
241
|
errorCode: scenario.outcome.errorCode
|
|
@@ -356,39 +243,38 @@ var Sca = /** @class */ (function () {
|
|
|
356
243
|
});
|
|
357
244
|
console.log(message);
|
|
358
245
|
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
var threedsResponseData = function (response) {
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const threedsResponseData = (response) => {
|
|
363
249
|
return {
|
|
364
250
|
// CAVV: Visa & Amex only
|
|
365
251
|
// AAV: Mastercard only, known as UCAF
|
|
366
252
|
cavv: response.cavv || response.aav,
|
|
367
253
|
par: response.pares,
|
|
368
|
-
sli:
|
|
254
|
+
sli: toFzSli(response.eci),
|
|
369
255
|
xid: response.xid,
|
|
370
256
|
ver: response.enrolled,
|
|
371
257
|
directoryServerTxnId: response.directory_server_txn_id,
|
|
372
258
|
threedsVersion: response.version,
|
|
373
259
|
};
|
|
374
260
|
};
|
|
375
|
-
|
|
376
|
-
return
|
|
261
|
+
const getEnrollmentResult = (enrollment) => {
|
|
262
|
+
return enrollmentScenarios.find((item) => {
|
|
377
263
|
return item.reasonCode === enrollment.reason_code &&
|
|
378
264
|
item.veresEnrolled === enrollment.enrolled &&
|
|
379
265
|
item.pares === enrollment.pares &&
|
|
380
266
|
item.threedsVersion === getMajor3dsVersion(enrollment.version);
|
|
381
267
|
});
|
|
382
268
|
};
|
|
383
|
-
|
|
384
|
-
return
|
|
269
|
+
const getValidationResult = (validation) => {
|
|
270
|
+
return validationScenarios.find((item) => {
|
|
385
271
|
return item.reasonCode === validation.reason_code &&
|
|
386
272
|
item.pares === validation.pares &&
|
|
387
273
|
item.threedsVersion === getMajor3dsVersion(validation.version);
|
|
388
274
|
});
|
|
389
275
|
};
|
|
390
276
|
// 3DS versioning follows SEMVER format. The first charactor is the major version number.
|
|
391
|
-
|
|
277
|
+
const getMajor3dsVersion = (original) => {
|
|
392
278
|
return original[0];
|
|
393
279
|
};
|
|
394
|
-
|
|
280
|
+
export default Sca;
|