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