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

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