@tonder.io/ionic-lite-sdk 0.0.35-beta.2 → 0.0.35-beta.20

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.
Files changed (40) hide show
  1. package/.idea/prettier.xml +6 -0
  2. package/.idea/workspace.xml +37 -47
  3. package/dist/classes/BaseInlineCheckout.d.ts +14 -15
  4. package/dist/classes/liteCheckout.d.ts +8 -9
  5. package/dist/data/paymentMethodApi.d.ts +1 -1
  6. package/dist/helpers/skyflow.d.ts +1 -1
  7. package/dist/helpers/utils.d.ts +1 -1
  8. package/dist/index.d.ts +3 -1
  9. package/dist/index.js +1 -1
  10. package/dist/types/card.d.ts +1 -0
  11. package/dist/types/checkout.d.ts +2 -1
  12. package/dist/types/commons.d.ts +6 -3
  13. package/dist/types/customer.d.ts +10 -0
  14. package/dist/types/transaction.d.ts +101 -0
  15. package/package.json +3 -1
  16. package/src/classes/BaseInlineCheckout.ts +363 -300
  17. package/src/classes/errorResponse.ts +1 -1
  18. package/src/classes/liteCheckout.ts +267 -213
  19. package/src/data/businessApi.ts +16 -12
  20. package/src/data/cardApi.ts +65 -62
  21. package/src/data/checkoutApi.ts +73 -60
  22. package/src/data/customerApi.ts +26 -26
  23. package/src/data/openPayApi.ts +12 -7
  24. package/src/data/paymentMethodApi.ts +32 -29
  25. package/src/data/skyflowApi.ts +18 -14
  26. package/src/helpers/mercadopago.ts +14 -14
  27. package/src/helpers/skyflow.ts +35 -29
  28. package/src/helpers/utils.ts +51 -39
  29. package/src/helpers/validations.ts +35 -35
  30. package/src/index.ts +9 -1
  31. package/src/shared/catalog/paymentMethodsCatalog.ts +8 -8
  32. package/src/shared/constants/paymentMethodAPM.ts +59 -59
  33. package/src/shared/constants/tonderUrl.ts +4 -4
  34. package/src/types/card.ts +1 -0
  35. package/src/types/checkout.ts +2 -1
  36. package/src/types/commons.ts +101 -99
  37. package/src/types/customer.ts +10 -0
  38. package/src/types/liteInlineCheckout.d.ts +207 -184
  39. package/src/types/transaction.ts +101 -0
  40. package/src/types/index.d.ts +0 -10
@@ -1,318 +1,381 @@
1
- import {ThreeDSHandler} from "./3dsHandler";
1
+ import { ThreeDSHandler } from "./3dsHandler";
2
+ import { ErrorResponse } from "./errorResponse";
3
+ import { fetchBusiness } from "../data/businessApi";
4
+ import { injectMercadoPagoSecurity } from "../helpers/mercadopago";
5
+ import { TONDER_URL_BY_MODE } from "../shared/constants/tonderUrl";
6
+ import {
7
+ createOrder,
8
+ createPayment,
9
+ startCheckoutRouter,
10
+ } from "../data/checkoutApi";
11
+ import { getOpenpayDeviceSessionID } from "../data/openPayApi";
12
+ import { getBrowserInfo } from "../helpers/utils";
13
+ import { registerOrFetchCustomer } from "../data/customerApi";
14
+ import { get } from "lodash";
15
+ import {
16
+ fetchCustomerCards,
17
+ removeCustomerCard,
18
+ saveCustomerCard,
19
+ } from "../data/cardApi";
20
+ import { fetchCustomerPaymentMethods } from "../data/paymentMethodApi";
2
21
  import {Business, IConfigureCheckout, IInlineCheckoutBaseOptions} from "../types/commons";
3
- import {ErrorResponse} from "./errorResponse";
4
- import {fetchBusiness} from "../data/businessApi";
5
- import {injectMercadoPagoSecurity} from "../helpers/mercadopago";
6
- import {TONDER_URL_BY_MODE} from "../shared/constants/tonderUrl";
22
+ import {ICustomer} from "../types/customer";
7
23
  import {ICardFields, IItem, IProcessPaymentRequest, IStartCheckoutResponse} from "../types/checkout";
24
+ import {ICustomerCardsResponse, ISaveCardResponse, ISaveCardSkyflowRequest} from "../types/card";
25
+ import {IPaymentMethodResponse} from "../types/paymentMethod";
8
26
  import {StartCheckoutResponse} from "../types/responses";
