tonder-web-sdk 1.12.0-beta.10 → 1.12.0-beta.11
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/workspace.xml +21 -39
- package/README.md +558 -84
- package/package.json +1 -1
- package/src/classes/BaseInlineCheckout.js +1 -7
- package/src/classes/LiteInlineCheckout.js +35 -37
- package/src/classes/inlineCheckout.js +43 -40
- package/types/inlineCheckout.d.ts +43 -0
- package/types/liteInlineCheckout.d.ts +64 -0
- package/v1/bundle.min.js +1 -1
package/package.json
CHANGED
|
@@ -13,12 +13,7 @@ import { getBrowserInfo, injectMercadoPagoSecurity } from "../helpers/utils";
|
|
|
13
13
|
export class BaseInlineCheckout {
|
|
14
14
|
baseUrl = "";
|
|
15
15
|
cartTotal = "0";
|
|
16
|
-
constructor({
|
|
17
|
-
mode = "stage",
|
|
18
|
-
apiKey,
|
|
19
|
-
returnUrl,
|
|
20
|
-
callBack = () => {},
|
|
21
|
-
}) {
|
|
16
|
+
constructor({ mode = "stage", apiKey, returnUrl, callBack = () => {} }) {
|
|
22
17
|
this.apiKeyTonder = apiKey;
|
|
23
18
|
this.returnUrl = returnUrl;
|
|
24
19
|
this.callBack = callBack;
|
|
@@ -75,7 +70,6 @@ export class BaseInlineCheckout {
|
|
|
75
70
|
this.#handleMetadata(data);
|
|
76
71
|
this.#handleCurrency(data);
|
|
77
72
|
this.#handleCard(data);
|
|
78
|
-
console.log("data", data)
|
|
79
73
|
const response = await this._checkout(data);
|
|
80
74
|
this.process3ds.setPayload(response);
|
|
81
75
|
this.callBack(response);
|
|
@@ -14,7 +14,6 @@ import { MESSAGES } from "../shared/constants/messages";
|
|
|
14
14
|
export class LiteInlineCheckout extends BaseInlineCheckout {
|
|
15
15
|
#customerData;
|
|
16
16
|
constructor({ mode = "stage", apiKey, returnUrl, callBack = () => {} }) {
|
|
17
|
-
|
|
18
17
|
super({ mode, apiKey, returnUrl, callBack });
|
|
19
18
|
}
|
|
20
19
|
|
|
@@ -104,22 +103,22 @@ export class LiteInlineCheckout extends BaseInlineCheckout {
|
|
|
104
103
|
* @public
|
|
105
104
|
*/
|
|
106
105
|
async removeCustomerCard(skyflowId) {
|
|
107
|
-
try{
|
|
106
|
+
try {
|
|
108
107
|
const { auth_token } = await this.#getCustomer();
|
|
109
108
|
const { business } = this.merchantData;
|
|
110
109
|
|
|
111
110
|
return await removeCustomerCard(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
this.baseUrl,
|
|
112
|
+
auth_token,
|
|
113
|
+
skyflowId,
|
|
114
|
+
business?.pk,
|
|
116
115
|
);
|
|
117
|
-
}catch (error){
|
|
116
|
+
} catch (error) {
|
|
118
117
|
throw formatPublicErrorResponse(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
{
|
|
119
|
+
message: MESSAGES.removeCardError,
|
|
120
|
+
},
|
|
121
|
+
error,
|
|
123
122
|
);
|
|
124
123
|
}
|
|
125
124
|
}
|
|
@@ -137,29 +136,29 @@ export class LiteInlineCheckout extends BaseInlineCheckout {
|
|
|
137
136
|
const response = await fetchCustomerAPMs(this.baseUrl, this.apiKeyTonder);
|
|
138
137
|
|
|
139
138
|
const apms_results =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
response && "results" in response && response["results"].length > 0
|
|
140
|
+
? response["results"]
|
|
141
|
+
: [];
|
|
143
142
|
|
|
144
143
|
return apms_results
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}catch (error){
|
|
144
|
+
.filter((apmItem) => apmItem.category.toLowerCase() !== "cards")
|
|
145
|
+
.map((apmItem) => {
|
|
146
|
+
const apm = {
|
|
147
|
+
id: apmItem.pk,
|
|
148
|
+
payment_method: apmItem.payment_method,
|
|
149
|
+
priority: apmItem.priority,
|
|
150
|
+
category: apmItem.category,
|
|
151
|
+
...getPaymentMethodDetails(apmItem.payment_method),
|
|
152
|
+
};
|
|
153
|
+
return apm;
|
|
154
|
+
})
|
|
155
|
+
.sort((a, b) => a.priority - b.priority);
|
|
156
|
+
} catch (error) {
|
|
158
157
|
throw formatPublicErrorResponse(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
{
|
|
159
|
+
message: MESSAGES.getPaymentMethodsError,
|
|
160
|
+
},
|
|
161
|
+
error,
|
|
163
162
|
);
|
|
164
163
|
}
|
|
165
164
|
}
|
|
@@ -169,7 +168,6 @@ export class LiteInlineCheckout extends BaseInlineCheckout {
|
|
|
169
168
|
}
|
|
170
169
|
|
|
171
170
|
async _checkout({ card, payment_method }) {
|
|
172
|
-
console.log("_checkout", card, payment_method)
|
|
173
171
|
const customer = await this._getCustomer(
|
|
174
172
|
this.customer,
|
|
175
173
|
this.abortController.signal,
|
|
@@ -200,13 +198,13 @@ export class LiteInlineCheckout extends BaseInlineCheckout {
|
|
|
200
198
|
}
|
|
201
199
|
|
|
202
200
|
async #getCustomer() {
|
|
203
|
-
if(!!this.#customerData) return this.#customerData;
|
|
201
|
+
if (!!this.#customerData) return this.#customerData;
|
|
204
202
|
|
|
205
203
|
this.#customerData = await registerOrFetchCustomer(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
this.baseUrl,
|
|
205
|
+
this.apiKeyTonder,
|
|
206
|
+
this.customer,
|
|
209
207
|
);
|
|
210
|
-
return this.#customerData
|
|
208
|
+
return this.#customerData;
|
|
211
209
|
}
|
|
212
210
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {apmItemsTemplate, cardItemsTemplate, cardTemplate} from '../helpers/template.js'
|
|
1
|
+
import { apmItemsTemplate, cardItemsTemplate, cardTemplate } from '../helpers/template.js'
|
|
2
2
|
import {
|
|
3
3
|
clearSpace,
|
|
4
4
|
injectMercadoPagoSecurity,
|
|
@@ -6,18 +6,18 @@ import {
|
|
|
6
6
|
showError,
|
|
7
7
|
showMessage
|
|
8
8
|
} from '../helpers/utils';
|
|
9
|
-
import {initSkyflow} from '../helpers/skyflow'
|
|
10
|
-
import {globalLoader} from './globalLoader.js';
|
|
11
|
-
import {BaseInlineCheckout} from "./BaseInlineCheckout";
|
|
9
|
+
import { initSkyflow } from '../helpers/skyflow'
|
|
10
|
+
import { globalLoader } from './globalLoader.js';
|
|
11
|
+
import { BaseInlineCheckout } from "./BaseInlineCheckout";
|
|
12
12
|
import {
|
|
13
13
|
fetchCustomerCards,
|
|
14
14
|
removeCustomerCard,
|
|
15
15
|
saveCustomerCard,
|
|
16
16
|
fetchCustomerAPMs
|
|
17
17
|
} from "../data";
|
|
18
|
-
import {MESSAGES} from "../shared/constants/messages";
|
|
18
|
+
import { MESSAGES } from "../shared/constants/messages";
|
|
19
19
|
|
|
20
|
-
export class InlineCheckout extends BaseInlineCheckout{
|
|
20
|
+
export class InlineCheckout extends BaseInlineCheckout {
|
|
21
21
|
static injected = false;
|
|
22
22
|
static cardsInjected = false
|
|
23
23
|
static apmsInjected = false
|
|
@@ -130,20 +130,20 @@ export class InlineCheckout extends BaseInlineCheckout{
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
async #mount(containerTonderCheckout) {
|
|
133
|
-
containerTonderCheckout.innerHTML = cardTemplate({renderPaymentButton: this.renderPaymentButton, customStyles: this.customStyles});
|
|
133
|
+
containerTonderCheckout.innerHTML = cardTemplate({ renderPaymentButton: this.renderPaymentButton, customStyles: this.customStyles });
|
|
134
134
|
globalLoader.show()
|
|
135
135
|
await this.#mountTonder();
|
|
136
136
|
InlineCheckout.injected = true;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
async #mountAPMs() {
|
|
140
|
-
try{
|
|
140
|
+
try {
|
|
141
141
|
const apms = await fetchCustomerAPMs(this.baseUrl, this.apiKeyTonder);
|
|
142
|
-
if(apms && apms['results'] && apms['results'].length > 0){
|
|
142
|
+
if (apms && apms['results'] && apms['results'].length > 0) {
|
|
143
143
|
this.apmsData = apms['results']
|
|
144
144
|
this.#loadAPMList(apms['results'])
|
|
145
145
|
}
|
|
146
|
-
}catch(e){
|
|
146
|
+
} catch (e) {
|
|
147
147
|
console.warn("Error getting APMS")
|
|
148
148
|
}
|
|
149
149
|
}
|
|
@@ -256,39 +256,15 @@ export class InlineCheckout extends BaseInlineCheckout{
|
|
|
256
256
|
)
|
|
257
257
|
const { auth_token } = customerData;
|
|
258
258
|
if (auth_token && this.email) {
|
|
259
|
-
|
|
260
|
-
if (saveCard && "checked" in saveCard && saveCard.checked) {
|
|
261
|
-
try {
|
|
262
|
-
await saveCustomerCard(this.baseUrl, auth_token, business.pk, {
|
|
263
|
-
skyflow_id: cardTokens.skyflow_id,
|
|
264
|
-
});
|
|
265
|
-
showMessage(MESSAGES.cardSaved, this.collectorIds.msgNotification);
|
|
266
|
-
} catch (error) {
|
|
267
|
-
if (error?.message) {
|
|
268
|
-
showError(error.message)
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
this.cardsInjected = false;
|
|
273
|
-
|
|
274
|
-
const cards = await fetchCustomerCards(
|
|
275
|
-
this.baseUrl,
|
|
276
|
-
auth_token,
|
|
277
|
-
this.merchantData.business.pk,
|
|
278
|
-
);
|
|
279
|
-
if ("cards" in cards) {
|
|
280
|
-
const cardsMapped = cards.cards.map((card) => mapCards(card))
|
|
281
|
-
this.#loadCardsList(cardsMapped, auth_token)
|
|
282
|
-
}
|
|
283
|
-
}
|
|
259
|
+
await this.#handleSaveCard(auth_token, business.pk, cardTokens)
|
|
284
260
|
}
|
|
285
261
|
|
|
286
|
-
const selected_apm = this.apmsData ? this.apmsData.find((iapm) => iapm.pk ===
|
|
262
|
+
const selected_apm = this.apmsData ? this.apmsData.find((iapm) => iapm.pk === this.radioChecked) : {};
|
|
287
263
|
|
|
288
264
|
const jsonResponseRouter = await this._handleCheckout({
|
|
289
|
-
...(
|
|
290
|
-
|
|
291
|
-
|
|
265
|
+
...(selected_apm && Object.keys(selected_apm).length > 0
|
|
266
|
+
? { payment_method: selected_apm.payment_method }
|
|
267
|
+
: { card: cardTokens }),
|
|
292
268
|
customer: customerData
|
|
293
269
|
});
|
|
294
270
|
|
|
@@ -308,6 +284,33 @@ export class InlineCheckout extends BaseInlineCheckout{
|
|
|
308
284
|
}
|
|
309
285
|
};
|
|
310
286
|
|
|
287
|
+
async #handleSaveCard(auth_token, businessId, cardTokens) {
|
|
288
|
+
const saveCard = document.getElementById("save-checkout-card");
|
|
289
|
+
if (saveCard && "checked" in saveCard && saveCard.checked) {
|
|
290
|
+
try {
|
|
291
|
+
await saveCustomerCard(this.baseUrl, auth_token, businessId, {
|
|
292
|
+
skyflow_id: cardTokens.skyflow_id,
|
|
293
|
+
});
|
|
294
|
+
showMessage(MESSAGES.cardSaved, this.collectorIds.msgNotification);
|
|
295
|
+
} catch (error) {
|
|
296
|
+
if (error?.message) {
|
|
297
|
+
showError(error.message)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
this.cardsInjected = false;
|
|
302
|
+
|
|
303
|
+
const cards = await fetchCustomerCards(
|
|
304
|
+
this.baseUrl,
|
|
305
|
+
auth_token,
|
|
306
|
+
this.merchantData.business.pk,
|
|
307
|
+
);
|
|
308
|
+
if ("cards" in cards) {
|
|
309
|
+
const cardsMapped = cards.cards.map((card) => mapCards(card))
|
|
310
|
+
this.#loadCardsList(cardsMapped, auth_token)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
311
314
|
#loadCardsList(cards, token) {
|
|
312
315
|
if (this.cardsInjected) return;
|
|
313
316
|
const injectInterval = setInterval(() => {
|
|
@@ -391,7 +394,7 @@ export class InlineCheckout extends BaseInlineCheckout{
|
|
|
391
394
|
}
|
|
392
395
|
const businessId = this.merchantData.business.pk
|
|
393
396
|
await removeCustomerCard(this.baseUrl, customerToken, skyflow_id, businessId)
|
|
394
|
-
} catch(error) {} finally {
|
|
397
|
+
} catch (error) { } finally {
|
|
395
398
|
this.deletingCards = this.deletingCards.filter(id => id !== skyflow_id);
|
|
396
399
|
this.#refreshCardOnDelete(customerToken)
|
|
397
400
|
}
|
|
@@ -5,14 +5,57 @@ import {ITransaction} from "./transaction";
|
|
|
5
5
|
export class InlineCheckout {
|
|
6
6
|
constructor(options: IInlineCheckoutOptions);
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* 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.
|
|
10
|
+
* @param {import("../../types").IConfigureCheckout} data - Configuration data including customer information and potentially other settings.
|
|
11
|
+
* @returns {Promise<void>}.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
8
14
|
configureCheckout(data: IConfigureCheckout): Promise<void>;
|
|
9
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Injects the checkout into the DOM and initializes it.
|
|
18
|
+
* Checks for an existing container and sets up an observer if needed.
|
|
19
|
+
* @returns {void}
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
10
22
|
injectCheckout(): Promise<void>;
|
|
11
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Processes a payment.
|
|
26
|
+
* @param {import("../../types").IProcessPaymentRequest} data - Payment data including customer, cart, and other relevant information.
|
|
27
|
+
* @returns {Promise<import("../../types").IStartCheckoutResponse>} A promise that resolves with the payment response or 3DS redirect or is rejected with an error.
|
|
28
|
+
*
|
|
29
|
+
* @throws {Error} Throws an error if the checkout process fails. The error object contains
|
|
30
|
+
* additional `details` property with the response from the server if available.
|
|
31
|
+
* @property {import("../../types").IStartCheckoutErrorResponse} error.details - The response body from the server when an error occurs.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
12
35
|
payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse>;
|
|
13
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Verifies the 3DS transaction status.
|
|
39
|
+
* @returns {Promise<import("../../types").ITransaction | void>} The result of the 3DS verification and checkout resumption.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
14
42
|
verify3dsTransaction(): Promise<ITransaction | void>;
|
|
15
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Removes the checkout from the DOM and cleans up associated resources.
|
|
46
|
+
*
|
|
47
|
+
* This method performs the following actions:
|
|
48
|
+
* 1. Resets the injection status flags for the checkout, cards, and APMs.
|
|
49
|
+
* 2. Aborts any ongoing requests using the AbortController.
|
|
50
|
+
* 3. Creates a new AbortController for future use.
|
|
51
|
+
* 4. Clears any existing injection intervals.
|
|
52
|
+
*
|
|
53
|
+
* Note: This method should be called when you want to completely remove
|
|
54
|
+
* the checkout from the page and reset its state.
|
|
55
|
+
*
|
|
56
|
+
* @returns {void}
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
16
59
|
removeCheckout(): void;
|
|
17
60
|
}
|
|
18
61
|
|
|
@@ -7,24 +7,88 @@ import {ITransaction} from "./transaction";
|
|
|
7
7
|
export class LiteInlineCheckout {
|
|
8
8
|
constructor(options: IInlineLiteCheckoutOptions);
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 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.
|
|
12
|
+
* @param {import("../../types").IConfigureCheckout} data - Configuration data including customer information and potentially other settings.
|
|
13
|
+
* @returns {Promise<void>}.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
10
16
|
configureCheckout(data: IConfigureCheckout): void;
|
|
11
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Initializes and prepares the checkout for use.
|
|
20
|
+
* This method set up the initial environment.
|
|
21
|
+
* @returns {Promise<void>} A promise that resolves when the checkout has been initialized.
|
|
22
|
+
* @throws {Error} If there's any problem during the checkout initialization.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
12
25
|
injectCheckout(): Promise<void>;
|
|
13
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Processes a payment.
|
|
29
|
+
* @param {import("../../types").IProcessPaymentRequest} data - Payment data including customer, cart, and other relevant information.
|
|
30
|
+
* @returns {Promise<import("../../types").IStartCheckoutResponse>} A promise that resolves with the payment response or 3DS redirect or is rejected with an error.
|
|
31
|
+
*
|
|
32
|
+
* @throws {Error} Throws an error if the checkout process fails. The error object contains
|
|
33
|
+
* additional `details` property with the response from the server if available.
|
|
34
|
+
* @property {import("../../types").IStartCheckoutErrorResponse} error.details - The response body from the server when an error occurs.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
14
38
|
payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse>;
|
|
15
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Verifies the 3DS transaction status.
|
|
42
|
+
* @returns {Promise<import("../../types").ITransaction | void>} The result of the 3DS verification and checkout resumption.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
16
45
|
verify3dsTransaction(): Promise<ITransaction | void>;
|
|
17
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the list of cards associated with a customer.
|
|
49
|
+
* @returns {Promise<import("../../types").ICustomerCardsResponse>} A promise that resolves with the customer's card data.
|
|
50
|
+
*
|
|
51
|
+
* @throws {import("../../types").IPublicError} Throws an error object if the operation fails.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
18
55
|
getCustomerCards(): Promise<ICustomerCardsResponse>;
|
|
19
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Saves a card to a customer's account. This method can be used to add a new card
|
|
59
|
+
* or update an existing one.
|
|
60
|
+
* @param {import("../../types").ISaveCardRequest} card - The card information to be saved.
|
|
61
|
+
* @returns {Promise<import("../../types").ISaveCardResponse>} A promise that resolves with the saved card data.
|
|
62
|
+
*
|
|
63
|
+
* @throws {import("../../types").IPublicError} Throws an error object if the operation fails.
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
20
67
|
saveCustomerCard(
|
|
21
68
|
card: ISaveCardRequest,
|
|
22
69
|
): Promise<ISaveCardResponse>;
|
|
23
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Removes a card from a customer's account.
|
|
73
|
+
* @param {string} skyflowId - The unique identifier of the card to be deleted.
|
|
74
|
+
* @returns {Promise<string>} A promise that resolves when the card is successfully deleted.
|
|
75
|
+
*
|
|
76
|
+
* @throws {import("../../types").IPublicError} Throws an error object if the operation fails.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
24
80
|
removeCustomerCard(
|
|
25
81
|
skyflowId: string,
|
|
26
82
|
): Promise<void>;
|
|
27
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Retrieves the list of available Alternative Payment Methods (APMs).
|
|
86
|
+
* @returns {Promise<import("../../types").IPaymentMethod[]>} A promise that resolves with the list of APMs.
|
|
87
|
+
*
|
|
88
|
+
* @throws {import("../../types").IPublicError} Throws an error object if the operation fails.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
28
92
|
getCustomerPaymentMethods(): Promise<IPaymentMethod[]>;
|
|
29
93
|
}
|
|
30
94
|
|