@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
@@ -1,39 +1,52 @@
1
- import {fetchBusiness} from "../data/businessApi";
1
+ import { fetchBusiness } from "../data/businessApi";
2
2
 
3
3
  declare const MP_DEVICE_SESSION_ID: string | undefined;
4
-
5
- import {APM, Business, IInlineCheckoutBaseOptions, TonderAPM} from "../types/commons";
6
- import { CreateOrderRequest, CreatePaymentRequest, RegisterCustomerCardRequest, StartCheckoutRequest, StartCheckoutFullRequest, StartCheckoutIdRequest } from "../types/requests";
7
- import {
8
- CustomerRegisterResponse,
9
- CreateOrderResponse,
10
- CreatePaymentResponse,
11
- StartCheckoutResponse,
12
- IErrorResponse,
13
- RegisterCustomerCardResponse,
14
- GetBusinessResponse
15
- } from "../types/responses";
16
4
  import { ErrorResponse } from "./errorResponse";
17
5
  import {
18
6
  buildErrorResponse,
19
7
  buildErrorResponseFromCatch,
20
8
  getBrowserInfo,
21
9
  getBusinessId,
22
- formatPublicErrorResponse, getCardType
10
+ formatPublicErrorResponse,
11
+ getCardType,
23
12
  } from "../helpers/utils";
24
13
  import { getCustomerAPMs } from "../data/api";
25
- import {BaseInlineCheckout} from "./BaseInlineCheckout";
26
- import {fetchCustomerCards, removeCustomerCard, saveCustomerCard} from "../data/cardApi";
27
- import {MESSAGES} from "../shared/constants/messages";
28
- import {ICustomerCardsResponse, ISaveCardRequest, ISaveCardResponse} from "../types/card";
29
- import {getSkyflowTokens} from "../helpers/skyflow";
30
- import {fetchCustomerAPMs} from "../data/paymentMethodApi";
31
- import {IPaymentMethod} from "../types/paymentMethod";
32
- import {ICardFields} from "../types/checkout";
33
- import {ILiteInlineCheckout} from "../types/liteInlineCheckout";
34
- import {startCheckoutRouter} from "../data/checkoutApi";
35
- import {getOpenpayDeviceSessionID} from "../data/openPayApi";
36
- import {getPaymentMethodDetails} from "../shared/catalog/paymentMethodsCatalog";
14
+ import { BaseInlineCheckout } from "./BaseInlineCheckout";
15
+ import {
16
+ fetchCustomerCards,
17
+ removeCustomerCard,
18
+ saveCustomerCard,
19
+ } from "../data/cardApi";
20
+ import { MESSAGES } from "../shared/constants/messages";
21
+ import { getSkyflowTokens } from "../helpers/skyflow";
22
+ import { fetchCustomerAPMs } from "../data/paymentMethodApi";
23
+ import { startCheckoutRouter } from "../data/checkoutApi";
24
+ import { getOpenpayDeviceSessionID } from "../data/openPayApi";
25
+ import { getPaymentMethodDetails } from "../shared/catalog/paymentMethodsCatalog";
26
+ import {
27
+ APM,
28
+ IInlineCheckoutBaseOptions,
29
+ TonderAPM,
30
+ RegisterCustomerCardResponse,
31
+ ISaveCardRequest,
32
+ ICustomerCardsResponse,
33
+ ISaveCardResponse,
34
+ IPaymentMethod,
35
+ GetBusinessResponse,
36
+ TokensRequest,
37
+ ICardFields,
38
+ CustomerRegisterResponse,
39
+ StartCheckoutFullRequest,
40
+ CreateOrderRequest,
41
+ CreatePaymentRequest,
42
+ StartCheckoutRequest,
43
+ IErrorResponse,
44
+ StartCheckoutResponse,
45
+ StartCheckoutIdRequest,
46
+ CreatePaymentResponse,
47
+ CreateOrderResponse,
48
+ RegisterCustomerCardRequest,
49
+ } from "../types";
37
50
 