9
- import {createOrder, createPayment, startCheckoutRouter} from "../data/checkoutApi";
10
- import {getOpenpayDeviceSessionID} from "../data/openPayApi";
11
- import {getBrowserInfo} from "../helpers/utils";
12
- import {registerOrFetchCustomer} from "../data/customerApi";
13
- import {ICustomer} from "../types/customer";
14
-
15
27
  export class BaseInlineCheckout {
16
- baseUrl = "";
17
- cartTotal = "0";
18
- process3ds: ThreeDSHandler;
19
- mode?: "production" | "sandbox" | "stage" | "development" | undefined;
20
- apiKeyTonder: string;
21
- returnUrl: string;
22
- callBack?: ((response: any) => void) | undefined;
23
- merchantData?: Business;
24
- abortController: AbortController;
25
-
26
- firstName?: string
27
- lastName?: string
28
- country?: string
29
- address?: string
30
- city?: string
31
- state?: string
32
- postCode?: string
33
- email?: string
34
- phone?: string
35
- customer?: ICustomer
36
-
37
- cartItems?: IItem[]
38
- metadata = {}
39
- card? = {}
40
- currency?: string = ""
41
-
42
- #customerData?: Record<string, any>;
43
-
44
- constructor({ mode = "stage", apiKey, apiKeyTonder, returnUrl, callBack = () => {} }: IInlineCheckoutBaseOptions) {
45
- this.apiKeyTonder = apiKey || apiKeyTonder || '';
46
- this.returnUrl = returnUrl;
47
- this.callBack = callBack;
48
- this.mode = mode;
49
- this.baseUrl = TONDER_URL_BY_MODE[this.mode] || TONDER_URL_BY_MODE["stage"];
50
- this.abortController = new AbortController();
51
- this.process3ds = new ThreeDSHandler({
52
- apiKey: apiKey,
53
- baseUrl: this.baseUrl,
54
- });
55
- }
56
-
57
-
58
- configureCheckout(data: IConfigureCheckout) {
59
- if ("customer" in data) this.#handleCustomer(data["customer"]);
60
- }
61
-
62
- async verify3dsTransaction () {
63
- const result3ds = await this.process3ds.verifyTransactionStatus()
64
- const resultCheckout = await this.#resumeCheckout(result3ds)
65
- this.process3ds.setPayload(resultCheckout)
66
- return this._handle3dsRedirect(resultCheckout)
67
- }
68
-
69
- payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse> {
70
- return new Promise(async (resolve, reject) => {
71
- try {
72
- this.#handleCustomer(data.customer);
73
- this._setCartTotal(data.cart?.total);
74
- this.#setCartItems(data.cart?.items);
75
- this.#handleMetadata(data);
76
- this.#handleCurrency(data);
77
- this.#handleCard(data);
78
- const response = await this._checkout(data);
79
- this.process3ds.setPayload(response);
80
- if(this.callBack)
81
- this.callBack!(response);
82
- const payload = await this._handle3dsRedirect(response);
83
- if (payload) {
84
- resolve(response);
85
- }
86
- } catch (error) {
87
- reject(error);
88
- }
89
- });
90
- }
91
-
92
- async _initializeCheckout() {
93
- const business_response = await this._fetchMerchantData();
94
-
95
- if (!!business_response && !!business_response.mercado_pago && business_response.mercado_pago.active) {
96
- injectMercadoPagoSecurity();
28
+ baseUrl = "";
29
+ cartTotal = "0";
30
+ process3ds: ThreeDSHandler;
31
+ mode?: "production" | "sandbox" | "stage" | "development" | undefined;
32
+ apiKeyTonder: string;
33
+ returnUrl?: string;
34
+ callBack?: ((response: any) => void) | undefined;
35
+ merchantData?: Business;
36
+ abortController: AbortController;
37
+
38
+ customer?: ICustomer | { email: string };
39
+
40
+ cartItems?: IItem[];
41
+ metadata = {};
42
+ card? = {};
43
+ currency?: string = "";
44
+
45
+ #customerData?: Record<string, any>;
46
+
47
+ constructor({
48
+ mode = "stage",
49
+ apiKey,
50
+ apiKeyTonder,
51
+ returnUrl,
52
+ callBack = () => {},
53
+ }: IInlineCheckoutBaseOptions) {
54
+ this.apiKeyTonder = apiKey || apiKeyTonder || "";
55
+ this.returnUrl = returnUrl;
56
+ this.callBack = callBack;
57
+ this.mode = mode;
58
+ this.customer = {} as ICustomer
59
+ this.baseUrl = TONDER_URL_BY_MODE[this.mode] || TONDER_URL_BY_MODE["stage"];
60
+ this.abortController = new AbortController();
61
+ this.process3ds = new ThreeDSHandler({
62
+ apiKey: apiKey,
63
+ baseUrl: this.baseUrl,
64
+ });
65
+ }
66
+
67
+ configureCheckout(data: IConfigureCheckout) {
68
+ if ("customer" in data) this.#handleCustomer(data["customer"]);
69
+ }
70
+
71
+ async verify3dsTransaction() {
72
+ const result3ds = await this.process3ds.verifyTransactionStatus();
73
+ const resultCheckout = await this.#resumeCheckout(result3ds);
74
+ this.process3ds.setPayload(resultCheckout);
75
+ return this._handle3dsRedirect(resultCheckout);
76
+ }
77
+
78
+ payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse> {
79
+ return new Promise(async (resolve, reject) => {
80
+ try {
81
+ this.#handleCustomer(data.customer);
82
+ this._setCartTotal(data.cart?.total);
83
+ this.#setCartItems(data.cart?.items);
84
+ this.#handleMetadata(data);
85
+ this.#handleCurrency(data);
86
+ this.#handleCard(data);
87
+ const response = await this._checkout(data);
88
+ this.process3ds.setPayload(response);
89
+ if (this.callBack) this.callBack!(response);
90
+ const payload = await this._handle3dsRedirect(response);
91
+ if (payload) {
92
+ resolve(response);
97
93
  }
94
+ } catch (error) {
95
+ reject(error);
96
+ }
97
+ });
98
+ }
99
+
100
+ async _initializeCheckout() {
101
+ const business_response = await this._fetchMerchantData();
102
+
103
+ if (
104
+ !!business_response &&
105
+ !!business_response.mercado_pago &&
106
+ business_response.mercado_pago.active
107
+ ) {
108
+ injectMercadoPagoSecurity();
98
109
  }
99
-
100
- async _checkout(data: any): Promise<any> {
101
- throw new Error(
102
- "The #checkout method should be implement in child classes.",
110
+ }
111
+
112
+ async _checkout(data: any): Promise<any> {
113
+ throw new Error(
114
+ "The #checkout method should be implement in child classes.",
115
+ );
116
+ }
117
+
118
+ _setCartTotal(total: string | number) {
119
+ throw new Error(
120
+ "The #setCartTotal method should be implement in child classes.",
121
+ );
122
+ }
123
+
124
+ async _getCustomer(signal: AbortSignal | null = null) {
125
+ if (!!this.#customerData) return this.#customerData!;
126
+
127
+ this.#customerData = await registerOrFetchCustomer(
128
+ this.baseUrl,
129
+ this.apiKeyTonder,
130
+ this.customer!,
131
+ signal,
132
+ );
133
+ return this.#customerData!;
134
+ }
135
+
136
+ async _handleCheckout({
137
+ card,
138
+ payment_method,
139
+ customer,
140
+ isSandbox,
141
+ }: {
142
+ card?: string;
143
+ payment_method?: string;
144
+ customer: Record<string, any>;
145
+ isSandbox?: boolean;
146
+ }) {
147
+ const { openpay_keys, reference, business } = this.merchantData!;
148
+ const total = Number(this.cartTotal);
149
+ try {
150
+ let deviceSessionIdTonder;
151
+ if (
152
+ !deviceSessionIdTonder &&
153
+ openpay_keys.merchant_id &&
154
+ openpay_keys.public_key
155
+ ) {
156
+ deviceSessionIdTonder = await getOpenpayDeviceSessionID(
157
+ openpay_keys.merchant_id,
158
+ openpay_keys.public_key,
159
+ isSandbox,
160
+ this.abortController.signal,
103
161
  );
162
+ }
163
+
164
+ const { id, auth_token } = customer;
165
+
166
+ const orderItems = {
167
+ business: this.apiKeyTonder,
168
+ client: auth_token,
169
+ billing_address_id: null,
170
+ shipping_address_id: null,
171
+ amount: total,
172
+ status: "A",
173
+ reference: reference,
174
+ is_oneclick: true,
175
+ items: this.cartItems!,
176
+ };
177
+ const jsonResponseOrder = await createOrder(
178
+ this.baseUrl,
179
+ this.apiKeyTonder,
180
+ orderItems,
181
+ );
182
+
183
+ // Create payment
184
+ const now = new Date();
185
+ const dateString = now.toISOString();
186
+
187
+ const paymentItems = {
188
+ business_pk: business.pk,
189
+ client_id: id,
190
+ amount: total,
191
+ date: dateString,
192
+ order_id: jsonResponseOrder.id,
193
+ };
194
+ const jsonResponsePayment = await createPayment(
195
+ this.baseUrl,
196
+ this.apiKeyTonder,
197
+ paymentItems,
198
+ );
199
+
200
+ // Checkout router
201
+ const routerItems = {
202
+ name: get(this.customer, "firstName", get(this.customer, "name", "")),
203
+ last_name: get(
204
+ this.customer,
205
+ "lastName",
206
+ get(this.customer, "lastname", ""),
207
+ ),
208
+ email_client: get(this.customer, "email", ""),
209
+ phone_number: get(this.customer, "phone", ""),
210
+ return_url: this.returnUrl,
211
+ id_product: "no_id",
212
+ quantity_product: 1,
213
+ id_ship: "0",
214
+ instance_id_ship: "0",
215
+ amount: total,
216
+ title_ship: "shipping",
217
+ description: "transaction",
218
+ device_session_id: deviceSessionIdTonder ? deviceSessionIdTonder : null,
219
+ token_id: "",
220
+ order_id: jsonResponseOrder.id,
221
+ business_id: business.pk,
222
+ payment_id: jsonResponsePayment.pk,
223
+ source: "sdk",
224
+ metadata: this.metadata,
225
+ browser_info: getBrowserInfo(),
226
+ currency: this.currency!,
227
+ ...(!!payment_method ? { payment_method } : { card }),
228
+ };
229
+
230
+ const jsonResponseRouter = await startCheckoutRouter(
231
+ this.baseUrl,
232
+ this.apiKeyTonder,
233
+ routerItems,
234
+ );
235
+
236
+ if (jsonResponseRouter) {
237
+ return jsonResponseRouter;
238
+ } else {
239
+ return false;
240
+ }
241
+ } catch (error) {
242
+ console.log(error);
243
+ throw error;
104
244
  }
105
-
106
- _setCartTotal(total: string | number) {
107
- throw new Error(
108
- "The #setCartTotal method should be implement in child classes.",
245
+ }
246
+
247
+ async _fetchMerchantData() {
248
+ try {
249
+ if (!this.merchantData) {
250
+ this.merchantData = await fetchBusiness(
251
+ this.baseUrl,
252
+ this.apiKeyTonder,
253
+ this.abortController.signal,
109
254
  );
255
+ }
256
+ return this.merchantData;
257
+ } catch (e) {
258
+ return this.merchantData;
110
259
  }
111
-
112
- async _getCustomer(signal: AbortSignal | null = null) {
113
- if (!!this.#customerData) return this.#customerData!;
114
-
115
- this.#customerData = await registerOrFetchCustomer(
116
- this.baseUrl,
117
- this.apiKeyTonder,
118
- this.customer!,
119
- signal
120
- );
121
- return this.#customerData!;
122
- }
123
-
124
- async _handleCheckout({ card, payment_method, customer, isSandbox }: {card?: string; payment_method?: string; customer: Record<string, any>; isSandbox?: boolean}) {
125
- const { openpay_keys, reference, business } = this.merchantData!;
126
- const total = Number(this.cartTotal);
127
- try {
128
- let deviceSessionIdTonder;
129
- if (
130
- !deviceSessionIdTonder &&
131
- openpay_keys.merchant_id &&
132
- openpay_keys.public_key
133
- ) {
134
- deviceSessionIdTonder = await getOpenpayDeviceSessionID(
135
- openpay_keys.merchant_id,
136
- openpay_keys.public_key,
137
- isSandbox,
138
- this.abortController.signal,
139
- );
140
- }
141
-
142
- const { id, auth_token } = customer;
143
-
144
- const orderItems = {
145
- business: this.apiKeyTonder,
146
- client: auth_token,
147
- billing_address_id: null,
148
- shipping_address_id: null,
149
- amount: total,
150
- status: "A",
151
- reference: reference,
152
- is_oneclick: true,
153
- items: this.cartItems!,
154
- };
155
- const jsonResponseOrder = await createOrder(
156
- this.baseUrl,
157
- this.apiKeyTonder,
158
- orderItems,
159
- );
160
-
161
- // Create payment
162
- const now = new Date();
163
- const dateString = now.toISOString();
164
-
165
- const paymentItems = {
166
- business_pk: business.pk,
167
- client_id: id,
168
- amount: total,
169
- date: dateString,
170
- order_id: jsonResponseOrder.id,
171
- };
172
- const jsonResponsePayment = await createPayment(
173
- this.baseUrl,
174
- this.apiKeyTonder,
175
- paymentItems,
176
- );
177
-
178
- // Checkout router
179
- const routerItems = {
180
- name: this.firstName || "",
181
- last_name: this.lastName || "",
182
- email_client: this.email,
183
- phone_number: this.phone,
184
- return_url: this.returnUrl,
185
- id_product: "no_id",
186
- quantity_product: 1,
187
- id_ship: "0",
188
- instance_id_ship: "0",
189
- amount: total,
190
- title_ship: "shipping",
191
- description: "transaction",
192
- device_session_id: deviceSessionIdTonder ? deviceSessionIdTonder : null,
193
- token_id: "",
194
- order_id: jsonResponseOrder.id,
195
- business_id: business.pk,
196
- payment_id: jsonResponsePayment.pk,
197
- source: "sdk",
198
- metadata: this.metadata,
199
- browser_info: getBrowserInfo(),
200
- currency: this.currency!,
201
- ...(!!payment_method ? { payment_method } : { card }),
202
- };
203
-
204
- const jsonResponseRouter = await startCheckoutRouter(
205
- this.baseUrl,
206
- this.apiKeyTonder,
207
- routerItems,
208
- );
209
-
210
- if (jsonResponseRouter) {
211
- return jsonResponseRouter;
212
- } else {
213
- return false;
214
- }
215
- } catch (error) {
216
- console.log(error);
217
- throw error;
218
- }
219
- }
220
-
221
-
222
- async _fetchMerchantData() {
223
- try {
224
- if (!this.merchantData){
225
- this.merchantData = await fetchBusiness(this.baseUrl, this.apiKeyTonder, this.abortController.signal);
226
- }
227
- return this.merchantData
228
- }catch(e){
229
- return this.merchantData
230
- }
231
- }
232
-
233
- #handleCustomer(customer: ICustomer) {
234
- if (!customer) return;
235
-
236
- this.firstName = customer?.firstName;
237
- this.lastName = customer?.lastName;
238
- this.country = customer?.country;
239
- this.address = customer?.street;
240
- this.city = customer?.city;
241
- this.state = customer?.state;
242
- this.postCode = customer?.postCode;
243
- this.email = customer?.email;
244
- this.phone = customer?.phone;
245
- this.customer = customer;
246
- }
247
-
248
- #setCartItems(items: IItem[]) {
249
- this.cartItems = items;
250
- }
251
-
252
- #handleMetadata(data: { metadata?: any }) {
253
- this.metadata = data?.metadata;
260
+ }
261
+
262
+ async _getCustomerCards(
263
+ authToken: string,
264
+ businessId: string | number,
265
+ ): Promise<ICustomerCardsResponse> {
266
+ return await fetchCustomerCards(this.baseUrl, authToken, businessId);
267
+ }
268
+
269
+ async _saveCustomerCard(
270
+ authToken: string,
271
+ businessId: string | number,
272
+ skyflowTokens: ISaveCardSkyflowRequest,
273
+ ): Promise<ISaveCardResponse> {
274
+ return await saveCustomerCard(
275
+ this.baseUrl,
276
+ authToken,
277
+ businessId,
278
+ skyflowTokens,
279
+ );
280
+ }
281
+
282
+ async _removeCustomerCard(
283
+ authToken: string,
284
+ businessId: string | number,
285
+ skyflowId: string,
286
+ ): Promise<string> {
287
+ return await removeCustomerCard(
288
+ this.baseUrl,
289
+ authToken,
290
+ skyflowId,
291
+ businessId,
292
+ );
293
+ }
294
+ async _fetchCustomerPaymentMethods(): Promise<IPaymentMethodResponse> {
295
+ return await fetchCustomerPaymentMethods(this.baseUrl, this.apiKeyTonder);
296
+ }
297
+
298
+ #handleCustomer(customer: ICustomer | { email: string }) {
299
+ if (!customer) return;
300
+
301
+ this.customer = customer;
302
+ }
303
+
304
+ #setCartItems(items: IItem[]) {
305
+ this.cartItems = items;
306
+ }
307
+
308
+ #handleMetadata(data: { metadata?: any }) {
309
+ this.metadata = data?.metadata;
310
+ }
311
+
312
+ #handleCurrency(data: { currency?: string }) {
313
+ this.currency = data?.currency;
314
+ }
315
+
316
+ #handleCard(data: { card?: ICardFields | string }) {
317
+ this.card = data?.card;
318
+ }
319
+
320
+ // TODO: Make private after remove deprecated functions of liteCheckout
321
+ async _handle3dsRedirect(
322
+ response: ErrorResponse | StartCheckoutResponse | false | undefined,
323
+ ) {
324
+ const iframe =
325
+ response && "next_action" in response
326
+ ? response?.next_action?.iframe_resources?.iframe
327
+ : null;
328
+
329
+ if (iframe) {
330
+ this.process3ds
331
+ .loadIframe()!
332
+ .then(() => {
333
+ //TODO: Check if this will be necessary on the frontend side
334
+ // after some the tests in production, since the 3DS process
335
+ // doesn't works properly on the sandbox environment
336
+ // setTimeout(() => {
337
+ // process3ds.verifyTransactionStatus();
338
+ // }, 10000);
339
+ this.process3ds.verifyTransactionStatus();
340
+ })
341
+ .catch((error) => {
342
+ console.log("Error loading iframe:", error);
343
+ });
344
+ } else {
345
+ const redirectUrl = this.process3ds.getRedirectUrl();
346
+ if (redirectUrl) {
347
+ this.process3ds.redirectToChallenge();
348
+ } else {
349
+ return response;
350
+ }
254
351
  }
352
+ }
255
353
 
