@tonder.io/ionic-lite-sdk 0.0.35-beta.1 → 0.0.35-beta.12

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