tonder-web-sdk 1.8.0 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tonder-web-sdk",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "tonder sdk for integrations",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -294,6 +294,7 @@ export class InlineCheckout {
294
294
  this.apiKeyTonder,
295
295
  this.abortController.signal,
296
296
  this.customStyles,
297
+ this.collectorIds
297
298
  );
298
299
  setTimeout(() => {
299
300
  this.#removeGlobalLoader()
@@ -338,8 +339,14 @@ export class InlineCheckout {
338
339
  const { openpay_keys, reference, business } = this.merchantData
339
340
  const total = Number(this.cartTotal)
340
341
 
341
- const cardTokens = await this.#getCardTokens();
342
-
342
+ let cardTokens = null;
343
+ if(this.radioChecked === "new"){
344
+ cardTokens = await this.#getCardTokens();
345
+ }else{
346
+ cardTokens = {
347
+ skyflow_id: this.radioChecked
348
+ }
349
+ }
343
350
  try {
344
351
  let deviceSessionIdTonder;
345
352
  if (openpay_keys.merchant_id && openpay_keys.public_key) {
@@ -52,6 +52,15 @@ export async function initSkyflow(
52
52
  max: 70,
53
53
  },
54
54
  };
55
+ const regexEmpty = RegExp("^(?!\s*$).+");
56
+
57
+ const regexMatchRule = {
58
+ type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
59
+ params: {
60
+ regex: regexEmpty,
61
+ error: "El campo es requerido" // Optional, default error is 'VALIDATION FAILED'.
62
+ }
63
+ }
55
64
 
56
65
  const cardHolderNameElement = await collectContainer.create({
57
66
  table: "cards",
@@ -60,10 +69,15 @@ export async function initSkyflow(
60
69
  label: collectStylesOptions.labels?.nameLabel,
61
70
  placeholder: collectStylesOptions.placeholders?.namePlaceholder,
62
71
  type: Skyflow.ElementType.CARDHOLDER_NAME,
63
- validations: [lengthMatchRule],
72
+ validations: [lengthMatchRule, regexMatchRule],
64
73
  });
65
74
 
66
- cardHolderNameElement.setError('Inválido')
75
+ handleSkyflowElementEvents(
76
+ cardHolderNameElement,
77
+ collectorIds.holderName,
78
+ "errorCardHolderIdTonder",
79
+ "titular de la tarjeta"
80
+ );
67
81
 
68
82
  // Create collect elements.
69
83
  const cardNumberElement = await collectContainer.create({
@@ -77,9 +91,16 @@ export async function initSkyflow(
77
91
  label: collectStylesOptions.labels?.cardLabel,
78
92
  placeholder: collectStylesOptions.placeholders?.cardPlaceholder,
79
93
  type: Skyflow.ElementType.CARD_NUMBER,
94
+ validations: [regexMatchRule],
80
95
  });
81
96
 
82
- cardNumberElement.setError('Inválido')
97
+ handleSkyflowElementEvents(
98
+ cardNumberElement,
99
+ collectorIds.cardNumber,
100
+ "errorCardNumberIdTonder",
101
+ "número de tarjeta"
102
+ );
103
+
83
104
 
84
105
  const cvvElement = await collectContainer.create({
85
106
  table: "cards",
@@ -88,9 +109,14 @@ export async function initSkyflow(
88
109
  label: collectStylesOptions.labels?.cvvLabel,
89
110
  placeholder: collectStylesOptions.placeholders?.cvvPlaceholder,
90
111
  type: Skyflow.ElementType.CVV,
112
+ validations: [regexMatchRule],
91
113
  });
92
114
 
93
- cvvElement.setError('Inválido')
115
+ handleSkyflowElementEvents(
116
+ cvvElement,
117
+ collectorIds.cvv,
118
+ "errorCvvIdTonder"
119
+ );
94
120
 
95
121
  const expiryMonthElement = await collectContainer.create({
96
122
  table: "cards",
@@ -99,9 +125,14 @@ export async function initSkyflow(
99
125
  label: collectStylesOptions.labels?.expiryDateLabel,
100
126
  placeholder: collectStylesOptions.placeholders?.expiryMonthPlaceholder,
101
127
  type: Skyflow.ElementType.EXPIRATION_MONTH,
128
+ validations: [regexMatchRule],
102
129
  });
103
130
 
104
- expiryMonthElement.setError('Inválido')
131
+ handleSkyflowElementEvents(
132
+ expiryMonthElement,
133
+ collectorIds.expirationMonth,
134
+ "errorExpiryMonthIdTonder"
135
+ );
105
136
 
106
137
  const expiryYearElement = await collectContainer.create({
107
138
  table: "cards",
@@ -110,9 +141,14 @@ export async function initSkyflow(
110
141
  label: "",
111
142
  placeholder: collectStylesOptions.placeholders?.expiryYearPlaceholder,
112
143
  type: Skyflow.ElementType.EXPIRATION_YEAR,
144
+ validations: [regexMatchRule],
113
145
  });
114
146
 
115
- expiryYearElement.setError('Inválido')
147
+ handleSkyflowElementEvents(
148
+ expiryYearElement,
149
+ collectorIds.expirationYear,
150
+ "errorExpiryYearIdTonder"
151
+ );
116
152
 
117
153
  await mountElements(
118
154
  cardNumberElement,
@@ -147,3 +183,30 @@ async function mountElements(
147
183
  expiryYearElement.mount("#collectExpirationYear");
148
184
  cardHolderNameElement.mount("#collectCardholderName");
149
185
  }
186
+
187
+
188
+ function handleSkyflowElementEvents(element, elementId, errorElementId, fieldMessage= "", requiredMessage = "El campo es requerido", invalidMessage= "El campo es inválido") {
189
+ if ("on" in element) {
190
+ element.on(Skyflow.EventName.CHANGE, (state) => {
191
+ let errorElement = document.getElementById(errorElementId);
192
+ if (errorElement && state.isValid && !state.isEmpty) {
193
+ errorElement.remove();
194
+ }
195
+ });
196
+
197
+ 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
+ if (!state.isValid) {
204
+ let errorLabel = document.createElement("div");
205
+ errorLabel.classList.add("error-custom-inputs-tonder");
206
+ errorLabel.id = errorElementId;
207
+ errorLabel.textContent = state.isEmpty ? requiredMessage : fieldMessage != "" ?`El campo ${fieldMessage} es inválido`: invalidMessage;
208
+ container?.appendChild(errorLabel);
209
+ }
210
+ });
211
+ }
212
+ }
@@ -55,10 +55,12 @@ export const cardTemplate = `
55
55
  }
56
56
 
57
57
  .expiration-year {
58
+ position: relative !important;
58
59
  padding-top: 25px !important;
59
60
  }
60
61
 
61
62
  .empty-div {
63
+ position: relative;
62
64
  height: 80px !important;
63
65
  margin-top: 2px;
64
66
  margin-bottom: 4px;
@@ -281,6 +283,26 @@ export const cardTemplate = `
281
283
  transition-duration: 150ms;
282
284
  opacity: 10;
283
285
  }
286
+
287
+ .error-custom-inputs-tonder {
288
+ background-color: white;
289
+ position: absolute;
290
+ left: 0px;
291
+ bottom: -4px;
292
+ width: 100%;
293
+ font-size: 12px;
294
+ color: red;
295
+ }
296
+
297
+ .expiration-year .error-custom-inputs-tonder {
298
+ background-color: white;
299
+ position: absolute;
300
+ left: 0px;
301
+ bottom: 3px;
302
+ width: 100%;
303
+ font-size: 12px;
304
+ color: red;
305
+ }
284
306
  </style>
285
307
  `
286
308
 
package/src/index-dev.js CHANGED
@@ -91,9 +91,9 @@ const checkoutData = {
91
91
  ]
92
92
  },
93
93
  // card: { "skyflow_id": "53ca875c-16fd-4395-8ac9-c756613dbaf9" },
94
- metadata: {
95
- order_id: 123456
96
- }
94
+ // metadata: {
95
+ // order_id: 123456
96
+ // }
97
97
  };
98
98
 
99
99
  // localhost
@@ -110,7 +110,7 @@ const inlineCheckout = new InlineCheckout({
110
110
  successUrl,
111
111
  styles: customStyles
112
112
  });
113
-
113
+ inlineCheckout.setCustomerEmail(checkoutData.customer.email)
114
114
  inlineCheckout.injectCheckout();
115
115
 
116
116
  document.addEventListener('DOMContentLoaded', function() {