38
51
  declare global {
39
52
  interface Window {
@@ -41,19 +54,13 @@ declare global {
41
54
  }
42
55
  }
43
56
 
44
- export interface LiteCheckoutConstructor extends IInlineCheckoutBaseOptions {}
57
+ export interface LiteCheckoutConstructor extends IInlineCheckoutBaseOptions {}
45
58
 
46
- export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheckout {
47
- activeAPMs: APM[] = []
48
- #customerData?: Record<string, any>;
59
+ export class LiteCheckout extends BaseInlineCheckout {
60
+ activeAPMs: APM[] = [];
49
61
 
50
- constructor({
51
- apiKey,
52
- mode,
53
- returnUrl,
54
- callBack,
55
- }: LiteCheckoutConstructor) {
56
- super({mode, apiKey, returnUrl, callBack});
62
+ constructor({ apiKey, mode, returnUrl, callBack }: LiteCheckoutConstructor) {
63
+ super({ mode, apiKey, returnUrl, callBack });
57
64
  }
58
65
 
59
66
  async injectCheckout() {
@@ -62,12 +69,12 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
62
69
 
63
70
  async getCustomerCards(): Promise<ICustomerCardsResponse> {
64
71
  try {
65
- await this._fetchMerchantData()
72
+ await this._fetchMerchantData();
66
73
  const { auth_token } = await this._getCustomer();
67
74
  const response = await fetchCustomerCards(
68
- this.baseUrl,
69
- auth_token,
70
- this.merchantData!.business.pk,
75
+ this.baseUrl,
76
+ auth_token,
77
+ this.merchantData!.business.pk,
71
78
  );
72
79
 
73
80
  return {
@@ -79,17 +86,17 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
79
86
  };
80
87
  } catch (error) {
81
88
  throw formatPublicErrorResponse(
82
- {
83
- message: MESSAGES.getCardsError,
84
- },
85
- error,
89
+ {
90
+ message: MESSAGES.getCardsError,
91
+ },
92
+ error,
86
93
  );
87
94
  }
88
95
  }
89
96
 
90
97
  async saveCustomerCard(card: ISaveCardRequest): Promise<ISaveCardResponse> {
91
98
  try {
92
- await this._fetchMerchantData()
99
+ await this._fetchMerchantData();
93
100
  const { auth_token } = await this._getCustomer();
94
101
  const { vault_id, vault_url, business } = this.merchantData!;
95
102
 
@@ -102,96 +109,135 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
102
109
  });
103
110
 
104
111
  return await saveCustomerCard(
105
- this.baseUrl,
106
- auth_token,
107
- business?.pk,
108
- skyflowTokens,
112
+ this.baseUrl,
113
+ auth_token,
114
+ business?.pk,
115
+ skyflowTokens,
109
116
  );
110
117
  } catch (error) {
111
118
  throw formatPublicErrorResponse(
112
- {
113
- message: MESSAGES.saveCardError,
114
- },
115
- error,
119
+ {
120
+ message: MESSAGES.saveCardError,
121
+ },
122
+ error,
116
123
  );
117
124
  }
118
125
  }
119
126
 
120
-
121
127
  async removeCustomerCard(skyflowId: string): Promise<string> {
122
128
  try {
123
- await this._fetchMerchantData()
129
+ await this._fetchMerchantData();
124
130
  const { auth_token } = await this._getCustomer();
125
131
  const { business } = this.merchantData!;
126
132
 
127
133
  return await removeCustomerCard(
128
- this.baseUrl,
129
- auth_token,
130
- skyflowId,
131
- business?.pk,
134
+ this.baseUrl,
135
+ auth_token,
136
+ skyflowId,
137
+ business?.pk,
132
138
  );
133
139
  } catch (error) {
134
140
  throw formatPublicErrorResponse(
135
- {
136
- message: MESSAGES.removeCardError,
137
- },
138
- error,
141
+ {
142
+ message: MESSAGES.removeCardError,
143
+ },
144
+ error,
139
145
  );
140
146
  }
141
147
  }
142
148
 
143
-
144
149
  async getCustomerPaymentMethods(): Promise<IPaymentMethod[]> {
145
150
  try {
146
151
  const response = await fetchCustomerAPMs(this.baseUrl, this.apiKeyTonder);
147
152
 
148
153
  const apms_results =
149
- response && "results" in response && response["results"].length > 0
150
- ? response["results"]
151
- : [];
154
+ response && "results" in response && response["results"].length > 0
155
+ ? response["results"]
156
+ : [];
152
157
 
153
158
  return apms_results
154
- .filter((apmItem) => apmItem.category.toLowerCase() !== "cards")
155
- .map((apmItem) => {
156
- const apm = {
157
- id: apmItem.pk,
158
- payment_method: apmItem.payment_method,
159
- priority: apmItem.priority,
160
- category: apmItem.category,
161
- ...getPaymentMethodDetails(apmItem.payment_method),
162
- };
163
- return apm;
164
- })
165
- .sort((a, b) => a.priority - b.priority);
159
+ .filter((apmItem) => apmItem.category.toLowerCase() !== "cards")
160
+ .map((apmItem) => {
161
+ const apm = {
162
+ id: apmItem.pk,
163
+ payment_method: apmItem.payment_method,
164
+ priority: apmItem.priority,
165
+ category: apmItem.category,
166
+ ...getPaymentMethodDetails(apmItem.payment_method),
167
+ };
168
+ return apm;
169
+ })
170
+ .sort((a, b) => a.priority - b.priority);
166
171
  } catch (error) {
167
172
  throw formatPublicErrorResponse(
168
- {
169
- message: MESSAGES.getPaymentMethodsError,
170
- },
171
- error,
173
+ {
174
+ message: MESSAGES.getPaymentMethodsError,
175
+ },
176
+ error,
172
177
  );
173
178
  }
174
179
  }
175
180
 
176
181
  async getBusiness(): Promise<GetBusinessResponse> {
177
182
  try {
178
- return await fetchBusiness(this.baseUrl, this.apiKeyTonder, this.abortController.signal)
183
+ return await fetchBusiness(
184
+ this.baseUrl,
185
+ this.apiKeyTonder,
186
+ this.abortController.signal,
187
+ );
179
188
  } catch (e) {
180
- throw formatPublicErrorResponse({
181
- message: MESSAGES.getBusinessError
182
- },e);
189
+ throw formatPublicErrorResponse(
190
+ {
191
+ message: MESSAGES.getBusinessError,
192
+ },
193
+ e,
194
+ );
183
195
  }
184
196
  }
185
197
 
198
+ // TODO: DEPRECATED
199
+ async getOpenpayDeviceSessionID(
200
+ merchant_id: string,
201
+ public_key: string,
202
+ is_sandbox: boolean
203
+ ): Promise<string | ErrorResponse> {
204
+ try {
205
+ return await getOpenpayDeviceSessionID(merchant_id, public_key, is_sandbox);
206
+ } catch (e) {
207
+ throw buildErrorResponseFromCatch(e);
208
+ }
209
+ }
210
+
211
+ // TODO: DEPRECATED
212
+ async getSkyflowTokens({
213
+ vault_id,
214
+ vault_url,
215
+ data,
216
+ }: TokensRequest): Promise<any | ErrorResponse> {
217
+ return await getSkyflowTokens({
218
+ vault_id: vault_id,
219
+ vault_url: vault_url,
220
+ data,
221
+ baseUrl: this.baseUrl,
222
+ apiKey: this.apiKeyTonder,
223
+ });
224
+ }
225
+
186
226
  _setCartTotal(total: string) {
187
227
  this.cartTotal = total;
188
228
  }
189
229
 
190
- async _checkout({ card, payment_method, isSandbox }: {card?: ICardFields | string; payment_method?: string; isSandbox?: boolean;}) {
191
- await this._fetchMerchantData()
192
- const customer = await this._getCustomer(
193
- this.abortController.signal,
194
- );
230
+ async _checkout({
231
+ card,
232
+ payment_method,
233
+ isSandbox,
234
+ }: {
235
+ card?: ICardFields | string;
236
+ payment_method?: string;
237
+ isSandbox?: boolean;
238
+ }) {
239
+ await this._fetchMerchantData();
240
+ const customer = await this._getCustomer(this.abortController.signal);
195
241
  const { vault_id, vault_url } = this.merchantData!;
196
242
  let skyflowTokens;
197
243
  if (!payment_method || payment_method !== "" || payment_method === null) {
@@ -203,7 +249,7 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
203
249
  skyflowTokens = await getSkyflowTokens({
204
250
  vault_id: vault_id,
205
251
  vault_url: vault_url,
206
- data: {...card, card_number: card!.card_number.replace(/\s+/g, '')},
252
+ data: { ...card, card_number: card!.card_number.replace(/\s+/g, "") },
207
253
  baseUrl: this.baseUrl,
208
254
  apiKey: this.apiKeyTonder,
209
255
  });
@@ -214,18 +260,19 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
214
260
  card: skyflowTokens,
215
261
  payment_method,
216
262
  customer,
217
- isSandbox
263
+ isSandbox,
218
264
  });
219
265
  }
220
266
 
221
-
222
267
  // TODO: DEPRECATED
223
268
  /**
224
269
  * @deprecated This method is deprecated and will be removed in a future release.
225
270
  * It is no longer necessary to use this method as customer registration is now automatically handled
226
271
  * during the payment process or when using card management methods.
227
272
  */
228
- async customerRegister(email: string): Promise<CustomerRegisterResponse | ErrorResponse> {
273
+ async customerRegister(
274
+ email: string,
275
+ ): Promise<CustomerRegisterResponse | ErrorResponse> {
229
276
  try {
230
277
  const url = `${this.baseUrl}/api/v1/customer/`;
231
278
  const data = { email: email };
@@ -239,21 +286,23 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
239
286
  body: JSON.stringify(data),
240
287
  });
241
288
 
242
- if (response.ok) return await response.json() as CustomerRegisterResponse;
289
+ if (response.ok)
290
+ return (await response.json()) as CustomerRegisterResponse;
243
291
  throw await buildErrorResponse(response);
244
292
  } catch (e) {
245
293
  throw buildErrorResponseFromCatch(e);
246
294
  }
247
295
  }
248
296
 
249
-
250
297
  // TODO: DEPRECATED
251
298
  /**
252
299
  * @deprecated This method is deprecated and will be removed in a future release.
253
300
  * It is no longer necessary to use this method as order creation is now automatically
254
301
  * handled when making a payment through the `payment` function.
255
302
  */
256
- async createOrder(orderItems: CreateOrderRequest): Promise<CreateOrderResponse | ErrorResponse> {
303
+ async createOrder(
304
+ orderItems: CreateOrderRequest,
305
+ ): Promise<CreateOrderResponse | ErrorResponse> {
257
306
  try {
258
307
  const url = `${this.baseUrl}/api/v1/orders/`;
259
308
  const data = orderItems;
@@ -265,7 +314,7 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
265
314
  },
266
315
  body: JSON.stringify(data),
267
316
  });
268
- if (response.ok) return await response.json() as CreateOrderResponse;
317
+ if (response.ok) return (await response.json()) as CreateOrderResponse;
269
318
  throw await buildErrorResponse(response);
270
319
  } catch (e) {
271
320
  throw buildErrorResponseFromCatch(e);
@@ -278,7 +327,9 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
278
327
  * It is no longer necessary to use this method as payment creation is now automatically
279
328
  * handled when making a payment through the `payment` function.
280
329
  */
281
- async createPayment(paymentItems: CreatePaymentRequest): Promise<CreatePaymentResponse | ErrorResponse> {
330
+ async createPayment(
331
+ paymentItems: CreatePaymentRequest,
332
+ ): Promise<CreatePaymentResponse | ErrorResponse> {
282
333
  try {
283
334
  const url = `${this.baseUrl}/api/v1/business/${paymentItems.business_pk}/payments/`;
284
335
  const data = paymentItems;
@@ -290,7 +341,7 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
290
341
  },
291
342
  body: JSON.stringify(data),
292
343
  });
293
- if (response.ok) return await response.json() as CreatePaymentResponse;
344
+ if (response.ok) return (await response.json()) as CreatePaymentResponse;
294
345
  throw await buildErrorResponse(response);
295
346
  } catch (e) {
296
347
  throw buildErrorResponseFromCatch(e);
@@ -302,17 +353,22 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
302
353
  * @deprecated This method is deprecated and will be removed in a future release.
303
354
  * Use the {@link payment} method
304
355
  */
305
- async startCheckoutRouter(routerData: StartCheckoutRequest | StartCheckoutIdRequest): Promise<StartCheckoutResponse | ErrorResponse | undefined> {
306
- const checkoutResult = await startCheckoutRouter(this.baseUrl, this.apiKeyTonder, routerData);
307
- const payload = await this.init3DSRedirect(checkoutResult)
308
- if(payload)
309
- return checkoutResult;
356
+ async startCheckoutRouter(
357
+ routerData: StartCheckoutRequest | StartCheckoutIdRequest,
358
+ ): Promise<StartCheckoutResponse | ErrorResponse | undefined> {
359
+ const checkoutResult = await startCheckoutRouter(
360
+ this.baseUrl,
361
+ this.apiKeyTonder,
362
+ routerData,
363
+ );
364
+ const payload = await this.init3DSRedirect(checkoutResult);
365
+ if (payload) return checkoutResult;
310
366
  }
311
367
 
312
368
  // TODO: DEPRECATED
313
- async init3DSRedirect(checkoutResult: ErrorResponse | StartCheckoutResponse){
314
- this.process3ds.setPayload(checkoutResult)
315
- return await this._handle3dsRedirect(checkoutResult)
369
+ async init3DSRedirect(checkoutResult: ErrorResponse | StartCheckoutResponse) {
370
+ this.process3ds.setPayload(checkoutResult);
371
+ return await this._handle3dsRedirect(checkoutResult);
316
372
  }
317
373
 
318
374
  // TODO: DEPRECATED
@@ -320,28 +376,33 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
320
376
  * @deprecated This method is deprecated and will be removed in a future release.
321
377
  * Use the {@link payment} method
322
378
  */
323
- async startCheckoutRouterFull(routerFullData: StartCheckoutFullRequest): Promise<StartCheckoutResponse | ErrorResponse | undefined> {
324
-
379
+ async startCheckoutRouterFull(
380
+ routerFullData: StartCheckoutFullRequest,
381
+ ): Promise<StartCheckoutResponse | ErrorResponse | undefined> {
325
382
  try {
326
-
327
- const {
328
- order,
329
- total,
330
- customer,
331
- skyflowTokens,
332
- return_url,
333
- isSandbox,
334
- metadata,
383
+ const {
384
+ order,
385
+ total,
386
+ customer,
387
+ skyflowTokens,
388
+ return_url,
389
+ isSandbox,
390
+ metadata,
335
391
  currency,
336
- payment_method
392
+ payment_method,
337
393
  } = routerFullData;
338
394
 
339
395
  const merchantResult = await this._fetchMerchantData();
340
396
 
341
- const customerResult : CustomerRegisterResponse | ErrorResponse = await this.customerRegister(customer.email);
342
-
343
- if(customerResult && "auth_token" in customerResult && merchantResult && "reference" in merchantResult) {
397
+ const customerResult: CustomerRegisterResponse | ErrorResponse =
398
+ await this.customerRegister(customer.email);
344
399
 
400
+ if (
401
+ customerResult &&
402
+ "auth_token" in customerResult &&
403
+ merchantResult &&
404
+ "reference" in merchantResult
405
+ ) {
345
406
  const orderData: CreateOrderRequest = {
346
407
  business: this.apiKeyTonder,
347
408
  client: customerResult.auth_token,
@@ -359,29 +420,30 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
359
420
 
360
421
  const dateString = now.toISOString();
361
422
 
362
- if("id" in orderResult && "id" in customerResult && "business" in merchantResult) {
363
-
423
+ if (
424
+ "id" in orderResult &&
425
+ "id" in customerResult &&
426
+ "business" in merchantResult
427
+ ) {
364
428
  const paymentItems: CreatePaymentRequest = {
365
429
  business_pk: merchantResult.business.pk,
366
430
  amount: total,
367
431
  date: dateString,
368
432
  order_id: orderResult.id,
369
- client_id: customerResult.id
433
+ client_id: customerResult.id,
370
434
  };
371
435
 
372
- const paymentResult = await this.createPayment(
373
- paymentItems
374
- );
436
+ const paymentResult = await this.createPayment(paymentItems);
375
437
 
376
438
  let deviceSessionIdTonder: any;
377
439
 
378
- const { openpay_keys, business } = merchantResult
440
+ const { openpay_keys, business } = merchantResult;
379
441
 
380
442
  if (openpay_keys.merchant_id && openpay_keys.public_key) {
381
443
  deviceSessionIdTonder = await getOpenpayDeviceSessionID(
382
444
  openpay_keys.merchant_id,
383
445
  openpay_keys.public_key,
384
- isSandbox
446
+ isSandbox,
385
447
  );
386
448
  }
387
449
 
@@ -398,51 +460,50 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
398
460
  amount: total,
399
461
  title_ship: "shipping",
400
462
  description: "transaction",
401
- device_session_id: deviceSessionIdTonder ? deviceSessionIdTonder : null,
463
+ device_session_id: deviceSessionIdTonder
464
+ ? deviceSessionIdTonder
465
+ : null,
402
466
  token_id: "",
403
- order_id: ("id" in orderResult) && orderResult.id,
467
+ order_id: "id" in orderResult && orderResult.id,
404
468
  business_id: business.pk,
405
- payment_id: ("pk" in paymentResult) && paymentResult.pk,
406
- source: 'sdk',
469
+ payment_id: "pk" in paymentResult && paymentResult.pk,
470
+ source: "sdk",
407
471
  metadata: metadata,
408
472
  browser_info: getBrowserInfo(),
409
473
  currency: currency,
410
- ...( !!payment_method
411
- ? {payment_method}
412
- : {card: skyflowTokens}
413
- ),
414
- ...(typeof MP_DEVICE_SESSION_ID !== "undefined" ? {mp_device_session_id: MP_DEVICE_SESSION_ID}:{})
474
+ ...(!!payment_method
475
+ ? { payment_method }
476
+ : { card: skyflowTokens }),
477
+ ...(typeof MP_DEVICE_SESSION_ID !== "undefined"
478
+ ? { mp_device_session_id: MP_DEVICE_SESSION_ID }
479
+ : {}),
415
480
  };
416
481
 
417
- const checkoutResult = await startCheckoutRouter(this.baseUrl, this.apiKeyTonder, routerItems);
418
- const payload = await this.init3DSRedirect(checkoutResult)
419
- if(payload)
420
- return checkoutResult;
482
+ const checkoutResult = await startCheckoutRouter(
483
+ this.baseUrl,
484
+ this.apiKeyTonder,
485
+ routerItems,
486
+ );
487
+ const payload = await this.init3DSRedirect(checkoutResult);
488
+ if (payload) return checkoutResult;
421
489
  } else {
422
-
423
490
  throw new ErrorResponse({
424
491
  code: "500",
425
492
  body: orderResult as any,
426
493
  name: "Keys error",
427
- message: "Order response errors"
428
- } as IErrorResponse)
429
-
494
+ message: "Order response errors",
495
+ } as IErrorResponse);
430
496
  }
431
-
432
497
  } else {
433
-
434
498
  throw new ErrorResponse({
435
499
  code: "500",
436
500
  body: merchantResult as any,
437
501
  name: "Keys error",
438
- message: "Merchant or customer reposne errors"
439
- } as IErrorResponse)
440
-
502
+ message: "Merchant or customer reposne errors",
503
+ } as IErrorResponse);
441
504
  }
442
505
  } catch (e) {
443
-
444
506
  throw buildErrorResponseFromCatch(e);
445
-
446
507
  }
447
508
  }
448
509
 
@@ -451,20 +512,27 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
451
512
  * @deprecated This method is deprecated and will be removed in a future release.
452
513
  * Use the {@link saveCustomerCard} method
453
514
  */
454
- async registerCustomerCard(customerToken: string, data: RegisterCustomerCardRequest): Promise<RegisterCustomerCardResponse | ErrorResponse> {
515
+ async registerCustomerCard(
516
+ customerToken: string,
517
+ data: RegisterCustomerCardRequest,
518
+ ): Promise<RegisterCustomerCardResponse | ErrorResponse> {
455
519
  try {
456
- await this._fetchMerchantData()
457
-
458
- const response = await fetch(`${this.baseUrl}/api/v1/business/${getBusinessId(this.merchantData)}/cards/`, {
459
- method: 'POST',
460
- headers: {
461
- 'Authorization': `Token ${customerToken}`,
462
- 'Content-Type': 'application/json'
520
+ await this._fetchMerchantData();
521
+
522
+ const response = await fetch(
523
+ `${this.baseUrl}/api/v1/business/${getBusinessId(this.merchantData)}/cards/`,
524
+ {
525
+ method: "POST",
526
+ headers: {
527
+ Authorization: `Token ${customerToken}`,
528
+ "Content-Type": "application/json",
529
+ },
530
+ body: JSON.stringify({ ...data }),
463
531
  },
464
- body: JSON.stringify({...data})
465
- });
532
+ );
466
533
 
467
- if (response.ok) return await response.json() as RegisterCustomerCardResponse;
534
+ if (response.ok)
535
+ return (await response.json()) as RegisterCustomerCardResponse;
468
536
  throw await buildErrorResponse(response);
469
537
  } catch (error) {
470
538
  throw buildErrorResponseFromCatch(error);
@@ -476,17 +544,23 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
476
544
  * @deprecated This method is deprecated and will be removed in a future release.
477
545
  * Use the {@link removeCustomerCard} method
478
546
  */
479
- async deleteCustomerCard(customerToken: string, skyflowId: string = ""): Promise<Boolean | ErrorResponse> {
547
+ async deleteCustomerCard(
548
+ customerToken: string,
549
+ skyflowId: string = "",
550
+ ): Promise<Boolean | ErrorResponse> {
480
551
  try {
481
- await this._fetchMerchantData()
482
- const response = await fetch(`${this.baseUrl}/api/v1/business/${getBusinessId(this.merchantData)}/cards/${skyflowId}`, {
483
- method: 'DELETE',
484
- headers: {
485
- 'Authorization': `Token ${customerToken}`,
486
- 'Content-Type': 'application/json'
552
+ await this._fetchMerchantData();
553
+ const response = await fetch(
554
+ `${this.baseUrl}/api/v1/business/${getBusinessId(this.merchantData)}/cards/${skyflowId}`,
555
+ {
556
+ method: "DELETE",
557
+ headers: {
558
+ Authorization: `Token ${customerToken}`,
559
+ "Content-Type": "application/json",
560
+ },
561
+ signal: this.abortController.signal,
487
562
  },
488
- signal: this.abortController.signal,
489
- });
563
+ );
490
564
 
491
565
  if (response.ok) return true;
492
566
  throw await buildErrorResponse(response);
@@ -502,27 +576,36 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
502
576
  */
503
577
  async getActiveAPMs(): Promise<APM[]> {
504
578
  try {
505
- const apms_response = await getCustomerAPMs(this.baseUrl, this.apiKeyTonder);
506
- const apms_results = apms_response && apms_response['results'] && apms_response['results'].length > 0 ? apms_response['results'] : []
579
+ const apms_response = await getCustomerAPMs(
580
+ this.baseUrl,
581
+ this.apiKeyTonder,
582
+ );
583
+ const apms_results =
584
+ apms_response &&
585
+ apms_response["results"] &&
586
+ apms_response["results"].length > 0
587
+ ? apms_response["results"]
588
+ : [];
507
589
  this.activeAPMs = apms_results
508
- .filter((apmItem: TonderAPM) =>
509
- apmItem.category.toLowerCase() !== 'cards')
510
- .map((apmItem: TonderAPM) => {
511
- const apm: APM = {
512
- id: apmItem.pk,
513
- payment_method: apmItem.payment_method,
514
- priority: apmItem.priority,
515
- category: apmItem.category,
516
- ...getPaymentMethodDetails(apmItem.payment_method,)
517
- }
518
- return apm;
519
- }).sort((a: APM, b: APM) => a.priority - b.priority);
520
-
521
- return this.activeAPMs
590
+ .filter(
591
+ (apmItem: TonderAPM) => apmItem.category.toLowerCase() !== "cards",
592
+ )
593
+ .map((apmItem: TonderAPM) => {
594
+ const apm: APM = {
595
+ id: apmItem.pk,
596
+ payment_method: apmItem.payment_method,
597
+ priority: apmItem.priority,
598
+ category: apmItem.category,
599
+ ...getPaymentMethodDetails(apmItem.payment_method),
600
+ };
601
+ return apm;
602
+ })
603
+ .sort((a: APM, b: APM) => a.priority - b.priority);
604
+
605
+ return this.activeAPMs;
522
606
  } catch (e) {
523
607
  console.error("Error getting APMS", e);
524
608
  return [];
525
609
  }
526
610
  }
527
-
528
611
  }