@tonder.io/ionic-full-sdk 0.0.24-beta → 0.0.26-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/index.js.example CHANGED
@@ -1,50 +1,50 @@
1
- import { Checkout } from './classes/checkout'
2
- export {
3
- Checkout,
4
- }
5
-
6
- const config = {
7
- url: "http://localhost:8081/#/",
8
- apiKey: "e0f89d5328398b93634f56ba06c9474ec9388d5e",
9
- type: "payment",
10
- backgroundColor: "#F34616",
11
- color: "#F3F7F6"
12
- }
13
- const tonderCheckout = new Checkout(config)
14
- const params = {
15
- shippingCost: "129.99",
16
- email: "fuentesc91@gmail.com"
17
- }
18
- tonderCheckout.setOrder(params)
19
-
20
- let products = {products: [
21
- {
22
- name: 'first product',
23
- price_unit: 120.99,
24
- quantity: 1
25
- },
26
- {
27
- name: 'second product',
28
- price_unit: 12.99,
29
- }
30
- ]}
31
-
32
- tonderCheckout.setOrder(products)
33
-
34
- products = {products: [
35
- {
36
- name: 'first product',
37
- price_unit: 120.99,
38
- quantity: 3
39
- },
40
- {
41
- name: 'second product',
42
- price_unit: 12.99,
43
- }
44
- ]}
45
-
46
- tonderCheckout.setOrder(products)
47
-
48
- console.log(tonderCheckout.getUrlParams())
49
-
1
+ import { Checkout } from './classes/checkout'
2
+ export {
3
+ Checkout,
4
+ }
5
+
6
+ const config = {
7
+ url: "http://localhost:8081/#/",
8
+ apiKey: "e0f89d5328398b93634f56ba06c9474ec9388d5e",
9
+ type: "payment",
10
+ backgroundColor: "#F34616",
11
+ color: "#F3F7F6"
12
+ }
13
+ const tonderCheckout = new Checkout(config)
14
+ const params = {
15
+ shippingCost: "129.99",
16
+ email: "fuentesc91@gmail.com"
17
+ }
18
+ tonderCheckout.setOrder(params)
19
+
20
+ let products = {products: [
21
+ {
22
+ name: 'first product',
23
+ price_unit: 120.99,
24
+ quantity: 1
25
+ },
26
+ {
27
+ name: 'second product',
28
+ price_unit: 12.99,
29
+ }
30
+ ]}
31
+
32
+ tonderCheckout.setOrder(products)
33
+
34
+ products = {products: [
35
+ {
36
+ name: 'first product',
37
+ price_unit: 120.99,
38
+ quantity: 3
39
+ },
40
+ {
41
+ name: 'second product',
42
+ price_unit: 12.99,
43
+ }
44
+ ]}
45
+
46
+ tonderCheckout.setOrder(products)
47
+
48
+ console.log(tonderCheckout.getUrlParams())
49
+
50
50
  tonderCheckout.mountButton({ buttonText: 'Proceder al pago' })
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "@tonder.io/ionic-full-sdk",
3
- "version": "0.0.24-beta",
4
- "description": "Tonder ionic full SDK",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.js",
7
- "scripts": {
8
- "build": "tsc -noEmit && rollup --config"
9
- },
10
- "author": "",
11
- "license": "ISC",
12
- "dependencies": {
13
- "@tonder.io/ionic-lite-sdk": "^0.0.29-beta",
14
- "crypto-js": "^4.1.1",
15
- "skyflow-js": "^1.34.1"
16
- },
17
- "devDependencies": {
18
- "@rollup/plugin-terser": "^0.4.4",
19
- "@rollup/plugin-typescript": "^11.1.6",
20
- "@types/crypto-js": "^4.2.2",
21
- "@types/node": "^20.11.5",
22
- "cypress": "^13.6.2",
23
- "rollup": "^4.9.6",
24
- "ts-loader": "^9.5.1",
25
- "typescript": "^5.3.3"
26
- }
27
- }
1
+ {
2
+ "name": "@tonder.io/ionic-full-sdk",
3
+ "version": "0.0.26-beta",
4
+ "description": "Tonder ionic full SDK",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.js",
7
+ "scripts": {
8
+ "build": "tsc -noEmit && rollup --config"
9
+ },
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "@tonder.io/ionic-lite-sdk": "^0.0.29-beta",
14
+ "crypto-js": "^4.1.1",
15
+ "skyflow-js": "^1.34.1"
16
+ },
17
+ "devDependencies": {
18
+ "@rollup/plugin-terser": "^0.4.4",
19
+ "@rollup/plugin-typescript": "^11.1.6",
20
+ "@types/crypto-js": "^4.2.2",
21
+ "@types/node": "^20.11.5",
22
+ "cypress": "^13.6.2",
23
+ "rollup": "^4.9.6",
24
+ "ts-loader": "^9.5.1",
25
+ "typescript": "^5.3.3"
26
+ }
27
+ }
package/rollup.config.js CHANGED
@@ -1,15 +1,15 @@
1
- const typescript = require('@rollup/plugin-typescript');
2
- const terser = require('@rollup/plugin-terser');
3
-
4
- module.exports = {
5
- input: './src/index.ts',
6
- output: {
7
- dir: 'dist',
8
- format: 'es',
9
- plugins: [terser()]
10
- },
11
- plugins: [
12
- typescript()
13
- ],
14
- external: ["skyflow-js", "crypto-js", "@tonder.io/ionic-lite-sdk"]
1
+ const typescript = require('@rollup/plugin-typescript');
2
+ const terser = require('@rollup/plugin-terser');
3
+
4
+ module.exports = {
5
+ input: './src/index.ts',
6
+ output: {
7
+ dir: 'dist',
8
+ format: 'es',
9
+ plugins: [terser()]
10
+ },
11
+ plugins: [
12
+ typescript()
13
+ ],
14
+ external: ["skyflow-js", "crypto-js", "@tonder.io/ionic-lite-sdk"]
15
15
  };
@@ -1,237 +1,237 @@
1
- type ThreeDSHandlerContructor = {
2
- payload?: any,
3
- apiKey?: string,
4
- baseUrl?: string,
5
- successUrl?: Location | string
6
- }
7
-
8
- export class ThreeDSHandler {
9
-
10
- baseUrl?: string
11
- apiKey?: string
12
- payload?: any
13
- successUrl?: Location | string
14
- localStorageKey: string = "verify_transaction_status_url"
15
-
16
- constructor({
17
- payload = null,
18
- apiKey,
19
- baseUrl,
20
- successUrl
21
- }: ThreeDSHandlerContructor) {
22
- this.baseUrl = baseUrl,
23
- this.apiKey = apiKey,
24
- this.payload = payload,
25
- this.successUrl = successUrl
26
- }
27
-
28
- setStorageItem (data: any) {
29
- return localStorage.setItem(this.localStorageKey, JSON.stringify(data))
30
- }
31
-
32
- getStorageItem () {
33
- return localStorage.getItem(this.localStorageKey)
34
- }
35
-
36
- removeStorageItem () {
37
- return localStorage.removeItem(this.localStorageKey)
38
- }
39
-
40
- saveVerifyTransactionUrl() {
41
- const url = this.payload?.next_action?.redirect_to_url?.verify_transaction_status_url
42
- if (url) {
43
- this.saveUrlWithExpiration(url)
44
- } else {
45
- const url = this.payload?.next_action?.iframe_resources?.verify_transaction_status_url
46
- if (url) {
47
- this.saveUrlWithExpiration(url)
48
- } else {
49
- console.log('No verify_transaction_status_url found');
50
- }
51
- }
52
- }
53
-
54
- saveUrlWithExpiration(url: string) {
55
- try {
56
- const now = new Date()
57
- const item = {
58
- url: url,
59
- // Expires after 20 minutes
60
- expires: now.getTime() + 20 * 60 * 1000
61
- }
62
- this.setStorageItem(item)
63
- } catch (error) {
64
- console.log('error: ', error)
65
- }
66
- }
67
-
68
- getUrlWithExpiration() {
69
- const status = this.getStorageItem();
70
- if(status) {
71
- const item = JSON.parse(status)
72
- if (!item) return
73
- const now = new Date()
74
- if (now.getTime() > item.expires) {
75
- this.removeVerifyTransactionUrl()
76
- return null
77
- } else {
78
- return item.url
79
- }
80
- } else {
81
- return null
82
- }
83
- }
84
-
85
- removeVerifyTransactionUrl() {
86
- return this.removeStorageItem()
87
- }
88
-
89
- getVerifyTransactionUrl() {
90
- return this.getStorageItem()
91
- }
92
-
93
- loadIframe() {
94
- const iframe = this.payload?.next_action?.iframe_resources?.iframe
95
-
96
- if (iframe) {
97
- return new Promise((resolve, reject) => {
98
- const iframe = this.payload?.next_action?.iframe_resources?.iframe
99
-
100
- if (iframe) {
101
- this.saveVerifyTransactionUrl()
102
- const container = document.createElement('div')
103
- container.innerHTML = iframe
104
- document.body.appendChild(container)
105
-
106
- // Create and append the script tag manually
107
- const script = document.createElement('script')
108
- script.textContent = 'document.getElementById("tdsMmethodForm").submit();'
109
- container.appendChild(script)
110
-
111
- // Resolve the promise when the iframe is loaded
112
- const iframeElement = document.getElementById('tdsMmethodTgtFrame')
113
- if(iframeElement) {
114
- iframeElement.onload = () => resolve(true)
115
- } else {
116
- console.log('No redirection found');
117
- reject(false)
118
- }
119
- } else {
120
- console.log('No redirection found');
121
- reject(false)
122
- }
123
- })
124
- }
125
- }
126
-
127
- getRedirectUrl() {
128
- return this.payload?.next_action?.redirect_to_url?.url
129
- }
130
-
131
- redirectToChallenge() {
132
- const url = this.getRedirectUrl()
133
- if (url) {
134
- this.saveVerifyTransactionUrl()
135
- window.location = url;
136
- } else {
137
- console.log('No redirection found');
138
- }
139
- }
140
-
141
- // Returns an object
142
- // https://example.com/?name=John&age=30&city=NewYork
143
- // { name: "John", age: "30", city: "NewYork" }
144
- getURLParameters() {
145
- const parameters: any = {};
146
- const urlParams: any = new URLSearchParams(window.location.search);
147
-
148
- for (const [key, value] of urlParams) {
149
- parameters[key] = value;
150
- }
151
-
152
- return parameters;
153
- }
154
-
155
- handleSuccessTransaction(response: any) {
156
- this.removeVerifyTransactionUrl();
157
- console.log('Transacción autorizada exitosamente.');
158
- return response;
159
- }
160
-
161
- handleDeclinedTransaction(response: any) {
162
- this.removeVerifyTransactionUrl();
163
- console.log('Transacción rechazada.');
164
- throw new Error("Transacción rechazada.");
165
- }
166
-
167
- // TODO: the method below needs to be tested with a real 3DS challenge
168
- // since we couldn't get a test card that works with this feature
169
- async handle3dsChallenge(response_json: any) {
170
- // Create the form element:
171
- const form = document.createElement('form');
172
- form.name = 'frm';
173
- form.method = 'POST';
174
- form.action = response_json.redirect_post_url;
175
-
176
- // Add hidden fields:
177
- const creqInput = document.createElement('input');
178
- creqInput.type = 'hidden';
179
- creqInput.name = response_json.creq;
180
- creqInput.value = response_json.creq;
181
- form.appendChild(creqInput);
182
-
183
- const termUrlInput = document.createElement('input');
184
- termUrlInput.type = 'hidden';
185
- termUrlInput.name = response_json.term_url;
186
- termUrlInput.value = response_json.TermUrl;
187
- form.appendChild(termUrlInput);
188
-
189
- // Append the form to the body:
190
- document.body.appendChild(form);
191
- form.submit();
192
-
193
- await this.verifyTransactionStatus();
194
- }
195
-
196
- async handleTransactionResponse(response: any) {
197
- const response_json = await response.json();
198
- if (response_json.status === "Pending") {
199
- return await this.handle3dsChallenge(response_json);
200
- } else if (["Success", "Authorized"].includes(response_json.status)) {
201
- return this.handleSuccessTransaction(response);
202
- } else {
203
- return this.handleDeclinedTransaction(response);
204
- }
205
- }
206
-
207
- async verifyTransactionStatus() {
208
- const verifyUrl = this.getUrlWithExpiration();
209
-
210
- if (verifyUrl) {
211
- const url = `${this.baseUrl}${verifyUrl}`;
212
- try {
213
- const response = await fetch(url, {
214
- method: "GET",
215
- headers: {
216
- "Content-Type": "application/json",
217
- Authorization: `Token ${this.apiKey}`,
218
- },
219
- // body: JSON.stringify(data),
220
- });
221
-
222
- if (response.status !== 200) {
223
- console.error('La verificación de la transacción falló.');
224
- return
225
- }
226
-
227
- return await this.handleTransactionResponse(response);
228
- } catch (error) {
229
- console.error('Error al verificar la transacción:', error);
230
- return error;
231
- }
232
- } else {
233
- console.log('No verify_transaction_status_url found');
234
- }
235
- }
236
-
237
- }
1
+ type ThreeDSHandlerContructor = {
2
+ payload?: any,
3
+ apiKey?: string,
4
+ baseUrl?: string,
5
+ successUrl?: Location | string
6
+ }
7
+
8
+ export class ThreeDSHandler {
9
+
10
+ baseUrl?: string
11
+ apiKey?: string
12
+ payload?: any
13
+ successUrl?: Location | string
14
+ localStorageKey: string = "verify_transaction_status_url"
15
+
16
+ constructor({
17
+ payload = null,
18
+ apiKey,
19
+ baseUrl,
20
+ successUrl
21
+ }: ThreeDSHandlerContructor) {
22
+ this.baseUrl = baseUrl,
23
+ this.apiKey = apiKey,
24
+ this.payload = payload,
25
+ this.successUrl = successUrl
26
+ }
27
+
28
+ setStorageItem (data: any) {
29
+ return localStorage.setItem(this.localStorageKey, JSON.stringify(data))
30
+ }
31
+
32
+ getStorageItem () {
33
+ return localStorage.getItem(this.localStorageKey)
34
+ }
35
+
36
+ removeStorageItem () {
37
+ return localStorage.removeItem(this.localStorageKey)
38
+ }
39
+
40
+ saveVerifyTransactionUrl() {
41
+ const url = this.payload?.next_action?.redirect_to_url?.verify_transaction_status_url
42
+ if (url) {
43
+ this.saveUrlWithExpiration(url)
44
+ } else {
45
+ const url = this.payload?.next_action?.iframe_resources?.verify_transaction_status_url
46
+ if (url) {
47
+ this.saveUrlWithExpiration(url)
48
+ } else {
49
+ console.log('No verify_transaction_status_url found');
50
+ }
51
+ }
52
+ }
53
+
54
+ saveUrlWithExpiration(url: string) {
55
+ try {
56
+ const now = new Date()
57
+ const item = {
58
+ url: url,
59
+ // Expires after 20 minutes
60
+ expires: now.getTime() + 20 * 60 * 1000
61
+ }
62
+ this.setStorageItem(item)
63
+ } catch (error) {
64
+ console.log('error: ', error)
65
+ }
66
+ }
67
+
68
+ getUrlWithExpiration() {
69
+ const status = this.getStorageItem();
70
+ if(status) {
71
+ const item = JSON.parse(status)
72
+ if (!item) return
73
+ const now = new Date()
74
+ if (now.getTime() > item.expires) {
75
+ this.removeVerifyTransactionUrl()
76
+ return null
77
+ } else {
78
+ return item.url
79
+ }
80
+ } else {
81
+ return null
82
+ }
83
+ }
84
+
85
+ removeVerifyTransactionUrl() {
86
+ return this.removeStorageItem()
87
+ }
88
+
89
+ getVerifyTransactionUrl() {
90
+ return this.getStorageItem()
91
+ }
92
+
93
+ loadIframe() {
94
+ const iframe = this.payload?.next_action?.iframe_resources?.iframe
95
+
96
+ if (iframe) {
97
+ return new Promise((resolve, reject) => {
98
+ const iframe = this.payload?.next_action?.iframe_resources?.iframe
99
+
100
+ if (iframe) {
101
+ this.saveVerifyTransactionUrl()
102
+ const container = document.createElement('div')
103
+ container.innerHTML = iframe
104
+ document.body.appendChild(container)
105
+
106
+ // Create and append the script tag manually
107
+ const script = document.createElement('script')
108
+ script.textContent = 'document.getElementById("tdsMmethodForm").submit();'
109
+ container.appendChild(script)
110
+
111
+ // Resolve the promise when the iframe is loaded
112
+ const iframeElement = document.getElementById('tdsMmethodTgtFrame')
113
+ if(iframeElement) {
114
+ iframeElement.onload = () => resolve(true)
115
+ } else {
116
+ console.log('No redirection found');
117
+ reject(false)
118
+ }
119
+ } else {
120
+ console.log('No redirection found');
121
+ reject(false)
122
+ }
123
+ })
124
+ }
125
+ }
126
+
127
+ getRedirectUrl() {
128
+ return this.payload?.next_action?.redirect_to_url?.url
129
+ }
130
+
131
+ redirectToChallenge() {
132
+ const url = this.getRedirectUrl()
133
+ if (url) {
134
+ this.saveVerifyTransactionUrl()
135
+ window.location = url;
136
+ } else {
137
+ console.log('No redirection found');
138
+ }
139
+ }
140
+
141
+ // Returns an object
142
+ // https://example.com/?name=John&age=30&city=NewYork
143
+ // { name: "John", age: "30", city: "NewYork" }
144
+ getURLParameters() {
145
+ const parameters: any = {};
146
+ const urlParams: any = new URLSearchParams(window.location.search);
147
+
148
+ for (const [key, value] of urlParams) {
149
+ parameters[key] = value;
150
+ }
151
+
152
+ return parameters;
153
+ }
154
+
155
+ handleSuccessTransaction(response: any) {
156
+ this.removeVerifyTransactionUrl();
157
+ console.log('Transacción autorizada exitosamente.');
158
+ return response;
159
+ }
160
+
161
+ handleDeclinedTransaction(response: any) {
162
+ this.removeVerifyTransactionUrl();
163
+ console.log('Transacción rechazada.');
164
+ throw new Error("Transacción rechazada.");
165
+ }
166
+
167
+ // TODO: the method below needs to be tested with a real 3DS challenge
168
+ // since we couldn't get a test card that works with this feature
169
+ async handle3dsChallenge(response_json: any) {
170
+ // Create the form element:
171
+ const form = document.createElement('form');
172
+ form.name = 'frm';
173
+ form.method = 'POST';
174
+ form.action = response_json.redirect_post_url;
175
+
176
+ // Add hidden fields:
177
+ const creqInput = document.createElement('input');
178
+ creqInput.type = 'hidden';
179
+ creqInput.name = response_json.creq;
180
+ creqInput.value = response_json.creq;
181
+ form.appendChild(creqInput);
182
+
183
+ const termUrlInput = document.createElement('input');
184
+ termUrlInput.type = 'hidden';
185
+ termUrlInput.name = response_json.term_url;
186
+ termUrlInput.value = response_json.TermUrl;
187
+ form.appendChild(termUrlInput);
188
+
189
+ // Append the form to the body:
190
+ document.body.appendChild(form);
191
+ form.submit();
192
+
193
+ await this.verifyTransactionStatus();
194
+ }
195
+
196
+ async handleTransactionResponse(response: any) {
197
+ const response_json = await response.json();
198
+ if (response_json.status === "Pending") {
199
+ return await this.handle3dsChallenge(response_json);
200
+ } else if (["Success", "Authorized"].includes(response_json.status)) {
201
+ return this.handleSuccessTransaction(response);
202
+ } else {
203
+ return this.handleDeclinedTransaction(response);
204
+ }
205
+ }
206
+
207
+ async verifyTransactionStatus() {
208
+ const verifyUrl = this.getUrlWithExpiration();
209
+
210
+ if (verifyUrl) {
211
+ const url = `${this.baseUrl}${verifyUrl}`;
212
+ try {
213
+ const response = await fetch(url, {
214
+ method: "GET",
215
+ headers: {
216
+ "Content-Type": "application/json",
217
+ Authorization: `Token ${this.apiKey}`,
218
+ },
219
+ // body: JSON.stringify(data),
220
+ });
221
+
222
+ if (response.status !== 200) {
223
+ console.error('La verificación de la transacción falló.');
224
+ return
225
+ }
226
+
227
+ return await this.handleTransactionResponse(response);
228
+ } catch (error) {
229
+ console.error('Error al verificar la transacción:', error);
230
+ return error;
231
+ }
232
+ } else {
233
+ console.log('No verify_transaction_status_url found');
234
+ }
235
+ }
236
+
237
+ }