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