@tonder.io/ionic-lite-sdk 0.0.35-beta.8 → 0.0.37-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.
Files changed (83) hide show
  1. package/.gitlab-ci.yml +28 -28
  2. package/README.md +532 -202
  3. package/dist/classes/BaseInlineCheckout.d.ts +21 -19
  4. package/dist/classes/errorResponse.d.ts +1 -1
  5. package/dist/classes/liteCheckout.d.ts +15 -43
  6. package/dist/data/api.d.ts +1 -1
  7. package/dist/data/businessApi.d.ts +1 -1
  8. package/dist/data/cardApi.d.ts +1 -1
  9. package/dist/data/checkoutApi.d.ts +2 -1
  10. package/dist/data/customerApi.d.ts +1 -1
  11. package/dist/data/paymentMethodApi.d.ts +2 -2
  12. package/dist/helpers/skyflow.d.ts +1 -1
  13. package/dist/index.d.ts +2 -1
  14. package/dist/index.js +1 -1
  15. package/dist/types/card.d.ts +1 -0
  16. package/dist/types/checkout.d.ts +7 -1
  17. package/dist/types/commons.d.ts +8 -3
  18. package/dist/types/customer.d.ts +10 -0
  19. package/{src → dist}/types/liteInlineCheckout.d.ts +33 -73
  20. package/dist/types/responses.d.ts +3 -0
  21. package/jest.config.ts +14 -14
  22. package/package.json +41 -38
  23. package/rollup.config.js +16 -16
  24. package/src/classes/3dsHandler.ts +237 -237
  25. package/src/classes/BaseInlineCheckout.ts +385 -356
  26. package/src/classes/errorResponse.ts +16 -16
  27. package/src/classes/liteCheckout.ts +588 -598
  28. package/src/data/api.ts +20 -20
  29. package/src/data/businessApi.ts +18 -18
  30. package/src/data/cardApi.ts +85 -89
  31. package/src/data/checkoutApi.ts +84 -87
  32. package/src/data/customerApi.ts +31 -31
  33. package/src/data/openPayApi.ts +12 -12
  34. package/src/data/paymentMethodApi.ts +37 -37
  35. package/src/data/skyflowApi.ts +20 -20
  36. package/src/helpers/constants.ts +63 -63
  37. package/src/helpers/mercadopago.ts +15 -15
  38. package/src/helpers/skyflow.ts +91 -91
  39. package/src/helpers/utils.ts +120 -120
  40. package/src/helpers/validations.ts +55 -55
  41. package/src/index.ts +12 -10
  42. package/src/shared/catalog/paymentMethodsCatalog.ts +247 -247
  43. package/src/shared/constants/messages.ts +10 -10
  44. package/src/shared/constants/paymentMethodAPM.ts +63 -63
  45. package/src/shared/constants/tonderUrl.ts +8 -8
  46. package/src/types/card.ts +35 -34
  47. package/src/types/checkout.ts +123 -117
  48. package/src/types/commons.ts +130 -125
  49. package/src/types/customer.ts +22 -12
  50. package/src/types/liteInlineCheckout.ts +216 -0
  51. package/src/types/paymentMethod.ts +23 -23
  52. package/src/types/requests.ts +114 -114
  53. package/src/types/responses.ts +193 -189
  54. package/src/types/skyflow.ts +17 -17
  55. package/src/types/transaction.ts +101 -101
  56. package/src/types/validations.d.ts +11 -11
  57. package/tests/classes/liteCheckout.test.ts +57 -57
  58. package/tests/methods/createOrder.test.ts +141 -142
  59. package/tests/methods/createPayment.test.ts +121 -122
  60. package/tests/methods/customerRegister.test.ts +118 -119
  61. package/tests/methods/getBusiness.test.ts +114 -115
  62. package/tests/methods/getCustomerCards.test.ts +112 -113
  63. package/tests/methods/registerCustomerCard.test.ts +117 -117
  64. package/tests/methods/startCheckoutRouter.test.ts +119 -119
  65. package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
  66. package/tests/utils/defaultMock.ts +21 -21
  67. package/tests/utils/mockClasses.ts +659 -659
  68. package/tsconfig.json +18 -18
  69. package/types/classes/liteCheckout.d.ts +29 -0
  70. package/types/classes/liteCheckout.js +225 -0
  71. package/types/classes/liteCheckout.js.map +1 -0
  72. package/types/helpers/utils.d.ts +3 -0
  73. package/types/helpers/utils.js +27 -0
  74. package/types/helpers/utils.js.map +1 -0
  75. package/types/index.d.ts +2 -0
  76. package/types/index.js +6 -0
  77. package/types/index.js.map +1 -0
  78. package/.idea/aws.xml +0 -17
  79. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  80. package/.idea/prettier.xml +0 -6
  81. package/.idea/vcs.xml +0 -6
  82. package/.idea/workspace.xml +0 -133
  83. package/src/types/index.d.ts +0 -10