256
- #handleCurrency(data: { currency?: string }) {
257
- this.currency = data?.currency;
354
+ async #resumeCheckout(response: any) {
355
+ // Stop the routing process if the transaction is either hard declined or successful
356
+ if (response?.decline?.error_type === "Hard") {
357
+ return response;
258
358
  }
259
359
 
260
- #handleCard(data: { card?: ICardFields | string }) {
261
- this.card = data?.card;
360
+ if (["Success", "Authorized"].includes(response?.transaction_status)) {
361
+ return response;
262
362
  }
263
363
 
264
- // TODO: Make private after remove deprecated functions of liteCheckout
265
- async _handle3dsRedirect(response: ErrorResponse | StartCheckoutResponse | false | undefined) {
266
- const iframe = response && 'next_action' in response ? response?.next_action?.iframe_resources?.iframe:null
267
-
268
- if (iframe) {
269
- this.process3ds.loadIframe()!.then(() => {
270
- //TODO: Check if this will be necessary on the frontend side
271
- // after some the tests in production, since the 3DS process
272
- // doesn't works properly on the sandbox environment
273
- // setTimeout(() => {
274
- // process3ds.verifyTransactionStatus();
275
- // }, 10000);
276
- this.process3ds.verifyTransactionStatus();
277
- }).catch((error) => {
278
- console.log('Error loading iframe:', error)
279
- })
280
- } else {
281
- const redirectUrl = this.process3ds.getRedirectUrl()
282
- if (redirectUrl) {
283
- this.process3ds.redirectToChallenge()
284
- } else {
285
- return response;
286
- }
287
- }
288
- }
289
-
290
- async #resumeCheckout(response: any) {
291
- // Stop the routing process if the transaction is either hard declined or successful
292
- if (response?.decline?.error_type === "Hard") {
293
- return response
294
- }
295
-
296
- if (["Success", "Authorized"].includes(response?.transaction_status)) {
297
- return response;
298
- }
364
+ if (response) {
365
+ const routerItems = {
366
+ checkout_id: response.checkout?.id,
367
+ };
299
368
 
300
- if (response) {
301
- const routerItems = {
302
- checkout_id: response.checkout?.id,
303
- };
304
-
305
- try{
306
- return await startCheckoutRouter(
307
- this.baseUrl,
308
- this.apiKeyTonder,
309
- routerItems
310
- )
311
- }catch (error){
312
- // throw error
313
- }
314
- return response
315
- }
369
+ try {
370
+ return await startCheckoutRouter(
371
+ this.baseUrl,
372
+ this.apiKeyTonder,
373
+ routerItems,
374
+ );
375
+ } catch (error) {
376
+ // throw error
377
+ }
378
+ return response;
316
379
  }
317
-
318
- }
380
+ }
381
+ }