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