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