tonder-web-sdk 1.9.0 → 1.9.2-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/README.md +1 -1
- package/package.json +1 -1
- package/src/helpers/skyflow.js +9 -37
- package/src/helpers/template.js +15 -12
- package/.htaccess +0 -1
- package/index.html +0 -178
- package/success.html +0 -22
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm i tonder-web-sdk
|
|
|
11
11
|
|
|
12
12
|
or using an script tag
|
|
13
13
|
```html
|
|
14
|
-
<script src="https://zplit-
|
|
14
|
+
<script src="https://zplit-prod.s3.amazonaws.com/v1/bundle.min.js"></script>
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Add dependencies to the root of the app (index.html)
|
package/package.json
CHANGED
package/src/helpers/skyflow.js
CHANGED
|
@@ -74,8 +74,6 @@ export async function initSkyflow(
|
|
|
74
74
|
|
|
75
75
|
handleSkyflowElementEvents(
|
|
76
76
|
cardHolderNameElement,
|
|
77
|
-
collectorIds.holderName,
|
|
78
|
-
"errorCardHolderIdTonder",
|
|
79
77
|
"titular de la tarjeta"
|
|
80
78
|
);
|
|
81
79
|
|
|
@@ -96,12 +94,9 @@ export async function initSkyflow(
|
|
|
96
94
|
|
|
97
95
|
handleSkyflowElementEvents(
|
|
98
96
|
cardNumberElement,
|
|
99
|
-
collectorIds.cardNumber,
|
|
100
|
-
"errorCardNumberIdTonder",
|
|
101
97
|
"número de tarjeta"
|
|
102
98
|
);
|
|
103
99
|
|
|
104
|
-
|
|
105
100
|
const cvvElement = await collectContainer.create({
|
|
106
101
|
table: "cards",
|
|
107
102
|
column: "cvv",
|
|
@@ -112,12 +107,6 @@ export async function initSkyflow(
|
|
|
112
107
|
validations: [regexMatchRule],
|
|
113
108
|
});
|
|
114
109
|
|
|
115
|
-
handleSkyflowElementEvents(
|
|
116
|
-
cvvElement,
|
|
117
|
-
collectorIds.cvv,
|
|
118
|
-
"errorCvvIdTonder"
|
|
119
|
-
);
|
|
120
|
-
|
|
121
110
|
const expiryMonthElement = await collectContainer.create({
|
|
122
111
|
table: "cards",
|
|
123
112
|
column: "expiration_month",
|
|
@@ -128,12 +117,6 @@ export async function initSkyflow(
|
|
|
128
117
|
validations: [regexMatchRule],
|
|
129
118
|
});
|
|
130
119
|
|
|
131
|
-
handleSkyflowElementEvents(
|
|
132
|
-
expiryMonthElement,
|
|
133
|
-
collectorIds.expirationMonth,
|
|
134
|
-
"errorExpiryMonthIdTonder"
|
|
135
|
-
);
|
|
136
|
-
|
|
137
120
|
const expiryYearElement = await collectContainer.create({
|
|
138
121
|
table: "cards",
|
|
139
122
|
column: "expiration_year",
|
|
@@ -144,12 +127,6 @@ export async function initSkyflow(
|
|
|
144
127
|
validations: [regexMatchRule],
|
|
145
128
|
});
|
|
146
129
|
|
|
147
|
-
handleSkyflowElementEvents(
|
|
148
|
-
expiryYearElement,
|
|
149
|
-
collectorIds.expirationYear,
|
|
150
|
-
"errorExpiryYearIdTonder"
|
|
151
|
-
);
|
|
152
|
-
|
|
153
130
|
await mountElements(
|
|
154
131
|
cardNumberElement,
|
|
155
132
|
cvvElement,
|
|
@@ -185,28 +162,23 @@ async function mountElements(
|
|
|
185
162
|
}
|
|
186
163
|
|
|
187
164
|
|
|
188
|
-
function handleSkyflowElementEvents(element,
|
|
165
|
+
function handleSkyflowElementEvents(element, fieldMessage= "", requiredMessage = "El campo es requerido", invalidMessage= "El campo es inválido") {
|
|
189
166
|
if ("on" in element) {
|
|
190
167
|
element.on(Skyflow.EventName.CHANGE, (state) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
errorElement.remove();
|
|
168
|
+
if (state.isValid && !state.isEmpty) {
|
|
169
|
+
element.resetError();
|
|
194
170
|
}
|
|
195
171
|
});
|
|
196
172
|
|
|
197
173
|
element.on(Skyflow.EventName.BLUR, (state) => {
|
|
198
|
-
let container = document.getElementById(elementId);
|
|
199
|
-
let errorElement = document.getElementById(errorElementId);
|
|
200
|
-
if (errorElement) {
|
|
201
|
-
errorElement.remove();
|
|
202
|
-
}
|
|
203
174
|
if (!state.isValid) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
errorLabel.id = errorElementId;
|
|
207
|
-
errorLabel.textContent = state.isEmpty ? requiredMessage : fieldMessage != "" ?`El campo ${fieldMessage} es inválido`: invalidMessage;
|
|
208
|
-
container?.appendChild(errorLabel);
|
|
175
|
+
const msj_error = state.isEmpty ? requiredMessage : fieldMessage != "" ?`El campo ${fieldMessage} es inválido`: invalidMessage;
|
|
176
|
+
element.setError(msj_error);
|
|
209
177
|
}
|
|
210
178
|
});
|
|
179
|
+
|
|
180
|
+
element.on(Skyflow.EventName.FOCUS, (state) => {
|
|
181
|
+
element.resetError();
|
|
182
|
+
});
|
|
211
183
|
}
|
|
212
184
|
}
|
package/src/helpers/template.js
CHANGED
|
@@ -35,7 +35,7 @@ export const cardTemplate = `
|
|
|
35
35
|
.container-tonder {
|
|
36
36
|
background-color: #F9F9F9;
|
|
37
37
|
margin: 0 auto !important;
|
|
38
|
-
padding: 30px
|
|
38
|
+
padding: 30px 25px;
|
|
39
39
|
overflow: hidden;
|
|
40
40
|
transition: max-height 0.5s ease-out;
|
|
41
41
|
max-width: 600px;
|
|
@@ -134,7 +134,8 @@ export const cardTemplate = `
|
|
|
134
134
|
top: 0;
|
|
135
135
|
left: 0;
|
|
136
136
|
width: 100%;
|
|
137
|
-
height: 100
|
|
137
|
+
height: 100%;
|
|
138
|
+
z-index: 1;
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
@media screen and (max-width: 600px) {
|
|
@@ -174,12 +175,13 @@ export const cardTemplate = `
|
|
|
174
175
|
justify-content: start;
|
|
175
176
|
align-items: center;
|
|
176
177
|
color: #1D1D1D;
|
|
177
|
-
gap: 33%
|
|
178
|
+
gap: 33% 15px;
|
|
178
179
|
margin-top: 10px;
|
|
179
180
|
margin-bottom: 10px;
|
|
180
181
|
padding-left: 10px;
|
|
181
182
|
padding-right: 10px;
|
|
182
|
-
width:
|
|
183
|
+
width: 100%;
|
|
184
|
+
position: relative;
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
.pay-new-card .card-number {
|
|
@@ -199,15 +201,14 @@ export const cardTemplate = `
|
|
|
199
201
|
gap: 33% 20px;
|
|
200
202
|
margin-top: 10px;
|
|
201
203
|
margin-bottom: 10px;
|
|
202
|
-
|
|
203
|
-
padding-right: 10px;
|
|
204
|
-
width: 90%;
|
|
204
|
+
width: 100%;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
.card_selected {
|
|
208
208
|
position: relative;
|
|
209
209
|
width: 16px;
|
|
210
210
|
height: 16px;
|
|
211
|
+
min-width: 16px;
|
|
211
212
|
appearance: none;
|
|
212
213
|
cursor: pointer;
|
|
213
214
|
border-radius: 100%;
|
|
@@ -240,6 +241,7 @@ export const cardTemplate = `
|
|
|
240
241
|
position: relative;
|
|
241
242
|
width: 16px;
|
|
242
243
|
height: 16px;
|
|
244
|
+
min-width: 16px;
|
|
243
245
|
appearance: none;
|
|
244
246
|
cursor: pointer;
|
|
245
247
|
border-radius: 100%;
|
|
@@ -284,6 +286,7 @@ export const cardTemplate = `
|
|
|
284
286
|
opacity: 10;
|
|
285
287
|
}
|
|
286
288
|
|
|
289
|
+
|
|
287
290
|
.error-custom-inputs-tonder {
|
|
288
291
|
background-color: white;
|
|
289
292
|
position: absolute;
|
|
@@ -337,16 +340,15 @@ export const cardItemsTemplate = (cards) => {
|
|
|
337
340
|
gap: 33% 20px;
|
|
338
341
|
margin-top: 10px;
|
|
339
342
|
margin-bottom: 10px;
|
|
340
|
-
|
|
341
|
-
padding-right: 10px;
|
|
342
|
-
width: 90%;
|
|
343
|
+
width: 100%;
|
|
343
344
|
}
|
|
344
345
|
|
|
345
346
|
.card-item {
|
|
347
|
+
position: relative;
|
|
346
348
|
display: flex;
|
|
347
349
|
justify-content: start;
|
|
348
350
|
align-items: center;
|
|
349
|
-
gap: 33%
|
|
351
|
+
gap: 33% 15px;
|
|
350
352
|
}
|
|
351
353
|
|
|
352
354
|
.card-item .card-number {
|
|
@@ -373,10 +375,10 @@ export const cardItemsTemplate = (cards) => {
|
|
|
373
375
|
background-color: transparent !important;
|
|
374
376
|
color: #D91C1C !important;
|
|
375
377
|
}
|
|
376
|
-
|
|
377
378
|
.card_selected {
|
|
378
379
|
position: relative;
|
|
379
380
|
width: 16px;
|
|
381
|
+
min-width: 16px;
|
|
380
382
|
height: 16px;
|
|
381
383
|
appearance: none;
|
|
382
384
|
cursor: pointer;
|
|
@@ -410,6 +412,7 @@ export const cardItemsTemplate = (cards) => {
|
|
|
410
412
|
position: relative;
|
|
411
413
|
width: 16px;
|
|
412
414
|
height: 16px;
|
|
415
|
+
min-width: 16px;
|
|
413
416
|
appearance: none;
|
|
414
417
|
cursor: pointer;
|
|
415
418
|
border-radius: 100%;
|
package/.htaccess
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
DirectoryIndex index.html
|
package/index.html
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<style>
|
|
8
|
-
#checkout-container {
|
|
9
|
-
display: flex;
|
|
10
|
-
justify-content: center;
|
|
11
|
-
}
|
|
12
|
-
#pay-button {
|
|
13
|
-
padding: 10px 20px;
|
|
14
|
-
margin-top: 30px;
|
|
15
|
-
background-color: #4a90e2;
|
|
16
|
-
color: white;
|
|
17
|
-
border: none;
|
|
18
|
-
border-radius: 5px;
|
|
19
|
-
font-size: 16px;
|
|
20
|
-
cursor: pointer;
|
|
21
|
-
transition: background-color 0.3s;
|
|
22
|
-
}
|
|
23
|
-
#payButton:hover {
|
|
24
|
-
background-color: #357abd;
|
|
25
|
-
}
|
|
26
|
-
.cart-details {
|
|
27
|
-
font-size: 3rem;
|
|
28
|
-
font-weight: bold;
|
|
29
|
-
padding: 2rem;
|
|
30
|
-
display: flex;
|
|
31
|
-
justify-content: center;
|
|
32
|
-
}
|
|
33
|
-
.button-container {
|
|
34
|
-
width: 100%;
|
|
35
|
-
display: flex;
|
|
36
|
-
justify-content: center;
|
|
37
|
-
}
|
|
38
|
-
</style>
|
|
39
|
-
</head>
|
|
40
|
-
|
|
41
|
-
<body>
|
|
42
|
-
<div class="checkout-container">
|
|
43
|
-
<div class="cart-details">
|
|
44
|
-
<span>Total </span>
|
|
45
|
-
<div id="cart-total">$100</div>
|
|
46
|
-
</div>
|
|
47
|
-
<form id="payment-form">
|
|
48
|
-
<div id="tonder-checkout"></div>
|
|
49
|
-
</form>
|
|
50
|
-
<div class="button-container">
|
|
51
|
-
<button id="pay-button">Pagar</button>
|
|
52
|
-
</div>
|
|
53
|
-
</div>
|
|
54
|
-
</body>
|
|
55
|
-
<script src="https://js.skyflow.com/v1/index.js"></script>
|
|
56
|
-
<script src="https://openpay.s3.amazonaws.com/openpay.v1.min.js"></script>
|
|
57
|
-
<script src="https://openpay.s3.amazonaws.com/openpay-data.v1.min.js"></script>
|
|
58
|
-
<script src="./v1/bundle.min.js"></script>
|
|
59
|
-
<script>
|
|
60
|
-
const customStyles = {
|
|
61
|
-
inputStyles: {
|
|
62
|
-
base: {
|
|
63
|
-
border: "2px dashed #4a90e2",
|
|
64
|
-
padding: "12px 8px",
|
|
65
|
-
borderRadius: "8px",
|
|
66
|
-
color: "#333333",
|
|
67
|
-
backgroundColor: "#f0f0f0",
|
|
68
|
-
fontFamily: '"Arial", sans-serif',
|
|
69
|
-
fontSize: '14px',
|
|
70
|
-
'&::placeholder': {
|
|
71
|
-
color: "#888888",
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
cardIcon: {
|
|
75
|
-
position: 'absolute',
|
|
76
|
-
left: '6px',
|
|
77
|
-
bottom: 'calc(50% - 12px)',
|
|
78
|
-
},
|
|
79
|
-
complete: {
|
|
80
|
-
color: "#4caf50",
|
|
81
|
-
},
|
|
82
|
-
empty: {},
|
|
83
|
-
focus: {},
|
|
84
|
-
invalid: {
|
|
85
|
-
border: "1px solid #f44336",
|
|
86
|
-
},
|
|
87
|
-
global: {
|
|
88
|
-
'@import': 'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")',
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
labelStyles: {
|
|
92
|
-
base: {
|
|
93
|
-
fontSize: '14px',
|
|
94
|
-
fontWeight: 'bold',
|
|
95
|
-
fontFamily: '"Inter", sans-serif',
|
|
96
|
-
color: "#4a90e2",
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
errorTextStyles: {
|
|
100
|
-
base: {
|
|
101
|
-
fontSize: '12px',
|
|
102
|
-
fontWeight: '500',
|
|
103
|
-
color: "#e74c3c",
|
|
104
|
-
fontFamily: '"Inter", sans-serif',
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
labels: {
|
|
108
|
-
nameLabel: 'Nombre de la tarjeta',
|
|
109
|
-
cardLabel: 'Número de Tarjeta Personalizado',
|
|
110
|
-
cvvLabel: 'Código de Seguridad',
|
|
111
|
-
expiryMonthLabel: 'Mes de Expiración',
|
|
112
|
-
expiryYearLabel: 'Año de Expiración'
|
|
113
|
-
},
|
|
114
|
-
placeholders: {
|
|
115
|
-
cardPlaceholder: '0000 0000 0000 0000',
|
|
116
|
-
cvvPlaceholder: '123',
|
|
117
|
-
expiryMonthPlaceholder: 'MM',
|
|
118
|
-
expiryYearPlaceholder: 'AA'
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const checkoutData = {
|
|
123
|
-
customer: {
|
|
124
|
-
firstName: "Adrian",
|
|
125
|
-
lastName: "Martinez",
|
|
126
|
-
country: "Mexico",
|
|
127
|
-
address: "Pinos 507, Col El Tecuan",
|
|
128
|
-
city: "Durango",
|
|
129
|
-
state: "Durango",
|
|
130
|
-
postCode: "34105",
|
|
131
|
-
email: "adrian@email.com",
|
|
132
|
-
phone: "8161234567",
|
|
133
|
-
},
|
|
134
|
-
currency: 'mxn',
|
|
135
|
-
cart: {
|
|
136
|
-
total: 399,
|
|
137
|
-
items: [
|
|
138
|
-
{
|
|
139
|
-
description: "Black T-Shirt",
|
|
140
|
-
quantity: 1,
|
|
141
|
-
price_unit: 1,
|
|
142
|
-
discount: 0,
|
|
143
|
-
taxes: 0,
|
|
144
|
-
product_reference: 1,
|
|
145
|
-
name: "T-Shirt",
|
|
146
|
-
amount_total: 399,
|
|
147
|
-
},
|
|
148
|
-
]
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const apiKey = "00d17d61e9240c6e0611fbdb1558e636ed6389db";
|
|
153
|
-
const returnUrl = "http://web-sdk.tonderdemo.website/"
|
|
154
|
-
const inlineCheckout = new TonderSdk.InlineCheckout({
|
|
155
|
-
apiKey,
|
|
156
|
-
returnUrl,
|
|
157
|
-
styles: customStyles
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
inlineCheckout.injectCheckout();
|
|
161
|
-
|
|
162
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
163
|
-
const payButton = document.getElementById('pay-button');
|
|
164
|
-
payButton.addEventListener('click', async function() {
|
|
165
|
-
try {
|
|
166
|
-
payButton.textContent = 'Procesando...';
|
|
167
|
-
const response = await inlineCheckout.payment(checkoutData);
|
|
168
|
-
console.log(response)
|
|
169
|
-
alert('Pago realizado con éxito');
|
|
170
|
-
} catch (error) {
|
|
171
|
-
alert('Error al realizar el pago')
|
|
172
|
-
} finally {
|
|
173
|
-
payButton.textContent = 'Pagar';
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
</script>
|
|
178
|
-
</html>
|
package/success.html
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="es">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>Pago Completado</title>
|
|
7
|
-
<style>
|
|
8
|
-
body {
|
|
9
|
-
font-family: Arial, sans-serif;
|
|
10
|
-
display: flex;
|
|
11
|
-
justify-content: center;
|
|
12
|
-
align-items: center;
|
|
13
|
-
height: 100vh;
|
|
14
|
-
margin: 0;
|
|
15
|
-
color: #333;
|
|
16
|
-
}
|
|
17
|
-
</style>
|
|
18
|
-
</head>
|
|
19
|
-
<body>
|
|
20
|
-
<h1>Pago completado con éxito</h1>
|
|
21
|
-
</body>
|
|
22
|
-
</html>
|