@tonder.io/ionic-lite-sdk 0.0.35-beta.0 → 0.0.35-beta.10

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