@tonder.io/ionic-full-sdk 0.0.33-beta → 0.0.34-beta
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 +10 -1
- package/dist/classes/3dsHandler.d.ts +5 -1
- package/dist/classes/inlineCheckout.d.ts +4 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/classes/3dsHandler.ts +26 -8
- package/src/classes/inlineCheckout.ts +56 -33
- package/src/index-dev.js +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonder.io/ionic-full-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34-beta",
|
|
4
4
|
"description": "Tonder ionic full SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@tonder.io/ionic-lite-sdk": "^0.0.
|
|
13
|
+
"@tonder.io/ionic-lite-sdk": "^0.0.33-beta",
|
|
14
14
|
"crypto-js": "^4.1.1",
|
|
15
15
|
"skyflow-js": "^1.34.1"
|
|
16
16
|
},
|
|
@@ -65,6 +65,19 @@ export class ThreeDSHandler {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
saveCheckoutId(checkoutId: any) {
|
|
69
|
+
localStorage.setItem('checkout_id', JSON.stringify(checkoutId))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
removeCheckoutId() {
|
|
73
|
+
localStorage.removeItem("checkout_id")
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getCurrentCheckoutId() {
|
|
77
|
+
const checkout_id = localStorage.getItem("checkout_id")
|
|
78
|
+
return checkout_id ? JSON.parse(checkout_id):null; // TODO: JSON.parse de una string?
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
getUrlWithExpiration() {
|
|
69
82
|
const status = this.getStorageItem();
|
|
70
83
|
if(status) {
|
|
@@ -154,14 +167,13 @@ export class ThreeDSHandler {
|
|
|
154
167
|
|
|
155
168
|
handleSuccessTransaction(response: any) {
|
|
156
169
|
this.removeVerifyTransactionUrl();
|
|
157
|
-
console.log('Transacción autorizada
|
|
170
|
+
console.log('Transacción autorizada.');
|
|
158
171
|
return response;
|
|
159
172
|
}
|
|
160
173
|
|
|
161
174
|
handleDeclinedTransaction(response: any) {
|
|
162
175
|
this.removeVerifyTransactionUrl();
|
|
163
|
-
|
|
164
|
-
throw new Error("Transacción rechazada.");
|
|
176
|
+
return response;
|
|
165
177
|
}
|
|
166
178
|
|
|
167
179
|
// TODO: the method below needs to be tested with a real 3DS challenge
|
|
@@ -193,14 +205,16 @@ export class ThreeDSHandler {
|
|
|
193
205
|
await this.verifyTransactionStatus();
|
|
194
206
|
}
|
|
195
207
|
|
|
208
|
+
// TODO: This method could be removed
|
|
196
209
|
async handleTransactionResponse(response: any) {
|
|
197
210
|
const response_json = await response.json();
|
|
198
|
-
if (response_json.status === "Pending") {
|
|
211
|
+
if (response_json.status === "Pending" && response_json.redirect_post_url) {
|
|
199
212
|
return await this.handle3dsChallenge(response_json);
|
|
200
213
|
} else if (["Success", "Authorized"].includes(response_json.status)) {
|
|
201
|
-
return this.handleSuccessTransaction(
|
|
214
|
+
return this.handleSuccessTransaction(response_json);
|
|
202
215
|
} else {
|
|
203
|
-
|
|
216
|
+
this.handleDeclinedTransaction(response);
|
|
217
|
+
return response_json
|
|
204
218
|
}
|
|
205
219
|
}
|
|
206
220
|
|
|
@@ -221,17 +235,21 @@ export class ThreeDSHandler {
|
|
|
221
235
|
|
|
222
236
|
if (response.status !== 200) {
|
|
223
237
|
console.error('La verificación de la transacción falló.');
|
|
224
|
-
|
|
238
|
+
this.removeVerifyTransactionUrl();
|
|
239
|
+
return response
|
|
225
240
|
}
|
|
226
241
|
|
|
227
242
|
return await this.handleTransactionResponse(response);
|
|
228
243
|
} catch (error) {
|
|
229
244
|
console.error('Error al verificar la transacción:', error);
|
|
230
|
-
|
|
245
|
+
this.removeVerifyTransactionUrl();
|
|
231
246
|
}
|
|
232
247
|
} else {
|
|
233
248
|
console.log('No verify_transaction_status_url found');
|
|
234
249
|
}
|
|
235
250
|
}
|
|
236
251
|
|
|
252
|
+
setPayload = (payload: any) => {
|
|
253
|
+
this.payload = payload
|
|
254
|
+
}
|
|
237
255
|
}
|
|
@@ -215,6 +215,31 @@ export class InlineCheckout {
|
|
|
215
215
|
this.card = data?.card
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
async handle3dsRedirect(response: ErrorResponse | StartCheckoutResponse | false | undefined) {
|
|
219
|
+
const iframe = response && 'next_action' in response ? response?.next_action?.iframe_resources?.iframe:null
|
|
220
|
+
|
|
221
|
+
if (iframe) {
|
|
222
|
+
this.process3ds.loadIframe()!.then(() => {
|
|
223
|
+
//TODO: Check if this will be necessary on the frontend side
|
|
224
|
+
// after some the tests in production, since the 3DS process
|
|
225
|
+
// doesn't works properly on the sandbox environment
|
|
226
|
+
// setTimeout(() => {
|
|
227
|
+
// process3ds.verifyTransactionStatus();
|
|
228
|
+
// }, 10000);
|
|
229
|
+
this.process3ds.verifyTransactionStatus();
|
|
230
|
+
}).catch((error) => {
|
|
231
|
+
console.log('Error loading iframe:', error)
|
|
232
|
+
})
|
|
233
|
+
} else {
|
|
234
|
+
const redirectUrl = this.process3ds.getRedirectUrl()
|
|
235
|
+
if (redirectUrl) {
|
|
236
|
+
this.process3ds.redirectToChallenge()
|
|
237
|
+
} else {
|
|
238
|
+
return response;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
218
243
|
payment(data: any) {
|
|
219
244
|
return new Promise(async (resolve, reject) => {
|
|
220
245
|
try {
|
|
@@ -225,37 +250,12 @@ export class InlineCheckout {
|
|
|
225
250
|
this.#handleCurrency(data)
|
|
226
251
|
this.#handleCard(data)
|
|
227
252
|
const response: ErrorResponse | StartCheckoutResponse | false | undefined = await this.#checkout()
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
235
|
-
this.callBack(response);
|
|
236
|
-
if("next_action" in response) {
|
|
237
|
-
const iframe = response?.next_action?.iframe_resources?.iframe
|
|
238
|
-
if (iframe) {
|
|
239
|
-
process3ds.loadIframe()?.then(() => {
|
|
240
|
-
//TODO: Check if this will be necessary on the frontend side
|
|
241
|
-
// after some the tests in production, since the 3DS process
|
|
242
|
-
// doesn't works properly on the sandbox environment
|
|
243
|
-
// setTimeout(() => {
|
|
244
|
-
// process3ds.verifyTransactionStatus();
|
|
245
|
-
// }, 10000);
|
|
246
|
-
process3ds.verifyTransactionStatus();
|
|
247
|
-
}).catch((error) => {
|
|
248
|
-
console.log('Error loading iframe:', error)
|
|
249
|
-
})
|
|
250
|
-
} else {
|
|
251
|
-
const redirectUrl = process3ds.getRedirectUrl()
|
|
252
|
-
if (redirectUrl) {
|
|
253
|
-
process3ds.redirectToChallenge()
|
|
254
|
-
} else {
|
|
255
|
-
resolve(response);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
253
|
+
this.process3ds.setPayload(response)
|
|
254
|
+
this.process3ds.saveCheckoutId(response && 'checkout_id' in response ? response.checkout_id:"")
|
|
255
|
+
this.callBack(response);
|
|
256
|
+
const payload = await this.handle3dsRedirect(response)
|
|
257
|
+
if (payload) {
|
|
258
|
+
resolve(response);
|
|
259
259
|
}
|
|
260
260
|
} catch (error) {
|
|
261
261
|
reject(error);
|
|
@@ -358,7 +358,6 @@ export class InlineCheckout {
|
|
|
358
358
|
|
|
359
359
|
injectCheckout() {
|
|
360
360
|
if (this.injected) return
|
|
361
|
-
this.process3ds.verifyTransactionStatus()
|
|
362
361
|
const injectInterval = setInterval(() => {
|
|
363
362
|
const queryElement = document.querySelector(`#${this.containerId}`)
|
|
364
363
|
if (queryElement) {
|
|
@@ -370,6 +369,30 @@ export class InlineCheckout {
|
|
|
370
369
|
}, 500);
|
|
371
370
|
}
|
|
372
371
|
|
|
372
|
+
async verify3dsTransaction () {
|
|
373
|
+
const result3ds = await this.process3ds.verifyTransactionStatus()
|
|
374
|
+
const resultCheckout = await this.resumeCheckout(result3ds)
|
|
375
|
+
this.process3ds.setPayload(resultCheckout)
|
|
376
|
+
if (resultCheckout && 'is_route_finished' in resultCheckout && 'provider' in resultCheckout && resultCheckout.provider === 'tonder') {
|
|
377
|
+
return resultCheckout
|
|
378
|
+
}
|
|
379
|
+
return this.handle3dsRedirect(resultCheckout)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async resumeCheckout(response: any) {
|
|
383
|
+
if (["Failed", "Declined", "Cancelled"].includes(response?.status)) {
|
|
384
|
+
const routerItems = {
|
|
385
|
+
// TODO: Replace this with reponse.checkout_id
|
|
386
|
+
checkout_id: this.process3ds.getCurrentCheckoutId(),
|
|
387
|
+
};
|
|
388
|
+
const routerResponse = await this.liteCheckout.handleCheckoutRouter(
|
|
389
|
+
routerItems
|
|
390
|
+
);
|
|
391
|
+
return routerResponse
|
|
392
|
+
}
|
|
393
|
+
return response
|
|
394
|
+
}
|
|
395
|
+
|
|
373
396
|
loadCardsList (cards: Card[], token: string) {
|
|
374
397
|
if(this.cardsInjected) return;
|
|
375
398
|
const injectInterval = setInterval(() => {
|
|
@@ -701,7 +724,7 @@ export class InlineCheckout {
|
|
|
701
724
|
currency: this.currency
|
|
702
725
|
};
|
|
703
726
|
|
|
704
|
-
const jsonResponseRouter = await this.liteCheckout.
|
|
727
|
+
const jsonResponseRouter = await this.liteCheckout.handleCheckoutRouter(
|
|
705
728
|
routerItems
|
|
706
729
|
);
|
|
707
730
|
|
package/src/index-dev.js
CHANGED
|
@@ -102,7 +102,9 @@ const inlineCheckout = new InlineCheckout({
|
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
inlineCheckout.injectCheckout();
|
|
105
|
-
|
|
105
|
+
inlineCheckout.verify3dsTransaction().then(response => {
|
|
106
|
+
console.log('Verify 3ds response', response)
|
|
107
|
+
})
|
|
106
108
|
document.addEventListener('DOMContentLoaded', function() {
|
|
107
109
|
const payButton = document.getElementById('pay-button');
|
|
108
110
|
payButton.addEventListener('click', async function() {
|