@tonder.io/ionic-lite-sdk 1.0.1 → 1.0.2-beta.TEC-1207.53fb846
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/README.md +38 -3
- package/dist/classes/3dsHandler.d.ts +26 -2
- package/dist/classes/BaseInlineCheckout.d.ts +12 -9
- package/dist/classes/liteCheckout.d.ts +1 -1
- package/dist/data/businessApi.d.ts +1 -1
- package/dist/data/coreApi.d.ts +15 -0
- package/dist/helpers/corePayment.d.ts +60 -0
- package/dist/helpers/safeUrl.d.ts +15 -0
- package/dist/helpers/sanitize3dsMarkup.d.ts +18 -0
- package/dist/helpers/utils.d.ts +1 -0
- package/dist/helpers/validations.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/shared/constants/apiEndpoints.d.ts +2 -0
- package/dist/shared/utils/appError.d.ts +9 -0
- package/dist/types/commons.d.ts +5 -0
- package/dist/types/core.d.ts +28 -0
- package/jest.config.ts +11 -1
- package/package.json +1 -1
- package/src/classes/3dsHandler.ts +134 -30
- package/src/classes/BaseInlineCheckout.ts +128 -16
- package/src/classes/liteCheckout.ts +9 -2
- package/src/data/businessApi.ts +13 -6
- package/src/data/coreApi.ts +47 -0
- package/src/helpers/corePayment.ts +211 -0
- package/src/helpers/safeUrl.ts +26 -0
- package/src/helpers/sanitize3dsMarkup.ts +133 -0
- package/src/helpers/utils.ts +4 -0
- package/src/helpers/validations.ts +9 -0
- package/src/shared/constants/apiEndpoints.ts +2 -0
- package/src/shared/constants/messages.ts +4 -4
- package/src/shared/utils/appError.ts +28 -11
- package/src/types/commons.ts +5 -0
- package/src/types/core.ts +30 -0
- package/tests/coreBusinessConfig.test.ts +100 -0
- package/tests/corePayment.test.ts +393 -0
- package/tests/corePaymentCheckout.test.ts +668 -0
- package/tests/coreStartupFailure.test.ts +70 -0
- package/tests/redirectToChallenge.test.ts +149 -0
- package/tests/sanitize3dsMarkup.test.ts +248 -0
- package/tests/secureTokenBoundary.test.ts +81 -0
- package/tests/threeDsApiKey.test.ts +41 -0
- package/tests/threeDsCore.test.ts +444 -0
- package/tests/threeDsPolling.test.ts +45 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildCoreProcessBody,
|
|
3
|
+
rebuildCheckoutResult,
|
|
4
|
+
} from "../src/helpers/corePayment";
|
|
5
|
+
|
|
6
|
+
const CORE_BASE = "https://api-stage.tonder.io";
|
|
7
|
+
const CTX = { coreBaseUrl: CORE_BASE };
|
|
8
|
+
const PUBLIC_ID = "0192b8a0-0000-7000-8000-000000000001";
|
|
9
|
+
|
|
10
|
+
const ITEMS = [
|
|
11
|
+
{
|
|
12
|
+
name: "Shirt",
|
|
13
|
+
description: "Blue",
|
|
14
|
+
quantity: 2,
|
|
15
|
+
price_unit: 50,
|
|
16
|
+
discount: 0,
|
|
17
|
+
taxes: 0,
|
|
18
|
+
product_reference: "sku-1",
|
|
19
|
+
amount_total: 100,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const NEW_CARD = {
|
|
24
|
+
card_number: "tok-number",
|
|
25
|
+
cvv: "tok-cvv",
|
|
26
|
+
expiration_month: "tok-month",
|
|
27
|
+
expiration_year: "tok-year",
|
|
28
|
+
cardholder_name: "tok-name",
|
|
29
|
+
skyflow_id: "sf-1",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function baseInput(overrides: Record<string, unknown> = {}) {
|
|
33
|
+
return {
|
|
34
|
+
amount: 100,
|
|
35
|
+
currency: "MXN",
|
|
36
|
+
reference: "TNDR-1",
|
|
37
|
+
customer: { firstName: "Ana", lastName: "Lopez", email: "ana@example.com", phone: "555" },
|
|
38
|
+
card: NEW_CARD,
|
|
39
|
+
metadata: { order_id: "o-1" },
|
|
40
|
+
returnUrl: "https://shop.example.com/done",
|
|
41
|
+
items: ITEMS,
|
|
42
|
+
...overrides,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe("buildCoreProcessBody", () => {
|
|
47
|
+
it("maps a new card to the vault field tokens, without the vault record id", () => {
|
|
48
|
+
const body = buildCoreProcessBody(baseInput());
|
|
49
|
+
|
|
50
|
+
expect(body.payment_method).toEqual({
|
|
51
|
+
type: "CARD",
|
|
52
|
+
card_number: "tok-number",
|
|
53
|
+
cvv: "tok-cvv",
|
|
54
|
+
expiration_month: "tok-month",
|
|
55
|
+
expiration_year: "tok-year",
|
|
56
|
+
cardholder_name: "tok-name",
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("maps a saved card to its vault record id as the token", () => {
|
|
61
|
+
const body = buildCoreProcessBody(baseInput({ card: { skyflow_id: "sf-9" } }));
|
|
62
|
+
|
|
63
|
+
expect(body.payment_method).toEqual({ type: "CARD", token: "sf-9" });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("sends the payment the way the legacy flow described it", () => {
|
|
67
|
+
const body = buildCoreProcessBody(baseInput());
|
|
68
|
+
|
|
69
|
+
expect(body).toMatchObject({
|
|
70
|
+
operation_type: "payment",
|
|
71
|
+
amount: 100,
|
|
72
|
+
currency: "MXN",
|
|
73
|
+
client_reference: "TNDR-1",
|
|
74
|
+
customer: { name: "Ana Lopez", email: "ana@example.com" },
|
|
75
|
+
metadata: { order_id: "o-1" },
|
|
76
|
+
return_url: "https://shop.example.com/done",
|
|
77
|
+
items: ITEMS,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("takes the customer name from the deprecated name and lastname fields too", () => {
|
|
82
|
+
const body = buildCoreProcessBody(
|
|
83
|
+
baseInput({ customer: { name: "Ana", lastname: "Lopez", email: "a@example.com" } }),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(body.customer).toEqual({ name: "Ana Lopez", email: "a@example.com" });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("leaves out what the merchant did not send", () => {
|
|
90
|
+
const body = buildCoreProcessBody(
|
|
91
|
+
baseInput({ currency: undefined, metadata: undefined, items: undefined, returnUrl: undefined }),
|
|
92
|
+
);
|
|
93
|
+
const sent = JSON.parse(JSON.stringify(body));
|
|
94
|
+
|
|
95
|
+
expect(sent).not.toHaveProperty("currency");
|
|
96
|
+
expect(sent).not.toHaveProperty("metadata");
|
|
97
|
+
expect(sent).not.toHaveProperty("items");
|
|
98
|
+
expect(sent).not.toHaveProperty("return_url");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("never sends the legacy order, payment or checkout anchors", () => {
|
|
102
|
+
const sent = JSON.parse(JSON.stringify(buildCoreProcessBody(baseInput())));
|
|
103
|
+
|
|
104
|
+
for (const key of ["order_id", "payment_id", "checkout_id", "business_id", "routing"]) {
|
|
105
|
+
expect(sent).not.toHaveProperty(key);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const SUCCESS = {
|
|
111
|
+
id: PUBLIC_ID,
|
|
112
|
+
status: "Success",
|
|
113
|
+
amount: 100,
|
|
114
|
+
currency: "MXN",
|
|
115
|
+
provider: "tonder",
|
|
116
|
+
status_code: 201,
|
|
117
|
+
payment_id: 55,
|
|
118
|
+
transaction_id: "9",
|
|
119
|
+
transaction_status: "Success",
|
|
120
|
+
psp_response: { id: "psp-1" },
|
|
121
|
+
routing: { checkout_id: "chk-1", is_route_finished: true },
|
|
122
|
+
next_action: { verify_transaction_status_url: `/transactions/v1/${PUBLIC_ID}` },
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const VERIFY_ACTION = {
|
|
126
|
+
name: "verify_transaction_status",
|
|
127
|
+
url: `${CORE_BASE}/transactions/v1/${PUBLIC_ID}`,
|
|
128
|
+
method: "GET",
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
describe("rebuildCheckoutResult", () => {
|
|
132
|
+
it("points the verify action of a core payment at the core's GET by public id", () => {
|
|
133
|
+
const { actions } = rebuildCheckoutResult(201, SUCCESS, CTX).body;
|
|
134
|
+
|
|
135
|
+
expect(actions[0]).toEqual({
|
|
136
|
+
name: "verify_transaction_status",
|
|
137
|
+
url: `${CORE_BASE}/transactions/v1/${PUBLIC_ID}`,
|
|
138
|
+
method: "GET",
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("rebuilds the checkout-router body of an approved payment", () => {
|
|
143
|
+
const result = rebuildCheckoutResult(201, SUCCESS, CTX);
|
|
144
|
+
|
|
145
|
+
expect(result.outcome).toBe("resolve");
|
|
146
|
+
expect(result.body).toEqual({
|
|
147
|
+
status: "200",
|
|
148
|
+
message: "Success",
|
|
149
|
+
checkout_id: "chk-1",
|
|
150
|
+
is_route_finished: true,
|
|
151
|
+
transaction_status: "Success",
|
|
152
|
+
transaction_id: 9,
|
|
153
|
+
payment_id: 55,
|
|
154
|
+
provider: "tonder",
|
|
155
|
+
next_action: SUCCESS.next_action,
|
|
156
|
+
psp_response: { id: "psp-1" },
|
|
157
|
+
actions: [
|
|
158
|
+
VERIFY_ACTION,
|
|
159
|
+
{
|
|
160
|
+
name: "refund_transaction",
|
|
161
|
+
url: `${CORE_BASE}/transactions/v1/process`,
|
|
162
|
+
method: "POST",
|
|
163
|
+
body: { operation_type: "refund", original_transaction_id: PUBLIC_ID },
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("reports the core's status as transaction_status, never the rail's", () => {
|
|
170
|
+
const open = rebuildCheckoutResult(
|
|
171
|
+
201,
|
|
172
|
+
{ ...SUCCESS, status: "Processing", transaction_status: "Declined" },
|
|
173
|
+
CTX,
|
|
174
|
+
);
|
|
175
|
+
const declined = rebuildCheckoutResult(
|
|
176
|
+
200,
|
|
177
|
+
{ ...SUCCESS, status: "Declined", decline_code: "05", transaction_status: "Pending" },
|
|
178
|
+
CTX,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
expect(open.body.transaction_status).toBe("Processing");
|
|
182
|
+
expect(declined.body.transaction_status).toBe("Declined");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("keeps the 3DS redirect of a pending payment and its verify URL", () => {
|
|
186
|
+
const redirect = {
|
|
187
|
+
redirect_to_url: {
|
|
188
|
+
url: "https://payflow.example.com/process?token=t#session=s",
|
|
189
|
+
return_url: "https://shop.example.com/done",
|
|
190
|
+
verify_transaction_status_url: `/transactions/v1/${PUBLIC_ID}`,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const result = rebuildCheckoutResult(
|
|
195
|
+
201,
|
|
196
|
+
{ ...SUCCESS, status: "Pending", transaction_status: "Pending", next_action: redirect,
|
|
197
|
+
routing: { checkout_id: "chk-1", is_route_finished: false } },
|
|
198
|
+
CTX,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
expect(result.outcome).toBe("resolve");
|
|
202
|
+
expect(result.body.transaction_status).toBe("Pending");
|
|
203
|
+
expect(result.body.is_route_finished).toBe(false);
|
|
204
|
+
expect(result.body.next_action).toEqual(redirect);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const DECLINE = {
|
|
208
|
+
...SUCCESS,
|
|
209
|
+
status: "Declined",
|
|
210
|
+
status_code: 200,
|
|
211
|
+
transaction_status: "Declined",
|
|
212
|
+
decline_code: "05",
|
|
213
|
+
decline_reason: "Do not honor",
|
|
214
|
+
next_action: undefined,
|
|
215
|
+
routing: {
|
|
216
|
+
checkout_id: "chk-1",
|
|
217
|
+
is_route_finished: true,
|
|
218
|
+
decline_type: "Soft",
|
|
219
|
+
rejected_psp_responses: [{ id: "r1" }, { id: "r2" }],
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
it("rejects a declined payment with the 404 body the router answered", () => {
|
|
224
|
+
const result = rebuildCheckoutResult(200, DECLINE, CTX);
|
|
225
|
+
|
|
226
|
+
expect(result.outcome).toBe("reject");
|
|
227
|
+
expect(result.status).toBe(404);
|
|
228
|
+
expect(result.body).toEqual({
|
|
229
|
+
status: "404",
|
|
230
|
+
message: "Do not honor",
|
|
231
|
+
checkout_id: "chk-1",
|
|
232
|
+
is_route_finished: true,
|
|
233
|
+
transaction_status: "Declined",
|
|
234
|
+
transaction_id: 9,
|
|
235
|
+
payment_id: 55,
|
|
236
|
+
provider: "tonder",
|
|
237
|
+
decline_code: "05",
|
|
238
|
+
psp_response: [{ id: "r1" }, { id: "r2" }],
|
|
239
|
+
actions: [
|
|
240
|
+
VERIFY_ACTION,
|
|
241
|
+
{
|
|
242
|
+
name: "refund_transaction",
|
|
243
|
+
url: `${CORE_BASE}/transactions/v1/process`,
|
|
244
|
+
method: "POST",
|
|
245
|
+
body: { operation_type: "refund", original_transaction_id: PUBLIC_ID },
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("answers a hard decline with its own message and the single rail response", () => {
|
|
252
|
+
const result = rebuildCheckoutResult(
|
|
253
|
+
200,
|
|
254
|
+
{
|
|
255
|
+
...DECLINE,
|
|
256
|
+
routing: {
|
|
257
|
+
...DECLINE.routing,
|
|
258
|
+
decline_type: "Hard",
|
|
259
|
+
rejected_psp_responses: [{ id: "r1" }, { id: "hard" }],
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
CTX,
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
expect(result.status).toBe(404);
|
|
266
|
+
expect(result.body.message).toBe("Hard decline");
|
|
267
|
+
expect(result.body.psp_response).toEqual({ id: "hard" });
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("answers a failed payment like a declined one", () => {
|
|
271
|
+
const result = rebuildCheckoutResult(
|
|
272
|
+
200,
|
|
273
|
+
{ ...DECLINE, status: "Failed", transaction_status: "Failed" },
|
|
274
|
+
CTX,
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
expect(result.outcome).toBe("reject");
|
|
278
|
+
expect(result.body.transaction_status).toBe("Failed");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("resolves a Guardian block with a 200 body, as the router answered it", () => {
|
|
282
|
+
const result = rebuildCheckoutResult(
|
|
283
|
+
200,
|
|
284
|
+
{
|
|
285
|
+
...DECLINE,
|
|
286
|
+
decline_code: "FH01",
|
|
287
|
+
decline_reason: "High risk transaction blocked",
|
|
288
|
+
transaction_id: "guardian-row-1",
|
|
289
|
+
psp_response: { guardian: true },
|
|
290
|
+
routing: { checkout_id: "chk-1", is_route_finished: true },
|
|
291
|
+
},
|
|
292
|
+
CTX,
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
expect(result.outcome).toBe("resolve");
|
|
296
|
+
expect(result.body).toEqual({
|
|
297
|
+
status: "200",
|
|
298
|
+
message: "High risk transaction blocked",
|
|
299
|
+
checkout_id: "chk-1",
|
|
300
|
+
transaction_status: "Declined",
|
|
301
|
+
transaction_id: "guardian-row-1",
|
|
302
|
+
payment_id: 55,
|
|
303
|
+
provider: "tonder",
|
|
304
|
+
amount: 100,
|
|
305
|
+
currency: "MXN",
|
|
306
|
+
psp_response: { guardian: true },
|
|
307
|
+
decline_code: "FH01",
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it.each(["Success", "Authorized", "Pending", "Processing"])(
|
|
312
|
+
"resolves a '%s' payment",
|
|
313
|
+
(status) => {
|
|
314
|
+
expect(rebuildCheckoutResult(201, { ...SUCCESS, status }, CTX).outcome).toBe("resolve");
|
|
315
|
+
},
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
it.each(["Cancelled", "Canceled", "Expired", "Voided", "Returned", "Error", "SomethingNew", ""])(
|
|
319
|
+
"never treats a '%s' status as approved",
|
|
320
|
+
(status) => {
|
|
321
|
+
const result = rebuildCheckoutResult(201, { ...SUCCESS, status }, CTX);
|
|
322
|
+
|
|
323
|
+
expect(result.outcome).toBe("reject");
|
|
324
|
+
expect(result.status).toBe(404);
|
|
325
|
+
expect(result.body.status).toBe("404");
|
|
326
|
+
expect(result.body.message).not.toBe("Success");
|
|
327
|
+
expect(result.body.transaction_status).toBe(status);
|
|
328
|
+
},
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
it("never treats an answer without a status as approved", () => {
|
|
332
|
+
expect(rebuildCheckoutResult(201, { id: "x" }, CTX).outcome).toBe("reject");
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it.each(["Cancelled", "Expired", "SomethingNew", "Failed"])(
|
|
336
|
+
"does not take the Guardian shape for a '%s' payment carrying the Guardian code",
|
|
337
|
+
(status) => {
|
|
338
|
+
const result = rebuildCheckoutResult(
|
|
339
|
+
200,
|
|
340
|
+
{ ...SUCCESS, status, decline_code: "FH01", decline_reason: "blocked" },
|
|
341
|
+
CTX,
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
expect(result.outcome).toBe("reject");
|
|
345
|
+
expect(result.body.status).toBe("404");
|
|
346
|
+
expect(result.body.transaction_status).toBe(status);
|
|
347
|
+
},
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
it("rebuilds every refusal of the core in one place, keeping the status text", () => {
|
|
351
|
+
const result = rebuildCheckoutResult(
|
|
352
|
+
409,
|
|
353
|
+
{ error: { code: "conflict", message: "busy", type: "conflict" }, request_id: "r-1" },
|
|
354
|
+
CTX,
|
|
355
|
+
"Conflict",
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
expect(result).toEqual({
|
|
359
|
+
outcome: "reject",
|
|
360
|
+
status: 409,
|
|
361
|
+
statusText: "Conflict",
|
|
362
|
+
body: { status: "409", message: "busy", psp_response: [], is_route_finished: false },
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("rebuilds a 402 other than a declined payment as a refusal, not as an ended route", () => {
|
|
367
|
+
const result = rebuildCheckoutResult(
|
|
368
|
+
402,
|
|
369
|
+
{ error: { code: "payment_required", message: "pay", type: "business_error" } },
|
|
370
|
+
CTX,
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
expect(result.status).toBe(402);
|
|
374
|
+
expect(result.body.is_route_finished).toBe(false);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("rejects the normalized 402 of a route that ended with no transaction", () => {
|
|
378
|
+
const result = rebuildCheckoutResult(
|
|
379
|
+
402,
|
|
380
|
+
{ error: { code: "payment_declined", message: "declined", type: "business_error" } },
|
|
381
|
+
CTX,
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
expect(result.outcome).toBe("reject");
|
|
385
|
+
expect(result.status).toBe(404);
|
|
386
|
+
expect(result.body).toEqual({
|
|
387
|
+
status: "404",
|
|
388
|
+
message: "Error",
|
|
389
|
+
psp_response: [],
|
|
390
|
+
is_route_finished: true,
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
});
|