@tonder.io/ionic-lite-sdk 0.0.34-beta.3 → 0.0.35-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/aws.xml +17 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +72 -17
- package/dist/classes/BaseInlineCheckout.d.ts +48 -0
- package/dist/classes/liteCheckout.d.ts +61 -29
- package/dist/data/businessApi.d.ts +2 -0
- package/dist/data/cardApi.d.ts +4 -0
- package/dist/data/checkoutApi.d.ts +5 -0
- package/dist/data/customerApi.d.ts +2 -0
- package/dist/data/openPayApi.d.ts +1 -0
- package/dist/data/paymentMethodApi.d.ts +5 -0
- package/dist/data/skyflowApi.d.ts +1 -0
- package/dist/helpers/skyflow.d.ts +3 -0
- package/dist/helpers/utils.d.ts +8 -4
- package/dist/helpers/validations.d.ts +6 -0
- package/dist/index.js +1 -1
- package/dist/shared/catalog/paymentMethodsCatalog.d.ts +1 -0
- package/dist/shared/constants/messages.d.ts +11 -0
- package/dist/shared/constants/paymentMethodAPM.d.ts +62 -0
- package/dist/shared/constants/tonderUrl.d.ts +7 -0
- package/dist/types/card.d.ts +29 -0
- package/dist/types/checkout.d.ts +103 -0
- package/dist/types/commons.d.ts +32 -0
- package/dist/types/customer.d.ts +12 -0
- package/dist/types/paymentMethod.d.ts +22 -0
- package/dist/types/requests.d.ts +12 -3
- package/package.json +1 -1
- package/src/classes/BaseInlineCheckout.ts +318 -0
- package/src/classes/liteCheckout.ts +273 -280
- package/src/data/businessApi.ts +14 -0
- package/src/data/cardApi.ts +82 -0
- package/src/data/checkoutApi.ts +71 -0
- package/src/data/customerApi.ts +31 -0
- package/src/data/openPayApi.ts +7 -0
- package/src/data/paymentMethodApi.ts +34 -0
- package/src/data/skyflowApi.ts +16 -0
- package/src/helpers/skyflow.ts +85 -0
- package/src/helpers/utils.ts +31 -243
- package/src/helpers/validations.ts +55 -0
- package/src/shared/catalog/paymentMethodsCatalog.ts +248 -0
- package/src/shared/constants/messages.ts +11 -0
- package/src/shared/constants/paymentMethodAPM.ts +63 -0
- package/src/shared/constants/tonderUrl.ts +8 -0
- package/src/types/card.ts +34 -0
- package/src/types/checkout.ts +118 -0
- package/src/types/commons.ts +37 -0
- package/src/types/customer.ts +12 -0
- package/src/types/index.d.ts +10 -0
- package/src/types/liteInlineCheckout.d.ts +191 -0
- package/src/types/paymentMethod.ts +24 -0
- package/src/types/requests.ts +12 -3
- package/src/types/validations.d.ts +11 -0
- package/tests/classes/liteCheckout.test.ts +3 -3
- package/tests/methods/getBusiness.test.ts +2 -2
- package/tests/methods/getCustomerCards.test.ts +4 -8
- package/tests/utils/defaultMock.ts +3 -2
- package/tests/utils/mockClasses.ts +7 -4
- package/tests/methods/getOpenpayDeviceSessionID.test.ts +0 -95
- package/tests/methods/getSkyflowToken.test.ts +0 -155
- package/tests/methods/getVaultToken.test.ts +0 -107
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {IConfigureCheckout, IInlineCheckoutBaseOptions} from "./common";
|
|
2
|
+
import {ICustomerCardsResponse, ISaveCardRequest, ISaveCardResponse} from "./card";
|
|
3
|
+
import {IPaymentMethod} from "./paymentMethod";
|
|
4
|
+
import {IProcessPaymentRequest, IStartCheckoutResponse} from "./checkout";
|
|
5
|
+
import {ITransaction} from "./transaction";
|
|
6
|
+
import {APM} from "./commons";
|
|
7
|
+
import {ErrorResponse} from "../classes/errorResponse";
|
|
8
|
+
import {
|
|
9
|
+
CreateOrderRequest,
|
|
10
|
+
CreatePaymentRequest,
|
|
11
|
+
RegisterCustomerCardRequest,
|
|
12
|
+
StartCheckoutFullRequest,
|
|
13
|
+
StartCheckoutIdRequest,
|
|
14
|
+
StartCheckoutRequest, TokensRequest
|
|
15
|
+
} from "./requests";
|
|
16
|
+
import {
|
|
17
|
+
CreateOrderResponse,
|
|
18
|
+
CreatePaymentResponse, CustomerRegisterResponse, GetBusinessResponse,
|
|
19
|
+
RegisterCustomerCardResponse,
|
|
20
|
+
StartCheckoutResponse
|
|
21
|
+
} from "./responses";
|
|
22
|
+
|
|
23
|
+
export class ILiteInlineCheckout {
|
|
24
|
+
constructor(options: IInlineLiteCheckoutOptions);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The configureCheckout function allows you to set initial information, such as the customer's email, which is used to retrieve a list of saved cards.
|
|
28
|
+
* @param {import("../types").IConfigureCheckout} data - Configuration data including customer information and potentially other settings.
|
|
29
|
+
* @returns {Promise<void>}.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
configureCheckout(data: IConfigureCheckout): void;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Initializes and prepares the checkout for use.
|
|
36
|
+
* This method set up the initial environment.
|
|
37
|
+
* @returns {Promise<void>} A promise that resolves when the checkout has been initialized.
|
|
38
|
+
* @throws {Error} If there's any problem during the checkout initialization.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
injectCheckout(): Promise<void>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Processes a payment.
|
|
45
|
+
* @param {import("../types").IProcessPaymentRequest} data - Payment data including customer, cart, and other relevant information.
|
|
46
|
+
* @returns {Promise<import("../types").IStartCheckoutResponse>} A promise that resolves with the payment response or 3DS redirect or is rejected with an error.
|
|
47
|
+
*
|
|
48
|
+
* @throws {Error} Throws an error if the checkout process fails. The error object contains
|
|
49
|
+
* additional `details` property with the response from the server if available.
|
|
50
|
+
* @property {import("../types").IStartCheckoutErrorResponse} error.details - The response body from the server when an error occurs.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Verifies the 3DS transaction status.
|
|
58
|
+
* @returns {Promise<import("../types").ITransaction | void>} The result of the 3DS verification and checkout resumption.
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
verify3dsTransaction(): Promise<ITransaction | void>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves the list of cards associated with a customer.
|
|
65
|
+
* @returns {Promise<import("../types").ICustomerCardsResponse>} A promise that resolves with the customer's card data.
|
|
66
|
+
*
|
|
67
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
getCustomerCards(): Promise<ICustomerCardsResponse>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Saves a card to a customer's account. This method can be used to add a new card
|
|
75
|
+
* or update an existing one.
|
|
76
|
+
* @param {import("../types").ISaveCardRequest} card - The card information to be saved.
|
|
77
|
+
* @returns {Promise<import("../types").ISaveCardResponse>} A promise that resolves with the saved card data.
|
|
78
|
+
*
|
|
79
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
saveCustomerCard(
|
|
84
|
+
card: ISaveCardRequest,
|
|
85
|
+
): Promise<ISaveCardResponse>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Removes a card from a customer's account.
|
|
89
|
+
* @param {string} skyflowId - The unique identifier of the card to be deleted.
|
|
90
|
+
* @returns {Promise<string>} A promise that resolves when the card is successfully deleted.
|
|
91
|
+
*
|
|
92
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
removeCustomerCard(
|
|
97
|
+
skyflowId: string,
|
|
98
|
+
): Promise<string>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Retrieves the list of available Alternative Payment Methods (APMs).
|
|
102
|
+
* @returns {Promise<import("../types").IPaymentMethod[]>} A promise that resolves with the list of APMs.
|
|
103
|
+
*
|
|
104
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
getCustomerPaymentMethods(): Promise<IPaymentMethod[]>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Retrieves the business information.
|
|
112
|
+
* @returns {Promise<import("../types").GetBusinessResponse>} A promise that resolves with the business information.
|
|
113
|
+
*
|
|
114
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
getBusiness(): Promise<GetBusinessResponse>;
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
// TODO: DEPRECATED
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
124
|
+
* It is no longer necessary to use this method as customer registration is now automatically handled
|
|
125
|
+
* during the payment process or when using card management methods.
|
|
126
|
+
*/
|
|
127
|
+
async customerRegister(email: string): Promise<CustomerRegisterResponse | ErrorResponse>
|
|
128
|
+
|
|
129
|
+
// TODO: DEPRECATED
|
|
130
|
+
/**
|
|
131
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
132
|
+
* It is no longer necessary to use this method as order creation is now automatically
|
|
133
|
+
* handled when making a payment through the `payment` function.
|
|
134
|
+
*/
|
|
135
|
+
async createOrder(orderItems: CreateOrderRequest): Promise<CreateOrderResponse | ErrorResponse>
|
|
136
|
+
|
|
137
|
+
// TODO: DEPRECATED
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
140
|
+
* It is no longer necessary to use this method as payment creation is now automatically
|
|
141
|
+
* handled when making a payment through the `payment` function.
|
|
142
|
+
*/
|
|
143
|
+
async createPayment(paymentItems: CreatePaymentRequest): Promise<CreatePaymentResponse | ErrorResponse>
|
|
144
|
+
|
|
145
|
+
// TODO: DEPRECATED
|
|
146
|
+
/**
|
|
147
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
148
|
+
* Use the {@link payment} method
|
|
149
|
+
*/
|
|
150
|
+
async startCheckoutRouter(routerData: StartCheckoutRequest | StartCheckoutIdRequest): Promise<StartCheckoutResponse | ErrorResponse | undefined>
|
|
151
|
+
|
|
152
|
+
// TODO: DEPRECATED
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
155
|
+
* Use the {@link payment} method
|
|
156
|
+
*/
|
|
157
|
+
async startCheckoutRouterFull(routerFullData: StartCheckoutFullRequest): Promise<StartCheckoutResponse | ErrorResponse | undefined>
|
|
158
|
+
|
|
159
|
+
// TODO: DEPRECATED
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
162
|
+
* Use the {@link saveCustomerCard} method
|
|
163
|
+
*/
|
|
164
|
+
async registerCustomerCard(customerToken: string, data: RegisterCustomerCardRequest): Promise<RegisterCustomerCardResponse | ErrorResponse>
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
// TODO: DEPRECATED
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
170
|
+
* Use the {@link removeCustomerCard} method
|
|
171
|
+
*/
|
|
172
|
+
async deleteCustomerCard(customerToken: string, skyflowId: string = ""): Promise<Boolean | ErrorResponse>
|
|
173
|
+
|
|
174
|
+
// TODO: DEPRECATED
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
177
|
+
* Use the {@link getCustomerPaymentMethods} method
|
|
178
|
+
*/
|
|
179
|
+
async getActiveAPMs(): Promise<APM[]>;
|
|
180
|
+
|
|
181
|
+
// TODO: DEPRECATED
|
|
182
|
+
/**
|
|
183
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
184
|
+
* It is no longer necessary to use this method as customer registration is now automatically handled
|
|
185
|
+
* during the payment process or when using card management methods.
|
|
186
|
+
*/
|
|
187
|
+
async getSkyflowTokens({vault_id, vault_url, data}: TokensRequest): Promise<any | ErrorResponse>
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
export interface IInlineLiteCheckoutOptions extends IInlineCheckoutBaseOptions {}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface IPaymentMethodResponse {
|
|
2
|
+
count: number;
|
|
3
|
+
next: string | null;
|
|
4
|
+
previous: string | null;
|
|
5
|
+
results: ITonderPaymentMethod[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ITonderPaymentMethod {
|
|
9
|
+
pk: string;
|
|
10
|
+
payment_method: string;
|
|
11
|
+
priority: number;
|
|
12
|
+
category: string;
|
|
13
|
+
unavailable_countries: string[];
|
|
14
|
+
status: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IPaymentMethod {
|
|
18
|
+
id: string;
|
|
19
|
+
payment_method: string;
|
|
20
|
+
priority: number;
|
|
21
|
+
category: string;
|
|
22
|
+
icon: string;
|
|
23
|
+
label: string;
|
|
24
|
+
}
|
package/src/types/requests.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OrderItem } from "./commons";
|
|
2
1
|
import { SkyflowRecord } from "./skyflow";
|
|
2
|
+
import {IItem} from "./checkout";
|
|
3
3
|
|
|
4
4
|
export interface CreateOrderRequest {
|
|
5
5
|
business: string,
|
|
@@ -10,7 +10,7 @@ export interface CreateOrderRequest {
|
|
|
10
10
|
status?: string,
|
|
11
11
|
reference: string | number,
|
|
12
12
|
is_oneclick: boolean,
|
|
13
|
-
items:
|
|
13
|
+
items: IItem[]
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export type CreatePaymentRequest = {
|
|
@@ -71,6 +71,15 @@ export type RegisterCustomerCardRequest = {
|
|
|
71
71
|
skyflow_id: string;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
export type TokensSkyflowRequest = {
|
|
75
|
+
baseUrl: string;
|
|
76
|
+
apiKey: string;
|
|
77
|
+
vault_id: string,
|
|
78
|
+
vault_url: string,
|
|
79
|
+
data: {
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
74
83
|
export type TokensRequest = {
|
|
75
84
|
vault_id: string,
|
|
76
85
|
vault_url: string,
|
|
@@ -81,7 +90,7 @@ export type TokensRequest = {
|
|
|
81
90
|
|
|
82
91
|
export type StartCheckoutFullRequest = {
|
|
83
92
|
order: {
|
|
84
|
-
items:
|
|
93
|
+
items: IItem[];
|
|
85
94
|
};
|
|
86
95
|
total: number;
|
|
87
96
|
customer: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function validateCardNumber(cardNumber: string): boolean;
|
|
2
|
+
|
|
3
|
+
export declare function validateCardholderName(name: string): boolean;
|
|
4
|
+
|
|
5
|
+
export declare function validateCVV(cvv: string): boolean;
|
|
6
|
+
|
|
7
|
+
export declare function validateExpirationMonth(month: string): boolean;
|
|
8
|
+
|
|
9
|
+
export declare function validateExpirationYear(year: string): boolean;
|
|
10
|
+
|
|
11
|
+
export declare function validateExpirationDateParts(month: string, year: string): boolean;
|
|
@@ -38,9 +38,9 @@ describe("LiteCheckout", () => {
|
|
|
38
38
|
|
|
39
39
|
it("Can instance LiteCheckout", () => {
|
|
40
40
|
expect(liteCheckout).toBeInstanceOf(LiteCheckout);
|
|
41
|
-
expect(liteCheckout.apiKeyTonder).toEqual(constructorFields.
|
|
42
|
-
expect(liteCheckout.
|
|
43
|
-
expect(liteCheckout.signal).toEqual(constructorFields.signal);
|
|
41
|
+
expect(liteCheckout.apiKeyTonder).toEqual(constructorFields.apiKey);
|
|
42
|
+
expect(liteCheckout.baseUrl).toEqual(constructorFields.baseUrl);
|
|
43
|
+
expect(liteCheckout.abortController.signal).toEqual(constructorFields.signal);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
|
|
@@ -84,7 +84,7 @@ describe("getBusiness", () => {
|
|
|
84
84
|
let error: ErrorResponse;
|
|
85
85
|
|
|
86
86
|
try {
|
|
87
|
-
const response = (await liteCheckout.getBusiness())
|
|
87
|
+
const response = (await liteCheckout.getBusiness());
|
|
88
88
|
} catch (e: any) {
|
|
89
89
|
error = e;
|
|
90
90
|
expect(error.code).toStrictEqual("400");
|
|
@@ -100,7 +100,7 @@ describe("getBusiness", () => {
|
|
|
100
100
|
let error: ErrorResponse;
|
|
101
101
|
|
|
102
102
|
try {
|
|
103
|
-
const response = (await liteCheckout.getBusiness())
|
|
103
|
+
const response = (await liteCheckout.getBusiness());
|
|
104
104
|
} catch (e: any) {
|
|
105
105
|
error = e;
|
|
106
106
|
expect(error.message).toStrictEqual("error");
|
|
@@ -48,7 +48,7 @@ describe("getCustomerCards", () => {
|
|
|
48
48
|
})
|
|
49
49
|
);
|
|
50
50
|
|
|
51
|
-
const response = await liteCheckout.getCustomerCards(
|
|
51
|
+
const response = await liteCheckout.getCustomerCards();
|
|
52
52
|
|
|
53
53
|
expect(response).toStrictEqual({ ...new GetCustomerCardsResponseClass() });
|
|
54
54
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
@@ -65,7 +65,7 @@ describe("getCustomerCards", () => {
|
|
|
65
65
|
})
|
|
66
66
|
);
|
|
67
67
|
|
|
68
|
-
const response = await liteCheckout.getCustomerCards(
|
|
68
|
+
const response = await liteCheckout.getCustomerCards();
|
|
69
69
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
70
70
|
expect(liteCheckoutSpy).toHaveReturned();
|
|
71
71
|
expect(response).toBeUndefined();
|
|
@@ -85,9 +85,7 @@ describe("getCustomerCards", () => {
|
|
|
85
85
|
let error: ErrorResponse;
|
|
86
86
|
|
|
87
87
|
try {
|
|
88
|
-
const response = (await liteCheckout.getCustomerCards(
|
|
89
|
-
"1234"
|
|
90
|
-
)) as IErrorResponse;
|
|
88
|
+
const response = (await liteCheckout.getCustomerCards());
|
|
91
89
|
} catch (e: any) {
|
|
92
90
|
error = e;
|
|
93
91
|
expect(error.code).toStrictEqual("400");
|
|
@@ -103,9 +101,7 @@ describe("getCustomerCards", () => {
|
|
|
103
101
|
let error: ErrorResponse;
|
|
104
102
|
|
|
105
103
|
try {
|
|
106
|
-
const response = (await liteCheckout.getCustomerCards(
|
|
107
|
-
"1234"
|
|
108
|
-
)) as IErrorResponse;
|
|
104
|
+
const response = (await liteCheckout.getCustomerCards());
|
|
109
105
|
} catch (e: any) {
|
|
110
106
|
error = e;
|
|
111
107
|
expect(error.message).toStrictEqual("error");
|
|
@@ -4,9 +4,8 @@ import {
|
|
|
4
4
|
CreatePaymentRequest,
|
|
5
5
|
RegisterCustomerCardRequest,
|
|
6
6
|
StartCheckoutRequest,
|
|
7
|
-
TokensRequest,
|
|
8
7
|
StartCheckoutFullRequest,
|
|
9
|
-
StartCheckoutRequestWithCard
|
|
8
|
+
StartCheckoutRequestWithCard, TokensSkyflowRequest
|
|
10
9
|
} from "../../src/types/requests";
|
|
11
10
|
import {
|
|
12
11
|
CreateOrderResponse,
|
|
@@ -556,13 +555,17 @@ export class StartCheckoutFullRequestClass implements StartCheckoutFullRequest {
|
|
|
556
555
|
}
|
|
557
556
|
}
|
|
558
557
|
|
|
559
|
-
export class TokensRequestClass implements
|
|
558
|
+
export class TokensRequestClass implements TokensSkyflowRequest {
|
|
559
|
+
baseUrl!: string;
|
|
560
|
+
apiKey!: string;
|
|
560
561
|
vault_id!: string;
|
|
561
562
|
vault_url!: string;
|
|
562
563
|
data: { [key: string]: any } = {};
|
|
563
564
|
|
|
564
|
-
get mockObject():
|
|
565
|
+
get mockObject(): TokensSkyflowRequest {
|
|
565
566
|
return {
|
|
567
|
+
baseUrl: "",
|
|
568
|
+
apiKey: "",
|
|
566
569
|
vault_id: "string",
|
|
567
570
|
vault_url: "string",
|
|
568
571
|
data: {
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import "../utils/defaultMock";
|
|
2
|
-
import { LiteCheckout } from "../../src";
|
|
3
|
-
import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
4
|
-
import { LiteCheckoutConstructor } from "../../src/classes/liteCheckout";
|
|
5
|
-
import { IErrorResponse } from "../../src/types/responses";
|
|
6
|
-
import { constructorFields } from "../utils/defaultMock";
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
interface Window {
|
|
10
|
-
OpenPay: any;
|
|
11
|
-
Skyflow: any;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe("getOpenpayDeviceSessionID", () => {
|
|
16
|
-
let checkoutConstructor: LiteCheckoutConstructor,
|
|
17
|
-
liteCheckout: LiteCheckout,
|
|
18
|
-
fetchSpy: jest.SpyInstance,
|
|
19
|
-
liteCheckoutSpy: jest.SpyInstance;
|
|
20
|
-
|
|
21
|
-
beforeEach(async () => {
|
|
22
|
-
window.fetch = jest.fn();
|
|
23
|
-
|
|
24
|
-
checkoutConstructor = {
|
|
25
|
-
...constructorFields,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
liteCheckout = new LiteCheckout(constructorFields);
|
|
29
|
-
|
|
30
|
-
fetchSpy = jest.spyOn(global, "fetch");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(() => {
|
|
34
|
-
jest.restoreAllMocks();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("getOpenpayDeviceSessionID success", async () => {
|
|
38
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getOpenpayDeviceSessionID");
|
|
39
|
-
|
|
40
|
-
window.OpenPay = {
|
|
41
|
-
setId: jest.fn(),
|
|
42
|
-
setApiKey: jest.fn(),
|
|
43
|
-
setSandboxMode: jest.fn(),
|
|
44
|
-
deviceData: {
|
|
45
|
-
setup: jest.fn().mockImplementation(() => Promise.resolve("test")),
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
expect(
|
|
50
|
-
liteCheckout.getOpenpayDeviceSessionID("4321", "1234", true)
|
|
51
|
-
).resolves.toBe("test");
|
|
52
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith("4321", "1234", true);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("getOpenpayDeviceSessionID empty", async () => {
|
|
56
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getOpenpayDeviceSessionID");
|
|
57
|
-
|
|
58
|
-
window.OpenPay = {
|
|
59
|
-
setId: jest.fn(),
|
|
60
|
-
setApiKey: jest.fn(),
|
|
61
|
-
setSandboxMode: jest.fn(),
|
|
62
|
-
deviceData: {
|
|
63
|
-
setup: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
expect(
|
|
68
|
-
liteCheckout.getOpenpayDeviceSessionID("", "", true)
|
|
69
|
-
).resolves.toBeUndefined();
|
|
70
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith("", "", true);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("getOpenpayDeviceSessionID error", async () => {
|
|
74
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getOpenpayDeviceSessionID");
|
|
75
|
-
|
|
76
|
-
window.OpenPay = {
|
|
77
|
-
setId: jest.fn(),
|
|
78
|
-
setApiKey: jest.fn(),
|
|
79
|
-
setSandboxMode: jest.fn(),
|
|
80
|
-
deviceData: {
|
|
81
|
-
setup: jest.fn().mockRejectedValue("error"),
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
await liteCheckout.getOpenpayDeviceSessionID("", "", true);
|
|
87
|
-
} catch (e) {
|
|
88
|
-
const error: IErrorResponse = e as IErrorResponse;
|
|
89
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith("", "", true);
|
|
90
|
-
expect(liteCheckoutSpy).toHaveReturned();
|
|
91
|
-
expect(error.message).toStrictEqual("error");
|
|
92
|
-
expect(error).toBeInstanceOf(ErrorResponse);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import "../utils/defaultMock";
|
|
2
|
-
import Skyflow from "skyflow-js";
|
|
3
|
-
import { LiteCheckout } from "../../src";
|
|
4
|
-
import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
5
|
-
import { LiteCheckoutConstructor } from "../../src/classes/liteCheckout";
|
|
6
|
-
import { IErrorResponse } from "../../src/types/responses";
|
|
7
|
-
import { constructorFields } from "../utils/defaultMock";
|
|
8
|
-
import { TokensRequestClass } from "../utils/mockClasses";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare global {
|
|
12
|
-
interface Window {
|
|
13
|
-
OpenPay: any;
|
|
14
|
-
Skyflow: any;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe("getSkyflowToken", () => {
|
|
19
|
-
let checkoutConstructor: LiteCheckoutConstructor,
|
|
20
|
-
liteCheckout: LiteCheckout,
|
|
21
|
-
fetchSpy: jest.SpyInstance,
|
|
22
|
-
liteCheckoutSpy: jest.SpyInstance;
|
|
23
|
-
|
|
24
|
-
beforeEach(async () => {
|
|
25
|
-
window.fetch = jest.fn();
|
|
26
|
-
|
|
27
|
-
checkoutConstructor = {
|
|
28
|
-
...constructorFields,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
liteCheckout = new LiteCheckout(constructorFields);
|
|
32
|
-
|
|
33
|
-
fetchSpy = jest.spyOn(global, "fetch");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
afterEach(() => {
|
|
37
|
-
jest.restoreAllMocks();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("getSkyflowTokens success", async () => {
|
|
41
|
-
liteCheckout.getVaultToken = jest
|
|
42
|
-
.fn()
|
|
43
|
-
.mockImplementation(() => Promise.resolve("1234"));
|
|
44
|
-
|
|
45
|
-
liteCheckout.getFieldsPromise = jest
|
|
46
|
-
.fn()
|
|
47
|
-
.mockImplementation(() =>
|
|
48
|
-
Promise.resolve(new Array(5).fill(Promise.resolve(true)))
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getSkyflowTokens");
|
|
52
|
-
|
|
53
|
-
const response = await liteCheckout.getSkyflowTokens({
|
|
54
|
-
...new TokensRequestClass(),
|
|
55
|
-
});
|
|
56
|
-
expect(response).toStrictEqual("1234");
|
|
57
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("getSkyflowTokens empty", async () => {
|
|
61
|
-
liteCheckout.getVaultToken = jest
|
|
62
|
-
.fn()
|
|
63
|
-
.mockImplementation(() => Promise.resolve(""));
|
|
64
|
-
|
|
65
|
-
jest.spyOn(Skyflow, "init").mockImplementation(jest.fn().mockImplementation(() => ({
|
|
66
|
-
container: () => ({
|
|
67
|
-
collect: jest.fn().mockResolvedValue(""),
|
|
68
|
-
}),
|
|
69
|
-
})));
|
|
70
|
-
|
|
71
|
-
liteCheckout.getFieldsPromise = jest
|
|
72
|
-
.fn()
|
|
73
|
-
.mockImplementation(() =>
|
|
74
|
-
Promise.resolve(new Array(5).fill(Promise.resolve(true)))
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getSkyflowTokens");
|
|
78
|
-
|
|
79
|
-
let error: ErrorResponse;
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
const response = await liteCheckout.getSkyflowTokens({
|
|
83
|
-
...new TokensRequestClass(),
|
|
84
|
-
}) as IErrorResponse;
|
|
85
|
-
} catch (e: any) {
|
|
86
|
-
error = e;
|
|
87
|
-
expect(error).toBeInstanceOf(ErrorResponse);
|
|
88
|
-
expect(error.message).toStrictEqual("Por favor, verifica todos los campos de tu tarjeta");
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("getSkyflowTokens error mount fields", async () => {
|
|
93
|
-
liteCheckout.getVaultToken = jest
|
|
94
|
-
.fn()
|
|
95
|
-
.mockImplementation(() => Promise.resolve(""));
|
|
96
|
-
|
|
97
|
-
jest.spyOn(Skyflow, "init").mockImplementation(jest.fn().mockImplementation(() => ({
|
|
98
|
-
container: () => ({
|
|
99
|
-
collect: jest.fn().mockResolvedValue(""),
|
|
100
|
-
}),
|
|
101
|
-
})));
|
|
102
|
-
|
|
103
|
-
liteCheckout.getFieldsPromise = jest
|
|
104
|
-
.fn()
|
|
105
|
-
.mockImplementation(() =>
|
|
106
|
-
new Array(5).fill(false)
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getSkyflowTokens");
|
|
110
|
-
|
|
111
|
-
let error: ErrorResponse;
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
const response = (await liteCheckout.getSkyflowTokens({
|
|
115
|
-
...new TokensRequestClass(),
|
|
116
|
-
})) as IErrorResponse;
|
|
117
|
-
} catch (e: any) {
|
|
118
|
-
error = e;
|
|
119
|
-
expect(error).toBeInstanceOf(ErrorResponse);
|
|
120
|
-
expect(error.message).toStrictEqual("Ocurrió un error al montar los campos de la tarjeta");
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("getSkyflowTokens error collect catch", async () => {
|
|
125
|
-
liteCheckout.getVaultToken = jest
|
|
126
|
-
.fn()
|
|
127
|
-
.mockImplementation(() => Promise.resolve("1234"));
|
|
128
|
-
|
|
129
|
-
jest.spyOn(Skyflow, "init").mockImplementation(jest.fn().mockImplementation(() => ({
|
|
130
|
-
container: () => ({
|
|
131
|
-
collect: jest.fn().mockRejectedValue("error"),
|
|
132
|
-
}),
|
|
133
|
-
})));
|
|
134
|
-
|
|
135
|
-
liteCheckout.getFieldsPromise = jest
|
|
136
|
-
.fn()
|
|
137
|
-
.mockImplementation(() =>
|
|
138
|
-
Promise.resolve(new Array(5).fill(Promise.resolve(true)))
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getSkyflowTokens");
|
|
142
|
-
|
|
143
|
-
let error: ErrorResponse;
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
const response = (await liteCheckout.getSkyflowTokens({
|
|
147
|
-
...new TokensRequestClass(),
|
|
148
|
-
})) as IErrorResponse;
|
|
149
|
-
} catch (e: any) {
|
|
150
|
-
error = e;
|
|
151
|
-
expect(error.message).toStrictEqual("error");
|
|
152
|
-
expect(error).toBeInstanceOf(ErrorResponse);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
});
|