@tonder.io/ionic-lite-sdk 0.0.35-beta.7 → 0.0.36-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 (85) hide show
  1. package/.gitlab-ci.yml +28 -28
  2. package/README.md +221 -202
  3. package/dist/classes/errorResponse.d.ts +1 -1
  4. package/dist/classes/liteCheckout.d.ts +32 -56
  5. package/dist/data/api.d.ts +1 -1
  6. package/dist/helpers/utils.d.ts +4 -8
  7. package/dist/index.d.ts +1 -2
  8. package/dist/index.js +1 -1
  9. package/dist/types/commons.d.ts +0 -37
  10. package/dist/types/requests.d.ts +3 -12
  11. package/dist/types/responses.d.ts +3 -0
  12. package/jest.config.ts +14 -14
  13. package/package.json +38 -38
  14. package/rollup.config.js +16 -16
  15. package/src/classes/3dsHandler.ts +237 -237
  16. package/src/classes/errorResponse.ts +16 -16
  17. package/src/classes/liteCheckout.ts +575 -598
  18. package/src/data/api.ts +20 -20
  19. package/src/helpers/constants.ts +63 -63
  20. package/src/helpers/mercadopago.ts +15 -15
  21. package/src/helpers/utils.ts +320 -120
  22. package/src/index.ts +4 -10
  23. package/src/types/commons.ts +83 -125
  24. package/src/types/requests.ts +105 -114
  25. package/src/types/responses.ts +193 -189
  26. package/src/types/skyflow.ts +17 -17
  27. package/tests/classes/liteCheckout.test.ts +57 -57
  28. package/tests/methods/createOrder.test.ts +142 -142
  29. package/tests/methods/createPayment.test.ts +122 -122
  30. package/tests/methods/customerRegister.test.ts +119 -119
  31. package/tests/methods/getBusiness.test.ts +115 -115
  32. package/tests/methods/getCustomerCards.test.ts +119 -113
  33. package/tests/methods/getOpenpayDeviceSessionID.test.ts +95 -0
  34. package/tests/methods/getSkyflowToken.test.ts +155 -0
  35. package/tests/methods/getVaultToken.test.ts +107 -0
  36. package/tests/methods/registerCustomerCard.test.ts +117 -117
  37. package/tests/methods/startCheckoutRouter.test.ts +119 -119
  38. package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
  39. package/tests/utils/defaultMock.ts +20 -21
  40. package/tests/utils/mockClasses.ts +656 -659
  41. package/tsconfig.json +18 -18
  42. package/.idea/aws.xml +0 -17
  43. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  44. package/.idea/prettier.xml +0 -6
  45. package/.idea/vcs.xml +0 -6
  46. package/.idea/workspace.xml +0 -132
  47. package/dist/classes/BaseInlineCheckout.d.ts +0 -45
  48. package/dist/data/businessApi.d.ts +0 -2
  49. package/dist/data/cardApi.d.ts +0 -4
  50. package/dist/data/checkoutApi.d.ts +0 -4
  51. package/dist/data/customerApi.d.ts +0 -2
  52. package/dist/data/openPayApi.d.ts +0 -1
  53. package/dist/data/paymentMethodApi.d.ts +0 -5
  54. package/dist/data/skyflowApi.d.ts +0 -1
  55. package/dist/helpers/skyflow.d.ts +0 -3
  56. package/dist/helpers/validations.d.ts +0 -6
  57. package/dist/shared/catalog/paymentMethodsCatalog.d.ts +0 -1
  58. package/dist/shared/constants/messages.d.ts +0 -11
  59. package/dist/shared/constants/paymentMethodAPM.d.ts +0 -62
  60. package/dist/shared/constants/tonderUrl.d.ts +0 -7
  61. package/dist/types/card.d.ts +0 -29
  62. package/dist/types/checkout.d.ts +0 -103
  63. package/dist/types/customer.d.ts +0 -12
  64. package/dist/types/paymentMethod.d.ts +0 -22
  65. package/src/classes/BaseInlineCheckout.ts +0 -356
  66. package/src/data/businessApi.ts +0 -18
  67. package/src/data/cardApi.ts +0 -89
  68. package/src/data/checkoutApi.ts +0 -87
  69. package/src/data/customerApi.ts +0 -31
  70. package/src/data/openPayApi.ts +0 -12
  71. package/src/data/paymentMethodApi.ts +0 -37
  72. package/src/data/skyflowApi.ts +0 -20
  73. package/src/helpers/skyflow.ts +0 -91
  74. package/src/helpers/validations.ts +0 -55
  75. package/src/shared/catalog/paymentMethodsCatalog.ts +0 -248
  76. package/src/shared/constants/messages.ts +0 -11
  77. package/src/shared/constants/paymentMethodAPM.ts +0 -63
  78. package/src/shared/constants/tonderUrl.ts +0 -8
  79. package/src/types/card.ts +0 -34
  80. package/src/types/checkout.ts +0 -118
  81. package/src/types/customer.ts +0 -12
  82. package/src/types/index.d.ts +0 -10
  83. package/src/types/liteInlineCheckout.d.ts +0 -191
  84. package/src/types/paymentMethod.ts +0 -24
  85. package/src/types/validations.d.ts +0 -11
@@ -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
+ }
@@ -1,17 +1,17 @@
1
- import { IErrorResponse } from "../types";
2
-
3
- export class ErrorResponse implements IErrorResponse {
4
- code?: string | undefined;
5
- body?: string | undefined;
6
- name!: string;
7
- message!: string;
8
- stack?: string | undefined;
9
-
10
- constructor({ code, body, name, message, stack }: IErrorResponse) {
11
- this.code = code;
12
- this.body = body;
13
- this.name = name;
14
- this.message = message;
15
- this.stack = stack;
16
- }
1
+ import { IErrorResponse } from "../types/responses";
2
+
3
+ export class ErrorResponse implements IErrorResponse {
4
+ code?: string | undefined;
5
+ body?: string | undefined;
6
+ name!: string;
7
+ message!: string;
8
+ stack?: string | undefined;
9
+
10
+ constructor({ code, body, name, message, stack }: IErrorResponse) {
11
+ this.code = code;
12
+ this.body = body;
13
+ this.name = name;
14
+ this.message = message;
15
+ this.stack = stack;
16
+ }
17
17
  }