@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.
- package/.idea/prettier.xml +6 -0
- package/.idea/workspace.xml +38 -26
- package/dist/classes/BaseInlineCheckout.d.ts +9 -19
- 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/checkout.d.ts +1 -0
- package/dist/types/commons.d.ts +10 -3
- package/dist/types/customer.d.ts +10 -0
- package/dist/types/transaction.d.ts +101 -0
- package/package.json +4 -2
- package/src/classes/BaseInlineCheckout.ts +324 -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/checkout.ts +1 -0
- package/src/types/commons.ts +98 -94
- package/src/types/customer.ts +10 -0
- package/src/types/liteInlineCheckout.d.ts +217 -184
- 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,
|
|
10
|
+
formatPublicErrorResponse,
|
|
11
|
+
getCardType,
|
|
31
12
|
} from "../helpers/utils";
|
|
32
13
|
import { getCustomerAPMs } from "../data/api";
|
|
33
|
-
import {BaseInlineCheckout} from "./BaseInlineCheckout";
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
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
|
|
57
|
+
export interface LiteCheckoutConstructor extends IInlineCheckoutBaseOptions {}
|
|
53
58
|
|
|
54
|
-
export class LiteCheckout extends BaseInlineCheckout
|
|
55
|
-
activeAPMs: APM[] = []
|
|
56
|
-
#customerData?: Record<string, any>;
|
|
59
|
+
export class LiteCheckout extends BaseInlineCheckout {
|
|
60
|
+
activeAPMs: APM[] = [];
|
|
57
61
|
|
|
58
|
-
constructor({
|
|
59
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
this.baseUrl,
|
|
113
|
+
auth_token,
|
|
114
|
+
business?.pk,
|
|
115
|
+
skyflowTokens,
|
|
117
116
|
);
|
|
118
117
|
} catch (error) {
|
|
119
118
|
throw formatPublicErrorResponse(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
this.baseUrl,
|
|
135
|
+
auth_token,
|
|
136
|
+
skyflowId,
|
|
137
|
+
business?.pk,
|
|
140
138
|
);
|
|
141
139
|
} catch (error) {
|
|
142
140
|
throw formatPublicErrorResponse(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
response && "results" in response && response["results"].length > 0
|
|
155
|
+
? response["results"]
|
|
156
|
+
: [];
|
|
159
157
|
|
|
160
158
|
return apms_results
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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(
|
|
183
|
+
return await fetchBusiness(
|
|
184
|
+
this.baseUrl,
|
|
185
|
+
this.apiKeyTonder,
|
|
186
|
+
this.abortController.signal,
|
|
187
|
+
);
|
|
186
188
|
} catch (e) {
|
|
187
|
-
throw formatPublicErrorResponse(
|
|
188
|
-
|
|
189
|
-
|
|
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
|
|
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({
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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(
|
|
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)
|
|
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(
|
|
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(
|
|
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(
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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(
|
|
343
|
-
|
|
379
|
+
async startCheckoutRouterFull(
|
|
380
|
+
routerFullData: StartCheckoutFullRequest,
|
|
381
|
+
): Promise<StartCheckoutResponse | ErrorResponse | undefined> {
|
|
344
382
|
try {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
|
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(
|
|
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
|
|
463
|
+
device_session_id: deviceSessionIdTonder
|
|
464
|
+
? deviceSessionIdTonder
|
|
465
|
+
: null,
|
|
421
466
|
token_id: "",
|
|
422
|
-
order_id:
|
|
467
|
+
order_id: "id" in orderResult && orderResult.id,
|
|
423
468
|
business_id: business.pk,
|
|
424
|
-
payment_id:
|
|
425
|
-
source:
|
|
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
|
-
...(
|
|
430
|
-
? {payment_method}
|
|
431
|
-
: {card: skyflowTokens}
|
|
432
|
-
|
|
433
|
-
|
|
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(
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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(
|
|
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(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
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
|
-
|
|
484
|
-
});
|
|
532
|
+
);
|
|
485
533
|
|
|
486
|
-
if (response.ok)
|
|
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(
|
|
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(
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
-
|
|
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(
|
|
525
|
-
|
|
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
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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
|
}
|