tonder-web-sdk 1.14.0 → 1.15.2

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.14.0",
3
+ "version": "1.15.2",
4
4
  "description": "tonder sdk for integrations",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -4,10 +4,9 @@ export class ThreeDSHandler {
4
4
  apiKey,
5
5
  baseUrl,
6
6
  }) {
7
- this.baseUrl = baseUrl,
8
- this.apiKey = apiKey,
9
- this.payload = payload,
10
- this.isTransactionPending = false
7
+ this.baseUrl = baseUrl
8
+ this.apiKey = apiKey
9
+ this.payload = payload
11
10
  }
12
11
 
13
12
  saveVerifyTransactionUrl() {
@@ -61,12 +60,12 @@ export class ThreeDSHandler {
61
60
 
62
61
  loadIframe() {
63
62
  const iframe = this.payload?.next_action?.iframe_resources?.iframe
64
-
65
63
  if (iframe) {
66
64
  return new Promise((resolve, reject) => {
67
65
  const iframe = this.payload?.next_action?.iframe_resources?.iframe
68
66
 
69
67
  if (iframe) {
68
+ // TODO: This is not working for Azul
70
69
  this.saveVerifyTransactionUrl()
71
70
  const container = document.createElement('div')
72
71
  container.innerHTML = iframe
@@ -153,14 +152,11 @@ export class ThreeDSHandler {
153
152
  // Append the form to the body:
154
153
  document.body.appendChild(form);
155
154
  form.submit();
156
-
157
- await this.verifyTransactionStatus();
158
155
  }
159
156
 
160
- // TODO: This method could be removed
157
+ // TODO: This works for Azul
161
158
  async handleTransactionResponse(response) {
162
159
  const response_json = await response.json();
163
-
164
160
  // Azul property
165
161
  if (response_json.status === "Pending" && response_json.redirect_post_url) {
166
162
  return await this.handle3dsChallenge(response_json);
@@ -173,16 +169,7 @@ export class ThreeDSHandler {
173
169
  }
174
170
 
175
171
  async verifyTransactionStatus() {
176
- console.log('Verificando la transacción...');
177
-
178
- if (this.isTransactionPending) {
179
- console.log('La transacción ya está en proceso');
180
- return
181
- }
182
-
183
- this.isTransactionPending = true
184
172
  const verifyUrl = this.getUrlWithExpiration();
185
-
186
173
  if (verifyUrl) {
187
174
  const url = `${this.baseUrl}${verifyUrl}`;
188
175
  try {
@@ -208,8 +195,6 @@ export class ThreeDSHandler {
208
195
  } else {
209
196
  console.log('No verify_transaction_status_url found');
210
197
  }
211
-
212
- this.isTransactionPending = false
213
198
  }
214
199
 
215
200
  setPayload = (payload) => {
@@ -47,8 +47,9 @@ export class BaseInlineCheckout {
47
47
  const result3ds = await this.process3ds.verifyTransactionStatus();
48
48
  const resultCheckout = await this.#resumeCheckout(result3ds);
49
49
  this.process3ds.setPayload(resultCheckout);
50
+ const response = await this.#handle3dsRedirect(resultCheckout);
50
51
  globalLoader.remove();
51
- return this.#handle3dsRedirect(resultCheckout);
52
+ return response
52
53
  }
53
54
 
54
55
  /**
@@ -159,6 +160,7 @@ export class BaseInlineCheckout {
159
160
  amount: total,
160
161
  date: dateString,
161
162
  order_id: jsonResponseOrder.id,
163
+ customer_order_reference: this.order_reference ? this.order_reference : reference,
162
164
  };
163
165
  const jsonResponsePayment = await createPayment(
164
166
  this.baseUrl,
@@ -223,7 +225,7 @@ export class BaseInlineCheckout {
223
225
 
224
226
  async #resumeCheckout(response) {
225
227
  // Stop the routing process if the transaction is either hard declined or successful
226
- if (response?.decline?.error_type === "Hard") {
228
+ if (response?.decline?.error_type === "Hard" || !!response?.checkout?.is_route_finished) {
227
229
  return response;
228
230
  }
229
231
 
@@ -272,6 +274,7 @@ export class BaseInlineCheckout {
272
274
 
273
275
  #handleMetadata(data) {
274
276
  this.metadata = data?.metadata;
277
+ this.order_reference = data?.order_reference;
275
278
  }
276
279
 
277
280
  #handleCurrency(data) {
@@ -294,12 +297,15 @@ export class BaseInlineCheckout {
294
297
  if (iframe) {
295
298
  try {
296
299
  await this.process3ds.loadIframe();
297
- await this.process3ds.verifyTransactionStatus();
300
+ const res = await this.process3ds.verifyTransactionStatus();
301
+ return res;
298
302
  } catch (error) {
299
303
  console.log("Error loading iframe:", error);
300
304
  }
301
305
  } else if (threeDsChallenge) {
302
306
  await this.process3ds.handle3dsChallenge(threeDsChallenge);
307
+ const res = await this.process3ds.verifyTransactionStatus();
308
+ return res;
303
309
  } else {
304
310
  const redirectUrl = this.process3ds.getRedirectUrl();
305
311
  if (redirectUrl) {
package/src/index-dev.js CHANGED
@@ -98,11 +98,13 @@ const checkoutData = {
98
98
  // metadata: {
99
99
  // order_id: 123456
100
100
  // }
101
+ // Reference from the merchant
102
+ order_reference: "ORD-123456"
101
103
  };
102
104
 
103
105
  // localhost
104
106
  const apiKey = "11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27";
105
- const returnUrl = "http://127.0.0.1:8080/";
107
+ const returnUrl = "http://localhost:8080/";
106
108
  // stage
107
109
  // const apiKey = "8365683bdc33dd6d50fe2397188d79f1a6765852";
108
110