tonder-web-sdk 1.11.11 → 1.12.0-beta.0

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/src/index-dev.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { InlineCheckout } from './classes/inlineCheckout'
2
+ import {LiteInlineCheckout} from "./classes/LiteInlineCheckout";
2
3
 
3
4
  const customStyles = {
4
5
  inputStyles: {
@@ -96,31 +97,43 @@ const checkoutData = {
96
97
  // }
97
98
  };
98
99
 
100
+
101
+
99
102
  // localhost
100
103
  const apiKey = "11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27";
101
104
  const returnUrl = "http://127.0.0.1:8080/"
102
- const successUrl = "http://127.0.0.1:8080/success"
103
105
  // stage
104
106
  // const apiKey = "8365683bdc33dd6d50fe2397188d79f1a6765852";
105
107
 
106
- const inlineCheckout = new InlineCheckout({
107
- mode: 'stage',
108
+
109
+ const commonConfig = {
110
+ mode: 'development',
108
111
  apiKey,
109
112
  returnUrl,
110
- successUrl,
111
113
  styles: customStyles
112
- });
113
- inlineCheckout.configureCheckout({customer: checkoutData.customer})
114
- inlineCheckout.injectCheckout();
115
- //
116
- // ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
117
- inlineCheckout.verify3dsTransaction().then(response => {
118
- console.log('Verify 3ds response', response)
119
- })
114
+ };
115
+
116
+ let checkout;
117
+ let inlineCheckout;
118
+ let liteInlineCheckout;
119
+
120
+
121
+ function getCheckoutMode() {
122
+ const urlParams = new URLSearchParams(window.location.search);
123
+ return urlParams.get('mode') || 'inline';
124
+ }
125
+
126
+ function setupInlineCheckout() {
127
+ inlineCheckout = new InlineCheckout({...commonConfig});
128
+ inlineCheckout.configureCheckout({customer: checkoutData.customer})
129
+ inlineCheckout.injectCheckout();
130
+ // ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
131
+ inlineCheckout.verify3dsTransaction().then(response => {
132
+ console.log('Verify 3ds response', response)
133
+ })
120
134
 
121
- document.addEventListener('DOMContentLoaded', function() {
122
135
  const payButton = document.getElementById('pay-button');
123
- payButton.addEventListener('click', async function() {
136
+ payButton.addEventListener('click', async function () {
124
137
  try {
125
138
  payButton.textContent = 'Procesando...';
126
139
  const response = await inlineCheckout.payment(checkoutData);
@@ -132,4 +145,73 @@ document.addEventListener('DOMContentLoaded', function() {
132
145
  payButton.textContent = 'Pagar';
133
146
  }
134
147
  });
148
+ }
149
+
150
+ function setupLiteInlineCheckout() {
151
+ liteInlineCheckout = new LiteInlineCheckout(commonConfig);
152
+ liteInlineCheckout.configureCheckout({customer: checkoutData.customer})
153
+ liteInlineCheckout.injectCheckout().then(() => {});
154
+ liteInlineCheckout.verify3dsTransaction().then(response => {
155
+ console.log('Verify 3ds response', response)
156
+ })
157
+
158
+ const liteForm = document.getElementById('lite-payment-form');
159
+ liteForm.addEventListener('submit', async function(event) {
160
+ event.preventDefault();
161
+
162
+ const cardData = {
163
+ card_number: document.getElementById('card-number').value,
164
+ cardholder_name: document.getElementById('card-name').value,
165
+ expiration_month: document.getElementById('month').value,
166
+ expiration_year: document.getElementById('year').value,
167
+ cvv: document.getElementById('cvv').value
168
+ };
169
+
170
+ try {
171
+ const paymentData = {
172
+ ...checkoutData,
173
+ card: cardData
174
+ };
175
+ const response = await liteInlineCheckout.payment(paymentData);
176
+ console.log("Respuesta del pago:", response);
177
+ alert('Pago realizado con éxito');
178
+ } catch (error) {
179
+ console.error("Error en el pago:", error);
180
+ alert('Error al realizar el pago');
181
+ }
182
+ });
183
+ }
184
+
185
+ function setupCheckout() {
186
+ const mode = getCheckoutMode();
187
+ document.querySelectorAll('.tab-content').forEach(content => {
188
+ content.style.display = 'none';
189
+ });
190
+
191
+ if (mode === 'inline') {
192
+ document.getElementById('inline-content').style.display = 'block';
193
+ setupInlineCheckout()
194
+ }else{
195
+ document.getElementById('lite-content').style.display = 'block';
196
+ setupLiteInlineCheckout()
197
+ }
198
+ }
199
+
200
+ function updateActiveTab() {
201
+ const mode = getCheckoutMode();
202
+ document.querySelectorAll('.tab').forEach(tab => {
203
+ tab.classList.remove('active');
204
+ });
205
+ document.querySelector(`[data-mode="${mode}"]`).classList.add('active');
206
+ }
207
+
208
+ function switchTab(mode) {
209
+ window.location.href = `${window.location.pathname}?mode=${mode}`;
210
+ }
211
+
212
+ document.addEventListener('DOMContentLoaded', function() {
213
+ setupCheckout();
214
+ updateActiveTab();
135
215
  });
216
+
217
+ window.switchTab = switchTab;
package/src/index.html CHANGED
@@ -35,20 +35,131 @@
35
35
  display: flex;
36
36
  justify-content: center;
37
37
  }
38
+ .tab-container {
39
+ display: flex;
40
+ justify-content: center;
41
+ margin-bottom: 20px;
42
+ }
43
+ .tab {
44
+ padding: 10px 20px;
45
+ cursor: pointer;
46
+ background-color: #f1f1f1;
47
+ border: 1px solid #ccc;
48
+ border-bottom: none;
49
+ margin-right: 5px;
50
+ }
51
+ .tab.active {
52
+ background-color: #fff;
53
+ border-bottom: 1px solid #4a90e2;
54
+ }
55
+ .tab-content {
56
+ display: none;
57
+ width: 100%;
58
+ }
59
+ .card-form {
60
+ max-width: 400px;
61
+ margin: 0 auto;
62
+ }
63
+ .form-group {
64
+ margin-bottom: 1.5rem;
65
+ }
66
+ .form-group label {
67
+ display: block;
68
+ margin-bottom: 0.5rem;
69
+ font-weight: 500;
70
+ }
71
+ .form-group input {
72
+ width: 100%;
73
+ padding: 0.75rem;
74
+ border: 1px solid #ddd;
75
+ border-radius: 4px;
76
+ font-size: 1rem;
77
+ transition: border-color 0.3s ease;
78
+ }
79
+ .form-group input:focus {
80
+ outline: none;
81
+ border-color: #4a90e2;
82
+ }
83
+ .form-row {
84
+ display: flex;
85
+ gap: 3rem;
86
+ }
87
+ .form-row .form-group {
88
+ flex: 1;
89
+ }
90
+ .btn {
91
+ display: inline-block;
92
+ padding: 0.75rem 1.5rem;
93
+ background-color: #4a90e2;
94
+ color: #fff;
95
+ border: none;
96
+ border-radius: 4px;
97
+ font-size: 1rem;
98
+ cursor: pointer;
99
+ transition: background-color 0.3s ease;
100
+ }
101
+ .btn:hover {
102
+ background-color: #357abd;
103
+ }
104
+ .cart-details {
105
+ text-align: center;
106
+ font-size: 1.5rem;
107
+ margin-bottom: 2rem;
108
+ }
109
+ .input-md {
110
+ max-width: 100%;
111
+ }
38
112
  </style>
39
113
  </head>
40
114
 
41
115
  <body>
42
116
  <div class="checkout-container">
43
- <div class="cart-details">
44
- <span>Total&nbsp</span>
45
- <div id="cart-total">$399</div>
117
+ <div class="tab-container">
118
+ <a href="?mode=inline" class="tab" data-mode="inline" onclick="switchTab('inline'); return false;">Inline Checkout</a>
119
+ <a href="?mode=lite" class="tab" data-mode="lite" onclick="switchTab('lite'); return false;">Lite Inline Checkout</a>
120
+ </div>
121
+
122
+ <div id="lite-content" class="tab-content">
123
+ <div class="cart-details">
124
+ <span>Total&nbsp;</span>
125
+ <div id="cart-total-lite">$399</div>
126
+ </div>
127
+ <form id="lite-payment-form" class="card-form">
128
+ <div class="form-group">
129
+ <label for="card-number">Número de Tarjeta</label>
130
+ <input type="text" id="card-number" placeholder="1234 5678 9012 3456" required>
131
+ </div>
132
+ <div class="form-group">
133
+ <label for="card-name">Nombre en la Tarjeta</label>
134
+ <input type="text" id="card-name" placeholder="John Doe" required>
135
+ </div>
136
+ <div class="form-row">
137
+ <div class="form-group">
138
+ <label for="month">Fecha de Expiración</label>
139
+ <div class="form-row">
140
+ <input class="input-md" type="text" id="month" placeholder="MM" required>
141
+ <input class="input-md" type="text" id="year" placeholder="AA" required>
142
+ </div>
143
+ </div>
144
+ <div class="form-group">
145
+ <label for="cvv">CVV</label>
146
+ <input class="input-md" type="text" id="cvv" placeholder="123" required>
147
+ </div>
148
+ </div>
149
+ <button type="submit" class="btn">Pagar Ahora</button>
150
+ </form>
46
151
  </div>
47
- <form id="payment-form">
48
- <div id="tonder-checkout"></div>
49
- </form>
50
- <div class="button-container">
51
- <button id="pay-button">Pagar</button>
152
+ <div id="inline-content" class="tab-content">
153
+ <div class="cart-details">
154
+ <span>Total&nbsp</span>
155
+ <div id="cart-total">$399</div>
156
+ </div>
157
+ <form id="payment-form">
158
+ <div id="tonder-checkout"></div>
159
+ </form>
160
+ <div class="button-container">
161
+ <button id="pay-button">Pagar</button>
162
+ </div>
52
163
  </div>
53
164
  </div>
54
165
  </body>
@@ -0,0 +1,63 @@
1
+ const PAYMENT_METHOD_APM = Object.freeze({
2
+ SORIANA: "SORIANA",
3
+ OXXO: "OXXO",
4
+ SPEI: "SPEI",
5
+ CODI: "CODI",
6
+ MERCADOPAGO: "MERCADOPAGO",
7
+ PAYPAL: "PAYPAL",
8
+ COMERCIALMEXICANA: "COMERCIALMEXICANA",
9
+ BANCOMER: "BANCOMER",
10
+ WALMART: "WALMART",
11
+ BODEGA: "BODEGA",
12
+ SAMSCLUB: "SAMSCLUB",
13
+ SUPERAMA: "SUPERAMA",
14
+ CALIMAX: "CALIMAX",
15
+ EXTRA: "EXTRA",
16
+ CIRCULOK: "CIRCULOK",
17
+ SEVEN11: "7ELEVEN",
18
+ TELECOMM: "TELECOMM",
19
+ BANORTE: "BANORTE",
20
+ BENAVIDES: "BENAVIDES",
21
+ DELAHORRO: "DELAHORRO",
22
+ ELASTURIANO: "ELASTURIANO",
23
+ WALDOS: "WALDOS",
24
+ ALSUPER: "ALSUPER",
25
+ KIOSKO: "KIOSKO",
26
+ STAMARIA: "STAMARIA",
27
+ LAMASBARATA: "LAMASBARATA",
28
+ FARMROMA: "FARMROMA",
29
+ FARMUNION: "FARMUNION",
30
+ FARMATODO: "FARMATODO",
31
+ SFDEASIS: "SFDEASIS",
32
+ FARM911: "FARM911",
33
+ FARMECONOMICAS: "FARMECONOMICAS",
34
+ FARMMEDICITY: "FARMMEDICITY",
35
+ RIANXEIRA: "RIANXEIRA",
36
+ WESTERNUNION: "WESTERNUNION",
37
+ ZONAPAGO: "ZONAPAGO",
38
+ CAJALOSANDES: "CAJALOSANDES",
39
+ CAJAPAITA: "CAJAPAITA",
40
+ CAJASANTA: "CAJASANTA",
41
+ CAJASULLANA: "CAJASULLANA",
42
+ CAJATRUJILLO: "CAJATRUJILLO",
43
+ EDPYME: "EDPYME",
44
+ KASNET: "KASNET",
45
+ NORANDINO: "NORANDINO",
46
+ QAPAQ: "QAPAQ",
47
+ RAIZ: "RAIZ",
48
+ PAYSER: "PAYSER",
49
+ WUNION: "WUNION",
50
+ BANCOCONTINENTAL: "BANCOCONTINENTAL",
51
+ GMONEY: "GMONEY",
52
+ GOPAY: "GOPAY",
53
+ WU: "WU",
54
+ PUNTOSHEY: "PUNTOSHEY",
55
+ AMPM: "AMPM",
56
+ JUMBOMARKET: "JUMBOMARKET",
57
+ SMELPUEBLO: "SMELPUEBLO",
58
+ BAM: "BAM",
59
+ REFACIL: "REFACIL",
60
+ ACYVALORES: "ACYVALORES",
61
+ });
62
+
63
+ export { PAYMENT_METHOD_APM };
@@ -0,0 +1,8 @@
1
+ const TONDER_URL_BY_MODE = Object.freeze({
2
+ production: "https://app.tonder.io",
3
+ sandbox: "https://sandbox.tonder.io",
4
+ stage: "https://stage.tonder.io",
5
+ development: "http://localhost:8000",
6
+ });
7
+
8
+ export { TONDER_URL_BY_MODE };
@@ -0,0 +1,14 @@
1
+ export interface InlineCheckoutOptions {
2
+ mode?: string;
3
+ apiKey: string;
4
+ returnUrl: string;
5
+ renderPaymentButton?: boolean;
6
+ callBack?: (response: any) => void;
7
+ styles?: Record<string, string>;
8
+ }
9
+
10
+ export class InlineCheckout {
11
+ constructor(options: InlineCheckoutOptions);
12
+ injectCheckout(): void;
13
+ }
14
+