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