@@ -1,237 +1,237 @@
1
- type ThreeDSHandlerContructor = {
2
- payload?: any,
3
- apiKey?: string,
4
- baseUrl?: string,
5
- }
6
-
7
- export class ThreeDSHandler {
8
-
9
- baseUrl?: string
10
- apiKey?: string
11
- payload?: any
12
- localStorageKey: string = "verify_transaction_status_url"
13
-
14
- constructor({
15
- payload = null,
16
- apiKey,
17
- baseUrl,
18
- }: ThreeDSHandlerContructor) {
19
- this.baseUrl = baseUrl,
20
- this.apiKey = apiKey,
21
- this.payload = payload
22
- }
23
-
24
- setStorageItem (data: any) {
25
- return localStorage.setItem(this.localStorageKey, JSON.stringify(data))
26
- }
27
-
28
- getStorageItem () {
29
- return localStorage.getItem(this.localStorageKey)
30
- }
31
-
32
- removeStorageItem () {
33
- return localStorage.removeItem(this.localStorageKey)
34
- }
35
-
36
- saveVerifyTransactionUrl() {
37
- const url = this.payload?.next_action?.redirect_to_url?.verify_transaction_status_url
38
- if (url) {
39
- this.saveUrlWithExpiration(url)
40
- } else {
41
- const url = this.payload?.next_action?.iframe_resources?.verify_transaction_status_url
42
- if (url) {
43
- this.saveUrlWithExpiration(url)
44
- } else {
45
- console.log('No verify_transaction_status_url found');
46
- }
47
- }
48
- }
49
-
50
- saveUrlWithExpiration(url: string) {
51
- try {
52
- const now = new Date()
53
- const item = {
54
- url: url,
55
- // Expires after 20 minutes
56
- expires: now.getTime() + 20 * 60 * 1000
57
- }
58
- this.setStorageItem(item)
59
- } catch (error) {
60
- console.log('error: ', error)
61
- }
62
- }
63
-
64
- getUrlWithExpiration() {
65
- const status = this.getStorageItem();
66
- if(status) {
67
- const item = JSON.parse(status)
68
- if (!item) return
69
- const now = new Date()
70
- if (now.getTime() > item.expires) {
71
- this.removeVerifyTransactionUrl()
72
- return null
73
- } else {
74
- return item.url
75
- }
76
- } else {
77
- return null
78
- }
79
- }
80
-
81
- removeVerifyTransactionUrl() {
82
- return this.removeStorageItem()
83
- }
84
-
85
- getVerifyTransactionUrl() {
86
- return this.getStorageItem()
87
- }
88
-
89
- loadIframe() {
90
- const iframe = this.payload?.next_action?.iframe_resources?.iframe
91
-
92
- if (iframe) {
93
- return new Promise((resolve, reject) => {
94
- const iframe = this.payload?.next_action?.iframe_resources?.iframe
95
-
96
- if (iframe) {
97
- this.saveVerifyTransactionUrl()
98
- const container = document.createElement('div')
99
- container.innerHTML = iframe
100
- document.body.appendChild(container)
101
-
102
- // Create and append the script tag manually
103
- const script = document.createElement('script')
104
- script.textContent = 'document.getElementById("tdsMmethodForm").submit();'
105
- container.appendChild(script)
106
-
107
- // Resolve the promise when the iframe is loaded
108
- const iframeElement = document.getElementById('tdsMmethodTgtFrame')
109
- if(iframeElement) {
110
- iframeElement.onload = () => resolve(true)
111
- } else {
112
- console.log('No redirection found');
113
- reject(false)
114
- }
115
- } else {
116
- console.log('No redirection found');
117
- reject(false)
118
- }
119
- })
120
- }
121
- }
122
-
123
- getRedirectUrl() {
124
- return this.payload?.next_action?.redirect_to_url?.url
125
- }
126
-
127
- redirectToChallenge() {
128
- const url = this.getRedirectUrl()
129
- if (url) {
130
- this.saveVerifyTransactionUrl()
131
- window.location = url;
132
- } else {
133
- console.log('No redirection found');
134
- }
135
- }
136
-
137
- // Returns an object
138
- // https://example.com/?name=John&age=30&city=NewYork
139
- // { name: "John", age: "30", city: "NewYork" }
140
- getURLParameters() {
141
- const parameters: any = {};
142
- const urlParams: any = new URLSearchParams(window.location.search);
143
-
144
- for (const [key, value] of urlParams) {
145
- parameters[key] = value;
146
- }
147
-
148
- return parameters;
149
- }
150
-
151
- handleSuccessTransaction(response: any) {
152
- this.removeVerifyTransactionUrl();
153
- console.log('Transacción autorizada.');
154
- return response;
155
- }
156
-
157
- handleDeclinedTransaction(response: any) {
158
- this.removeVerifyTransactionUrl();
159
- return response;
160
- }
161
-
162
- // TODO: the method below needs to be tested with a real 3DS challenge
163
- // since we couldn't get a test card that works with this feature
164
- async handle3dsChallenge(response_json: any) {
165
- // Create the form element:
166
- const form = document.createElement('form');
167
- form.name = 'frm';
168
- form.method = 'POST';
169
- form.action = response_json.redirect_post_url;
170
-
171
- // Add hidden fields:
172
- const creqInput = document.createElement('input');
173
- creqInput.type = 'hidden';
174
- creqInput.name = response_json.creq;
175
- creqInput.value = response_json.creq;
176
- form.appendChild(creqInput);
177
-
178
- const termUrlInput = document.createElement('input');
179
- termUrlInput.type = 'hidden';
180
- termUrlInput.name = response_json.term_url;
181
- termUrlInput.value = response_json.TermUrl;
182
- form.appendChild(termUrlInput);
183
-
184
- // Append the form to the body:
185
- document.body.appendChild(form);
186
- form.submit();
187
-
188
- await this.verifyTransactionStatus();
189
- }
190
-
191
- // TODO: This method could be removed
192
- async handleTransactionResponse(response: any) {
193
- const response_json = await response.json();
194
- if (response_json.status === "Pending" && response_json.redirect_post_url) {
195
- return await this.handle3dsChallenge(response_json);
196
- } else if (["Success", "Authorized"].includes(response_json.status)) {
197
- return this.handleSuccessTransaction(response_json);
198
- } else {
199
- this.handleDeclinedTransaction(response);
200
- return response_json
201
- }
202
- }
203
-
204
- async verifyTransactionStatus() {
205
- const verifyUrl = this.getUrlWithExpiration();
206
- if (verifyUrl) {
207
- const url = `${this.baseUrl}${verifyUrl}`;
208
- try {
209
- const response = await fetch(url, {
210
- method: "GET",
211
- headers: {
212
- "Content-Type": "application/json",
213
- Authorization: `Token ${this.apiKey}`,
214
- },
215
- // body: JSON.stringify(data),
216
- });
217
-
218
- if (response.status !== 200) {
219
- console.error('La verificación de la transacción falló.');
220
- this.removeVerifyTransactionUrl();
221
- return response
222
- }
223
-
224
- return await this.handleTransactionResponse(response);
225
- } catch (error) {
226
- console.error('Error al verificar la transacción:', error);
227
- this.removeVerifyTransactionUrl();
228
- }
229
- } else {
230
- console.log('No verify_transaction_status_url found');
231
- }
232
- }
233
-
234
- setPayload = (payload: any) => {
235
- this.payload = payload
236
- }
237
- }
1
+ type ThreeDSHandlerContructor = {
2
+ payload?: any,
3
+ apiKey?: string,
4
+ baseUrl?: string,
5
+ }
6
+
7
+ export class ThreeDSHandler {
8
+
9
+ baseUrl?: string
10
+ apiKey?: string
11
+ payload?: any
12
+ localStorageKey: string = "verify_transaction_status_url"
13
+
14
+ constructor({
15
+ payload = null,
16
+ apiKey,
17
+ baseUrl,
18
+ }: ThreeDSHandlerContructor) {
19
+ this.baseUrl = baseUrl,
20
+ this.apiKey = apiKey,
21
+ this.payload = payload
22
+ }
23
+
24
+ setStorageItem (data: any) {
25
+ return localStorage.setItem(this.localStorageKey, JSON.stringify(data))
26
+ }
27
+
28
+ getStorageItem () {
29
+ return localStorage.getItem(this.localStorageKey)
30
+ }
31
+
32
+ removeStorageItem () {
33
+ return localStorage.removeItem(this.localStorageKey)
34
+ }
35
+
36
+ saveVerifyTransactionUrl() {
37
+ const url = this.payload?.next_action?.redirect_to_url?.verify_transaction_status_url
38
+ if (url) {
39
+ this.saveUrlWithExpiration(url)
40
+ } else {
41
+ const url = this.payload?.next_action?.iframe_resources?.verify_transaction_status_url
42
+ if (url) {
43
+ this.saveUrlWithExpiration(url)
44
+ } else {
45
+ console.log('No verify_transaction_status_url found');
46
+ }
47
+ }
48
+ }
49
+
50
+ saveUrlWithExpiration(url: string) {
51
+ try {
52
+ const now = new Date()
53
+ const item = {
54
+ url: url,
55
+ // Expires after 20 minutes
56
+ expires: now.getTime() + 20 * 60 * 1000
57
+ }
58
+ this.setStorageItem(item)
59
+ } catch (error) {
60
+ console.log('error: ', error)
61
+ }
62
+ }
63
+
64
+ getUrlWithExpiration() {
65
+ const status = this.getStorageItem();
66
+ if(status) {
67
+ const item = JSON.parse(status)
68
+ if (!item) return
69
+ const now = new Date()
70
+ if (now.getTime() > item.expires) {
71
+ this.removeVerifyTransactionUrl()
72
+ return null
73
+ } else {
74
+ return item.url
75
+ }
76
+ } else {
77
+ return null
78
+ }
79
+ }
80
+
81
+ removeVerifyTransactionUrl() {
82
+ return this.removeStorageItem()
83
+ }
84
+
85
+ getVerifyTransactionUrl() {
86
+ return this.getStorageItem()
87
+ }
88
+
89
+ loadIframe() {
90
+ const iframe = this.payload?.next_action?.iframe_resources?.iframe
91
+
92
+ if (iframe) {
93
+ return new Promise((resolve, reject) => {
94
+ const iframe = this.payload?.next_action?.iframe_resources?.iframe
95
+
96
+ if (iframe) {
97
+ this.saveVerifyTransactionUrl()
98
+ const container = document.createElement('div')
99
+ container.innerHTML = iframe
100
+ document.body.appendChild(container)
101
+
102
+ // Create and append the script tag manually
103
+ const script = document.createElement('script')
104
+ script.textContent = 'document.getElementById("tdsMmethodForm").submit();'
105
+ container.appendChild(script)
106
+
107
+ // Resolve the promise when the iframe is loaded
108
+ const iframeElement = document.getElementById('tdsMmethodTgtFrame')
109
+ if(iframeElement) {
110
+ iframeElement.onload = () => resolve(true)
111
+ } else {
112
+ console.log('No redirection found');
113
+ reject(false)
114
+ }
115
+ } else {
116
+ console.log('No redirection found');
117
+ reject(false)
118
+ }
119
+ })
120
+ }
121
+ }
122
+
123
+ getRedirectUrl() {
124
+ return this.payload?.next_action?.redirect_to_url?.url
125
+ }
126
+
127
+ redirectToChallenge() {
128
+ const url = this.getRedirectUrl()
129
+ if (url) {
130
+ this.saveVerifyTransactionUrl()
131
+ window.location = url;
132
+ } else {
133
+ console.log('No redirection found');
134
+ }
135
+ }
136
+
137
+ // Returns an object
138
+ // https://example.com/?name=John&age=30&city=NewYork
139
+ // { name: "John", age: "30", city: "NewYork" }
140
+ getURLParameters() {
141
+ const parameters: any = {};
142
+ const urlParams: any = new URLSearchParams(window.location.search);
143
+
144
+ for (const [key, value] of urlParams) {
145
+ parameters[key] = value;
146
+ }
147
+
148
+ return parameters;
149
+ }
150
+
151
+ handleSuccessTransaction(response: any) {
152
+ this.removeVerifyTransactionUrl();
153
+ console.log('Transacción autorizada.');
154
+ return response;
155
+ }
156
+
157
+ handleDeclinedTransaction(response: any) {
158
+ this.removeVerifyTransactionUrl();
159
+ return response;
160
+ }
161
+
162
+ // TODO: the method below needs to be tested with a real 3DS challenge
163
+ // since we couldn't get a test card that works with this feature
164
+ async handle3dsChallenge(response_json: any) {
165
+ // Create the form element:
166
+ const form = document.createElement('form');
167
+ form.name = 'frm';
168
+ form.method = 'POST';
169
+ form.action = response_json.redirect_post_url;
170
+
171
+ // Add hidden fields:
172
+ const creqInput = document.createElement('input');
173
+ creqInput.type = 'hidden';
174
+ creqInput.name = response_json.creq;
175
+ creqInput.value = response_json.creq;
176
+ form.appendChild(creqInput);
177
+
178
+ const termUrlInput = document.createElement('input');
179
+ termUrlInput.type = 'hidden';
180
+ termUrlInput.name = response_json.term_url;
181
+ termUrlInput.value = response_json.TermUrl;
182
+ form.appendChild(termUrlInput);
183
+
184
+ // Append the form to the body:
185
+ document.body.appendChild(form);
186
+ form.submit();
187
+
188
+ await this.verifyTransactionStatus();
189
+ }
190
+
191
+ // TODO: This method could be removed
192
+ async handleTransactionResponse(response: any) {
193
+ const response_json = await response.json();
194
+ if (response_json.status === "Pending" && response_json.redirect_post_url) {
195
+ return await this.handle3dsChallenge(response_json);
196
+ } else if (["Success", "Authorized"].includes(response_json.status)) {
197
+ return this.handleSuccessTransaction(response_json);
198
+ } else {
199
+ this.handleDeclinedTransaction(response);
200
+ return response_json
201
+ }
202
+ }
203
+
204
+ async verifyTransactionStatus() {
205
+ const verifyUrl = this.getUrlWithExpiration();
206
+ if (verifyUrl) {
207
+ const url = `${this.baseUrl}${verifyUrl}`;
208
+ try {
209
+ const response = await fetch(url, {
210
+ method: "GET",
211
+ headers: {
212
+ "Content-Type": "application/json",
213
+ Authorization: `Token ${this.apiKey}`,
214
+ },
215
+ // body: JSON.stringify(data),
216
+ });
217
+
218
+ if (response.status !== 200) {
219
+ console.error('La verificación de la transacción falló.');
220
+ this.removeVerifyTransactionUrl();
221
+ return response
222
+ }
223
+
224
+ return await this.handleTransactionResponse(response);
225
+ } catch (error) {
226
+ console.error('Error al verificar la transacción:', error);
227
+ this.removeVerifyTransactionUrl();
228
+ }
229
+ } else {
230
+ console.log('No verify_transaction_status_url found');
231
+ }
232
+ }
233
+
234
+ setPayload = (payload: any) => {
235
+ this.payload = payload
236
+ }
237
+ }