@voxepay/checkout 0.0.1-security → 0.5.19
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.
Potentially problematic release.
This version of @voxepay/checkout might be problematic. Click here for more details.
- package/README.md +140 -3
- package/dist/api/client.d.ts +146 -0
- package/dist/components/modal.d.ts +190 -0
- package/dist/index.cjs.js +2272 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.esm.js +2253 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/types.d.ts +170 -0
- package/dist/utils/card-validator.d.ts +47 -0
- package/dist/utils/encryption.d.ts +28 -0
- package/dist/utils/formatter.d.ts +31 -0
- package/dist/voxepay-checkout.min.js +2 -0
- package/dist/voxepay-checkout.min.js.map +1 -0
- package/dist/voxepay.d.ts +63 -0
- package/package.json +41 -3
- package/src/api/client.ts +301 -0
- package/src/components/modal.ts +1783 -0
- package/src/index.ts +76 -0
- package/src/types.ts +178 -0
- package/src/utils/card-validator.ts +198 -0
- package/src/utils/encryption.ts +182 -0
- package/src/utils/formatter.ts +91 -0
- package/src/voxepay.ts +200 -0
|
@@ -0,0 +1,1783 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VoxePay Checkout Modal Component
|
|
3
|
+
* A modern, glassmorphism payment modal
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
detectCardBrand,
|
|
8
|
+
validateCardNumber,
|
|
9
|
+
validateExpiry,
|
|
10
|
+
validateCVV,
|
|
11
|
+
validatePIN
|
|
12
|
+
} from '../utils/card-validator';
|
|
13
|
+
import {
|
|
14
|
+
formatCardNumber,
|
|
15
|
+
formatExpiry,
|
|
16
|
+
formatCVV,
|
|
17
|
+
formatPIN,
|
|
18
|
+
formatAmount,
|
|
19
|
+
formatMainUnitAmount
|
|
20
|
+
} from '../utils/formatter';
|
|
21
|
+
import { generateAuthData, formatExpiryForApi, cleanPan } from '../utils/encryption';
|
|
22
|
+
import { VoxePayApiClient } from '../api/client';
|
|
23
|
+
import type { CheckoutOptions, PaymentResult, PaymentError, BankTransferDetails, PaymentMethod } from '../types';
|
|
24
|
+
|
|
25
|
+
// SVG Icons
|
|
26
|
+
const ICONS = {
|
|
27
|
+
close: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
28
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
29
|
+
</svg>`,
|
|
30
|
+
lock: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
31
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
|
|
32
|
+
</svg>`,
|
|
33
|
+
check: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">
|
|
34
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
|
|
35
|
+
</svg>`,
|
|
36
|
+
error: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20" stroke="currentColor" stroke-width="2">
|
|
37
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" />
|
|
38
|
+
</svg>`,
|
|
39
|
+
copy: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
40
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
|
|
41
|
+
</svg>`,
|
|
42
|
+
bank: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
43
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M3 21h18M3 10h18M5 6l7-3 7 3M4 10v11M20 10v11M8 14v3M12 14v3M16 14v3" />
|
|
44
|
+
</svg>`,
|
|
45
|
+
card: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
46
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />
|
|
47
|
+
</svg>`,
|
|
48
|
+
clock: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
49
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
50
|
+
</svg>`,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Card brand logos
|
|
54
|
+
const CARD_BRAND_DISPLAY: Record<string, string> = {
|
|
55
|
+
visa: 'VISA',
|
|
56
|
+
mastercard: 'MC',
|
|
57
|
+
amex: 'AMEX',
|
|
58
|
+
verve: 'VERVE',
|
|
59
|
+
discover: 'DISC',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export interface ModalState {
|
|
63
|
+
cardNumber: string;
|
|
64
|
+
expiry: string;
|
|
65
|
+
cvv: string;
|
|
66
|
+
pin: string;
|
|
67
|
+
otp: string;
|
|
68
|
+
errors: {
|
|
69
|
+
cardNumber?: string;
|
|
70
|
+
expiry?: string;
|
|
71
|
+
cvv?: string;
|
|
72
|
+
pin?: string;
|
|
73
|
+
otp?: string;
|
|
74
|
+
};
|
|
75
|
+
isProcessing: boolean;
|
|
76
|
+
isSuccess: boolean;
|
|
77
|
+
isOtpStep: boolean;
|
|
78
|
+
otpTimer: number;
|
|
79
|
+
canResendOtp: boolean;
|
|
80
|
+
otpTimerInterval: number | null;
|
|
81
|
+
paymentMethod: PaymentMethod;
|
|
82
|
+
transferTimer: number;
|
|
83
|
+
transferTimerInterval: number | null;
|
|
84
|
+
bankTransferDetails: BankTransferDetails | null;
|
|
85
|
+
// API response fields
|
|
86
|
+
paymentId: string | null;
|
|
87
|
+
transactionId: string | null;
|
|
88
|
+
transactionRef: string | null;
|
|
89
|
+
eciFlag: string | null;
|
|
90
|
+
otpDeliveryMessage: string | null;
|
|
91
|
+
feeDetails?: {
|
|
92
|
+
transactionFee: number;
|
|
93
|
+
transactionFeeVat: number;
|
|
94
|
+
totalFees: number;
|
|
95
|
+
grossAmount: number;
|
|
96
|
+
currency: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class VoxePayModal {
|
|
101
|
+
private options: CheckoutOptions;
|
|
102
|
+
private state: ModalState;
|
|
103
|
+
private container: HTMLDivElement | null = null;
|
|
104
|
+
private overlay: HTMLDivElement | null = null;
|
|
105
|
+
private apiClient: VoxePayApiClient | null = null;
|
|
106
|
+
|
|
107
|
+
constructor(options: CheckoutOptions) {
|
|
108
|
+
this.options = options;
|
|
109
|
+
const methods = options.paymentMethods || ['card', 'bank_transfer'];
|
|
110
|
+
|
|
111
|
+
// Initialize API client from SDK config
|
|
112
|
+
if (options._sdkConfig) {
|
|
113
|
+
this.apiClient = new VoxePayApiClient(
|
|
114
|
+
options._sdkConfig.apiKey,
|
|
115
|
+
options._sdkConfig.baseUrl
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this.state = {
|
|
120
|
+
cardNumber: '',
|
|
121
|
+
expiry: '',
|
|
122
|
+
cvv: '',
|
|
123
|
+
pin: '',
|
|
124
|
+
otp: '',
|
|
125
|
+
errors: {},
|
|
126
|
+
isProcessing: false,
|
|
127
|
+
isSuccess: false,
|
|
128
|
+
isOtpStep: false,
|
|
129
|
+
otpTimer: 60,
|
|
130
|
+
canResendOtp: false,
|
|
131
|
+
otpTimerInterval: null,
|
|
132
|
+
paymentMethod: methods[0],
|
|
133
|
+
transferTimer: 0,
|
|
134
|
+
transferTimerInterval: null,
|
|
135
|
+
bankTransferDetails: options.bankTransferDetails || null,
|
|
136
|
+
paymentId: null,
|
|
137
|
+
transactionId: null,
|
|
138
|
+
transactionRef: null,
|
|
139
|
+
eciFlag: null,
|
|
140
|
+
otpDeliveryMessage: null,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Open the checkout modal
|
|
146
|
+
*/
|
|
147
|
+
open(): void {
|
|
148
|
+
this.injectStyles();
|
|
149
|
+
this.render();
|
|
150
|
+
this.attachEventListeners();
|
|
151
|
+
|
|
152
|
+
// Trigger open animation
|
|
153
|
+
requestAnimationFrame(() => {
|
|
154
|
+
this.overlay?.classList.add('voxepay-visible');
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Close the checkout modal
|
|
160
|
+
*/
|
|
161
|
+
close(): void {
|
|
162
|
+
this.stopTransferTimer();
|
|
163
|
+
this.stopStatusPolling();
|
|
164
|
+
this.overlay?.classList.remove('voxepay-visible');
|
|
165
|
+
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
this.container?.remove();
|
|
168
|
+
this.container = null;
|
|
169
|
+
this.overlay = null;
|
|
170
|
+
this.options.onClose?.();
|
|
171
|
+
}, 300);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Inject styles if not already present
|
|
176
|
+
*/
|
|
177
|
+
private injectStyles(): void {
|
|
178
|
+
if (document.getElementById('voxepay-checkout-styles')) return;
|
|
179
|
+
|
|
180
|
+
const style = document.createElement('style');
|
|
181
|
+
style.id = 'voxepay-checkout-styles';
|
|
182
|
+
style.textContent = this.getStyles();
|
|
183
|
+
document.head.appendChild(style);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Render the modal HTML
|
|
188
|
+
*/
|
|
189
|
+
private render(): void {
|
|
190
|
+
this.container = document.createElement('div');
|
|
191
|
+
this.container.className = 'voxepay-checkout';
|
|
192
|
+
this.container.innerHTML = this.getModalHTML();
|
|
193
|
+
document.body.appendChild(this.container);
|
|
194
|
+
|
|
195
|
+
this.overlay = this.container.querySelector('.voxepay-overlay');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Get available payment methods
|
|
200
|
+
*/
|
|
201
|
+
private getPaymentMethods(): PaymentMethod[] {
|
|
202
|
+
return this.options.paymentMethods || ['card', 'bank_transfer'];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get modal HTML
|
|
207
|
+
*/
|
|
208
|
+
private getModalHTML(): string {
|
|
209
|
+
const totalPayableKobo = this.options.feeDetails
|
|
210
|
+
? Math.round((this.options.feeDetails.grossAmount + this.options.feeDetails.totalFees) * 100)
|
|
211
|
+
: this.options.amount;
|
|
212
|
+
const formattedAmount = formatAmount(totalPayableKobo, this.options.currency);
|
|
213
|
+
const methods = this.getPaymentMethods();
|
|
214
|
+
const showTabs = methods.length > 1;
|
|
215
|
+
const isCard = this.state.paymentMethod === 'card';
|
|
216
|
+
|
|
217
|
+
return `
|
|
218
|
+
<div class="voxepay-overlay">
|
|
219
|
+
<div class="voxepay-modal" role="dialog" aria-modal="true" aria-labelledby="voxepay-title">
|
|
220
|
+
<div class="voxepay-header">
|
|
221
|
+
<div class="voxepay-header-left">
|
|
222
|
+
<div class="voxepay-logo">V</div>
|
|
223
|
+
<div>
|
|
224
|
+
<div class="voxepay-amount" id="voxepay-title">Pay ${formattedAmount}</div>
|
|
225
|
+
${this.options.description ? `<div style="font-size: 0.875rem; color: var(--voxepay-text-muted);">${this.options.description}</div>` : ''}
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
<button class="voxepay-close" aria-label="Close" data-action="close">
|
|
229
|
+
${ICONS.close}
|
|
230
|
+
</button>
|
|
231
|
+
</div>
|
|
232
|
+
|
|
233
|
+
${showTabs ? `
|
|
234
|
+
<div class="voxepay-method-tabs">
|
|
235
|
+
${methods.includes('card') ? `
|
|
236
|
+
<button class="voxepay-method-tab ${isCard ? 'active' : ''}" data-method="card">
|
|
237
|
+
${ICONS.card} <span>Card</span>
|
|
238
|
+
</button>` : ''}
|
|
239
|
+
${methods.includes('bank_transfer') ? `
|
|
240
|
+
<button class="voxepay-method-tab ${!isCard ? 'active' : ''}" data-method="bank_transfer">
|
|
241
|
+
${ICONS.bank} <span>Bank Transfer</span>
|
|
242
|
+
</button>` : ''}
|
|
243
|
+
</div>` : ''}
|
|
244
|
+
|
|
245
|
+
<div class="voxepay-body" id="voxepay-form-container">
|
|
246
|
+
${isCard ? this.getCardFormHTML(formattedAmount) : this.getBankTransferHTML(formattedAmount)}
|
|
247
|
+
</div>
|
|
248
|
+
|
|
249
|
+
<div class="voxepay-footer">
|
|
250
|
+
<div class="voxepay-powered-by">
|
|
251
|
+
${ICONS.lock}
|
|
252
|
+
<span>Secured by <strong>VoxePay</strong></span>
|
|
253
|
+
</div>
|
|
254
|
+
</div>
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
`;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Get card form HTML
|
|
262
|
+
*/
|
|
263
|
+
private getCardFormHTML(formattedAmount: string): string {
|
|
264
|
+
return `
|
|
265
|
+
<form id="voxepay-payment-form" novalidate>
|
|
266
|
+
<div class="voxepay-form-group">
|
|
267
|
+
<label class="voxepay-label">
|
|
268
|
+
<span class="voxepay-label-icon">💳</span>
|
|
269
|
+
Card Number
|
|
270
|
+
</label>
|
|
271
|
+
<div class="voxepay-card-input-wrapper">
|
|
272
|
+
<input type="text" class="voxepay-input" id="voxepay-card-number" name="cardNumber"
|
|
273
|
+
placeholder="1234 5678 9012 3456" autocomplete="cc-number" inputmode="numeric" />
|
|
274
|
+
<div class="voxepay-card-brand" id="voxepay-card-brand"></div>
|
|
275
|
+
</div>
|
|
276
|
+
<div class="voxepay-error-message" id="voxepay-card-error" style="display: none;"></div>
|
|
277
|
+
</div>
|
|
278
|
+
|
|
279
|
+
<div class="voxepay-row">
|
|
280
|
+
<div class="voxepay-form-group">
|
|
281
|
+
<label class="voxepay-label"><span class="voxepay-label-icon">📅</span> Expiry</label>
|
|
282
|
+
<input type="text" class="voxepay-input" id="voxepay-expiry" name="expiry"
|
|
283
|
+
placeholder="MM/YY" autocomplete="cc-exp" inputmode="numeric" maxlength="5" />
|
|
284
|
+
<div class="voxepay-error-message" id="voxepay-expiry-error" style="display: none;"></div>
|
|
285
|
+
</div>
|
|
286
|
+
<div class="voxepay-form-group">
|
|
287
|
+
<label class="voxepay-label"><span class="voxepay-label-icon">🔒</span> CVV</label>
|
|
288
|
+
<input type="text" class="voxepay-input" id="voxepay-cvv" name="cvv"
|
|
289
|
+
placeholder="•••" autocomplete="cc-csc" inputmode="numeric" maxlength="4" />
|
|
290
|
+
<div class="voxepay-error-message" id="voxepay-cvv-error" style="display: none;"></div>
|
|
291
|
+
</div>
|
|
292
|
+
<div class="voxepay-form-group">
|
|
293
|
+
<label class="voxepay-label"><span class="voxepay-label-icon">🔑</span> PIN</label>
|
|
294
|
+
<input type="password" class="voxepay-input" id="voxepay-pin" name="pin"
|
|
295
|
+
placeholder="••••" autocomplete="current-password" inputmode="numeric" maxlength="4" />
|
|
296
|
+
<div class="voxepay-error-message" id="voxepay-pin-error" style="display: none;"></div>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
<div class="voxepay-sticky-actions">
|
|
300
|
+
<button type="submit" class="voxepay-submit-btn" id="voxepay-submit">
|
|
301
|
+
<span>Pay Now ${formattedAmount}</span>
|
|
302
|
+
</button>
|
|
303
|
+
</div>
|
|
304
|
+
</form>
|
|
305
|
+
`;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Get bank transfer HTML
|
|
310
|
+
*/
|
|
311
|
+
private getBankTransferHTML(formattedAmount: string): string {
|
|
312
|
+
const details = this.state.bankTransferDetails;
|
|
313
|
+
|
|
314
|
+
if (!details) {
|
|
315
|
+
return `
|
|
316
|
+
<div class="voxepay-transfer-view">
|
|
317
|
+
<div class="voxepay-transfer-loading">
|
|
318
|
+
<div class="voxepay-spinner"></div>
|
|
319
|
+
<p style="margin-top: 16px; color: var(--voxepay-text-muted);">Generating account details...</p>
|
|
320
|
+
</div>
|
|
321
|
+
</div>
|
|
322
|
+
`;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
let displayAmount = formattedAmount;
|
|
326
|
+
let feeBreakdown = '';
|
|
327
|
+
|
|
328
|
+
if (details.feeDetails && details.totalPayableAmount !== undefined) {
|
|
329
|
+
displayAmount = formatMainUnitAmount(details.totalPayableAmount, details.feeDetails.currency);
|
|
330
|
+
feeBreakdown = `
|
|
331
|
+
<div style="border-top: 1px dashed var(--voxepay-border); padding-top: 8px; margin-top: 8px; display: flex; flex-direction: column; gap: 4px;">
|
|
332
|
+
<div style="display: flex; justify-content: space-between; width: 100%; font-size: 0.85rem; color: var(--voxepay-text-muted);">
|
|
333
|
+
<span>Amount</span>
|
|
334
|
+
<span>${formatMainUnitAmount(details.feeDetails.grossAmount, details.feeDetails.currency)}</span>
|
|
335
|
+
</div>
|
|
336
|
+
<div style="display: flex; justify-content: space-between; width: 100%; font-size: 0.85rem; color: var(--voxepay-text-muted);">
|
|
337
|
+
<span>Fee</span>
|
|
338
|
+
<span>${formatMainUnitAmount(details.feeDetails.totalFees, details.feeDetails.currency)}</span>
|
|
339
|
+
</div>
|
|
340
|
+
</div>
|
|
341
|
+
`;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return `
|
|
345
|
+
<div class="voxepay-transfer-view">
|
|
346
|
+
<div class="voxepay-transfer-instruction">
|
|
347
|
+
<p>Transfer <strong>${displayAmount}</strong> to the account below</p>
|
|
348
|
+
</div>
|
|
349
|
+
|
|
350
|
+
<div class="voxepay-transfer-details">
|
|
351
|
+
<div class="voxepay-transfer-detail">
|
|
352
|
+
<span class="voxepay-transfer-label">Account Number</span>
|
|
353
|
+
<div class="voxepay-transfer-value-row">
|
|
354
|
+
<span class="voxepay-transfer-value voxepay-transfer-account" id="voxepay-account-number">${details.accountNumber}</span>
|
|
355
|
+
<button class="voxepay-copy-btn" id="voxepay-copy-btn" data-copy="${details.accountNumber}" title="Copy">
|
|
356
|
+
${ICONS.copy}
|
|
357
|
+
</button>
|
|
358
|
+
</div>
|
|
359
|
+
</div>
|
|
360
|
+
|
|
361
|
+
<div class="voxepay-transfer-detail">
|
|
362
|
+
<span class="voxepay-transfer-label">Bank Name</span>
|
|
363
|
+
<span class="voxepay-transfer-value">${details.bankName}</span>
|
|
364
|
+
</div>
|
|
365
|
+
|
|
366
|
+
<div class="voxepay-transfer-detail">
|
|
367
|
+
<span class="voxepay-transfer-label">Account Name</span>
|
|
368
|
+
<span class="voxepay-transfer-value">${details.accountName}</span>
|
|
369
|
+
</div>
|
|
370
|
+
|
|
371
|
+
<div class="voxepay-transfer-detail">
|
|
372
|
+
<span class="voxepay-transfer-label">Total Amount</span>
|
|
373
|
+
<span class="voxepay-transfer-value voxepay-transfer-amount">${displayAmount}</span>
|
|
374
|
+
</div>
|
|
375
|
+
${feeBreakdown}
|
|
376
|
+
|
|
377
|
+
<div class="voxepay-transfer-detail">
|
|
378
|
+
<span class="voxepay-transfer-label">Reference</span>
|
|
379
|
+
<span class="voxepay-transfer-value" style="font-family: monospace; letter-spacing: 1px;">${details.reference}</span>
|
|
380
|
+
</div>
|
|
381
|
+
</div>
|
|
382
|
+
|
|
383
|
+
<div class="voxepay-transfer-timer" id="voxepay-transfer-timer">
|
|
384
|
+
${ICONS.clock}
|
|
385
|
+
<span>Account expires in <strong id="voxepay-transfer-countdown">${this.formatCountdown(details.expiresIn)}</strong></span>
|
|
386
|
+
</div>
|
|
387
|
+
|
|
388
|
+
<div style="margin: 16px 0; padding: 12px; background: rgba(0, 97, 255, 0.05); border: 1px solid var(--voxepay-primary); border-radius: 8px; display: flex; gap: 12px; align-items: flex-start;">
|
|
389
|
+
<div style="color: var(--voxepay-primary); flex-shrink: 0; margin-top: 2px;">
|
|
390
|
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" width="20" height="20">
|
|
391
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
392
|
+
</svg>
|
|
393
|
+
</div>
|
|
394
|
+
<p style="font-size: 0.85rem; color: var(--voxepay-text); margin: 0; line-height: 1.4;">
|
|
395
|
+
<strong>Important Note:</strong> Please include <strong>${details.reference}</strong> as the narration or remark on your bank app to ensure your payment is confirmed instantly.
|
|
396
|
+
</p>
|
|
397
|
+
</div>
|
|
398
|
+
<div class="voxepay-sticky-actions">
|
|
399
|
+
<button type="button" class="voxepay-submit-btn" id="voxepay-transfer-confirm">
|
|
400
|
+
<span>🔐 Verify & Pay</span>
|
|
401
|
+
</button>
|
|
402
|
+
</div>
|
|
403
|
+
</div>
|
|
404
|
+
`;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Format countdown seconds to MM:SS
|
|
409
|
+
*/
|
|
410
|
+
private formatCountdown(seconds: number): string {
|
|
411
|
+
const m = Math.floor(seconds / 60);
|
|
412
|
+
const s = seconds % 60;
|
|
413
|
+
return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Render success view
|
|
418
|
+
*/
|
|
419
|
+
private renderSuccessView(): void {
|
|
420
|
+
const formContainer = this.container?.querySelector('#voxepay-form-container');
|
|
421
|
+
if (!formContainer) return;
|
|
422
|
+
|
|
423
|
+
const formattedAmount = formatAmount(this.options.amount, this.options.currency);
|
|
424
|
+
|
|
425
|
+
formContainer.innerHTML = `
|
|
426
|
+
<div class="voxepay-success-view">
|
|
427
|
+
<div class="voxepay-success-icon">
|
|
428
|
+
${ICONS.check}
|
|
429
|
+
</div>
|
|
430
|
+
<h2 class="voxepay-success-title">Payment Successful!</h2>
|
|
431
|
+
<p class="voxepay-success-message">Your payment of ${formattedAmount} has been processed.</p>
|
|
432
|
+
<button class="voxepay-success-btn" data-action="close">Done</button>
|
|
433
|
+
</div>
|
|
434
|
+
`;
|
|
435
|
+
|
|
436
|
+
// Re-attach close listener
|
|
437
|
+
const closeBtn = formContainer.querySelector('[data-action="close"]');
|
|
438
|
+
closeBtn?.addEventListener('click', () => this.close());
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Render error modal view
|
|
443
|
+
*/
|
|
444
|
+
private renderErrorModal(code: string, message: string, recoverable: boolean): void {
|
|
445
|
+
const formContainer = this.container?.querySelector('#voxepay-form-container');
|
|
446
|
+
if (!formContainer) return;
|
|
447
|
+
|
|
448
|
+
const isRetryable = recoverable && this.state.paymentMethod === 'card';
|
|
449
|
+
|
|
450
|
+
formContainer.innerHTML = `
|
|
451
|
+
<div class="voxepay-error-view">
|
|
452
|
+
<div class="voxepay-error-icon-large">
|
|
453
|
+
${ICONS.error}
|
|
454
|
+
</div>
|
|
455
|
+
<h2 class="voxepay-error-title">Payment Failed</h2>
|
|
456
|
+
<p class="voxepay-error-message">${message}</p>
|
|
457
|
+
${code ? `<p class="voxepay-error-code">Error code: ${code}</p>` : ''}
|
|
458
|
+
<div class="voxepay-error-actions">
|
|
459
|
+
${isRetryable ? `
|
|
460
|
+
<button class="voxepay-submit-btn" id="voxepay-retry-btn">
|
|
461
|
+
<span>Try Again</span>
|
|
462
|
+
</button>
|
|
463
|
+
` : ''}
|
|
464
|
+
<button class="voxepay-back-btn" id="voxepay-error-close-btn">
|
|
465
|
+
${isRetryable ? 'Cancel' : 'Close'}
|
|
466
|
+
</button>
|
|
467
|
+
</div>
|
|
468
|
+
</div>
|
|
469
|
+
`;
|
|
470
|
+
|
|
471
|
+
// Attach listeners
|
|
472
|
+
const retryBtn = formContainer.querySelector('#voxepay-retry-btn');
|
|
473
|
+
retryBtn?.addEventListener('click', () => this.handleBackToCard());
|
|
474
|
+
|
|
475
|
+
const closeBtn = formContainer.querySelector('#voxepay-error-close-btn');
|
|
476
|
+
closeBtn?.addEventListener('click', () => this.close());
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Show error — inline for field errors, modal for fatal errors
|
|
481
|
+
*/
|
|
482
|
+
private showErrorModal(code: string, message: string, recoverable: boolean): void {
|
|
483
|
+
this.renderErrorModal(code, message, recoverable);
|
|
484
|
+
this.options.onError({ code, message, recoverable });
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Render OTP verification view
|
|
489
|
+
*/
|
|
490
|
+
private renderOTPView(): void {
|
|
491
|
+
const formContainer = this.container?.querySelector('#voxepay-form-container');
|
|
492
|
+
if (!formContainer) return;
|
|
493
|
+
|
|
494
|
+
this.state.isOtpStep = true;
|
|
495
|
+
this.state.otpTimer = 60;
|
|
496
|
+
this.state.canResendOtp = false;
|
|
497
|
+
|
|
498
|
+
// Use backend message if available (e.g. "Kindly enter the OTP sent to **********2888")
|
|
499
|
+
const subtitle = this.state.otpDeliveryMessage
|
|
500
|
+
? this.state.otpDeliveryMessage
|
|
501
|
+
: (() => {
|
|
502
|
+
const sentToPhone = this.options.customerPhone && (
|
|
503
|
+
!this.state.otpDeliveryMessage || this.state.otpDeliveryMessage.toLowerCase().includes('phone')
|
|
504
|
+
);
|
|
505
|
+
const maskedDestination = sentToPhone
|
|
506
|
+
? `****${(this.options.customerPhone ?? '').slice(-4)}`
|
|
507
|
+
: this.options.customerEmail
|
|
508
|
+
? `****${this.options.customerEmail.slice(-4)}`
|
|
509
|
+
: '****';
|
|
510
|
+
const destinationLabel = sentToPhone ? 'phone number' : 'email';
|
|
511
|
+
return `We've sent a 6-digit code to your ${destinationLabel} ending in <strong>${maskedDestination}</strong>`;
|
|
512
|
+
})();
|
|
513
|
+
|
|
514
|
+
let feeBreakdownHTML = '';
|
|
515
|
+
if (this.state.feeDetails) {
|
|
516
|
+
const totalAmount = this.state.feeDetails.grossAmount + this.state.feeDetails.totalFees;
|
|
517
|
+
|
|
518
|
+
const titleEl = this.container?.querySelector('#voxepay-title');
|
|
519
|
+
if (titleEl) {
|
|
520
|
+
titleEl.textContent = `Pay ${formatMainUnitAmount(totalAmount, this.state.feeDetails.currency)}`;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
feeBreakdownHTML = `
|
|
524
|
+
<div style="margin: 16px 0; padding: 12px; background: var(--voxepay-surface); border-radius: 8px; border: 1px solid var(--voxepay-border);">
|
|
525
|
+
<div style="display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 0.85rem; color: var(--voxepay-text-muted);">
|
|
526
|
+
<span>Amount</span>
|
|
527
|
+
<span>${formatMainUnitAmount(this.state.feeDetails.grossAmount, this.state.feeDetails.currency)}</span>
|
|
528
|
+
</div>
|
|
529
|
+
<div style="display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.85rem; color: var(--voxepay-text-muted);">
|
|
530
|
+
<span>Fee</span>
|
|
531
|
+
<span>${formatMainUnitAmount(this.state.feeDetails.totalFees, this.state.feeDetails.currency)}</span>
|
|
532
|
+
</div>
|
|
533
|
+
<div style="display: flex; justify-content: space-between; border-top: 1px solid var(--voxepay-border); padding-top: 8px; font-weight: 600;">
|
|
534
|
+
<span>Total Payable</span>
|
|
535
|
+
<span>${formatMainUnitAmount(totalAmount, this.state.feeDetails.currency)}</span>
|
|
536
|
+
</div>
|
|
537
|
+
</div>
|
|
538
|
+
`;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
formContainer.innerHTML = `
|
|
542
|
+
<div class="voxepay-otp-view">
|
|
543
|
+
<div class="voxepay-otp-header">
|
|
544
|
+
<div class="voxepay-otp-icon">📱</div>
|
|
545
|
+
<h3 class="voxepay-otp-title">Verify Your Payment</h3>
|
|
546
|
+
<p class="voxepay-otp-subtitle">${subtitle}</p>
|
|
547
|
+
</div>
|
|
548
|
+
${feeBreakdownHTML}
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
<div class="voxepay-otp-inputs-container">
|
|
552
|
+
<div class="voxepay-otp-inputs" id="voxepay-otp-inputs">
|
|
553
|
+
<input type="text" maxlength="1" class="voxepay-otp-digit" data-index="0" inputmode="numeric" autocomplete="one-time-code" />
|
|
554
|
+
<input type="text" maxlength="1" class="voxepay-otp-digit" data-index="1" inputmode="numeric" />
|
|
555
|
+
<input type="text" maxlength="1" class="voxepay-otp-digit" data-index="2" inputmode="numeric" />
|
|
556
|
+
<input type="text" maxlength="1" class="voxepay-otp-digit" data-index="3" inputmode="numeric" />
|
|
557
|
+
<input type="text" maxlength="1" class="voxepay-otp-digit" data-index="4" inputmode="numeric" />
|
|
558
|
+
<input type="text" maxlength="1" class="voxepay-otp-digit" data-index="5" inputmode="numeric" />
|
|
559
|
+
</div>
|
|
560
|
+
<div class="voxepay-error-message" id="voxepay-otp-error" style="display: none;"></div>
|
|
561
|
+
</div>
|
|
562
|
+
|
|
563
|
+
<div class="voxepay-otp-timer" id="voxepay-otp-timer">
|
|
564
|
+
Resend code in <span id="voxepay-timer-count">60</span>s
|
|
565
|
+
</div>
|
|
566
|
+
<div class="voxepay-sticky-actions">
|
|
567
|
+
<button class="voxepay-resend-btn" id="voxepay-resend-otp" disabled>
|
|
568
|
+
Resend OTP
|
|
569
|
+
</button>
|
|
570
|
+
|
|
571
|
+
<button type="button" class="voxepay-submit-btn" id="voxepay-verify-otp">
|
|
572
|
+
<span>✓ Confirm OTP</span>
|
|
573
|
+
</button>
|
|
574
|
+
|
|
575
|
+
<button class="voxepay-back-btn" id="voxepay-back-to-card">
|
|
576
|
+
← Back to card details
|
|
577
|
+
</button>
|
|
578
|
+
</div>
|
|
579
|
+
</div>
|
|
580
|
+
`;
|
|
581
|
+
|
|
582
|
+
this.attachOTPEventListeners();
|
|
583
|
+
this.startOTPTimer();
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Attach OTP-specific event listeners
|
|
588
|
+
*/
|
|
589
|
+
private attachOTPEventListeners(): void {
|
|
590
|
+
const otpInputs = this.container?.querySelectorAll('.voxepay-otp-digit') as NodeListOf<HTMLInputElement>;
|
|
591
|
+
|
|
592
|
+
otpInputs?.forEach((input, index) => {
|
|
593
|
+
input.addEventListener('input', (e) => this.handleOTPInput(e, index));
|
|
594
|
+
input.addEventListener('keydown', (e) => this.handleOTPKeydown(e, index));
|
|
595
|
+
input.addEventListener('paste', (e) => this.handleOTPPaste(e));
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
const verifyBtn = this.container?.querySelector('#voxepay-verify-otp');
|
|
599
|
+
verifyBtn?.addEventListener('click', () => this.handleOTPSubmit());
|
|
600
|
+
|
|
601
|
+
const resendBtn = this.container?.querySelector('#voxepay-resend-otp');
|
|
602
|
+
resendBtn?.addEventListener('click', () => this.handleResendOTP());
|
|
603
|
+
|
|
604
|
+
const backBtn = this.container?.querySelector('#voxepay-back-to-card');
|
|
605
|
+
backBtn?.addEventListener('click', () => this.handleBackToCard());
|
|
606
|
+
|
|
607
|
+
(otpInputs?.[0] as HTMLInputElement)?.focus();
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
private handleOTPInput(e: Event, index: number): void {
|
|
611
|
+
const input = e.target as HTMLInputElement;
|
|
612
|
+
const value = input.value.replace(/\D/g, '');
|
|
613
|
+
input.value = value;
|
|
614
|
+
|
|
615
|
+
if (value && index < 5) {
|
|
616
|
+
const nextInput = this.container?.querySelector(`[data-index="${index + 1}"]`) as HTMLInputElement;
|
|
617
|
+
nextInput?.focus();
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
this.updateOTPState();
|
|
621
|
+
this.clearError('otp');
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
private handleOTPKeydown(e: KeyboardEvent, index: number): void {
|
|
625
|
+
const input = e.target as HTMLInputElement;
|
|
626
|
+
|
|
627
|
+
if (e.key === 'Backspace' && !input.value && index > 0) {
|
|
628
|
+
const prevInput = this.container?.querySelector(`[data-index="${index - 1}"]`) as HTMLInputElement;
|
|
629
|
+
prevInput?.focus();
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
private handleOTPPaste(e: ClipboardEvent): void {
|
|
634
|
+
e.preventDefault();
|
|
635
|
+
const pastedData = e.clipboardData?.getData('text').replace(/\D/g, '').slice(0, 6);
|
|
636
|
+
|
|
637
|
+
if (pastedData) {
|
|
638
|
+
const inputs = this.container?.querySelectorAll('.voxepay-otp-digit') as NodeListOf<HTMLInputElement>;
|
|
639
|
+
pastedData.split('').forEach((digit, i) => {
|
|
640
|
+
if (inputs[i]) {
|
|
641
|
+
inputs[i].value = digit;
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
this.updateOTPState();
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
private updateOTPState(): void {
|
|
649
|
+
const inputs = this.container?.querySelectorAll('.voxepay-otp-digit') as NodeListOf<HTMLInputElement>;
|
|
650
|
+
let otp = '';
|
|
651
|
+
inputs?.forEach(input => otp += input.value);
|
|
652
|
+
this.state.otp = otp;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
private startOTPTimer(): void {
|
|
656
|
+
const timerEl = this.container?.querySelector('#voxepay-timer-count');
|
|
657
|
+
const timerContainer = this.container?.querySelector('#voxepay-otp-timer');
|
|
658
|
+
const resendBtn = this.container?.querySelector('#voxepay-resend-otp') as HTMLButtonElement;
|
|
659
|
+
|
|
660
|
+
this.state.otpTimerInterval = window.setInterval(() => {
|
|
661
|
+
this.state.otpTimer--;
|
|
662
|
+
|
|
663
|
+
if (timerEl) {
|
|
664
|
+
timerEl.textContent = String(this.state.otpTimer);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (this.state.otpTimer <= 0) {
|
|
668
|
+
if (this.state.otpTimerInterval) {
|
|
669
|
+
clearInterval(this.state.otpTimerInterval);
|
|
670
|
+
}
|
|
671
|
+
this.state.canResendOtp = true;
|
|
672
|
+
if (timerContainer) (timerContainer as HTMLElement).style.display = 'none';
|
|
673
|
+
if (resendBtn) resendBtn.disabled = false;
|
|
674
|
+
}
|
|
675
|
+
}, 1000);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
private async handleOTPSubmit(): Promise<void> {
|
|
679
|
+
if (this.state.otp.length !== 6) {
|
|
680
|
+
this.showError('otp', 'Please enter the complete 6-digit code');
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
this.setOTPProcessing(true);
|
|
685
|
+
|
|
686
|
+
try {
|
|
687
|
+
await this.verifyOTP();
|
|
688
|
+
|
|
689
|
+
if (this.state.otpTimerInterval) {
|
|
690
|
+
clearInterval(this.state.otpTimerInterval);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
const result = await this.processPayment();
|
|
694
|
+
|
|
695
|
+
this.state.isSuccess = true;
|
|
696
|
+
this.renderSuccessView();
|
|
697
|
+
this.options.onSuccess(result);
|
|
698
|
+
} catch (error) {
|
|
699
|
+
this.setOTPProcessing(false);
|
|
700
|
+
const paymentError = error as PaymentError;
|
|
701
|
+
const code = paymentError.code || 'OTP_VALIDATION_FAILED';
|
|
702
|
+
const message = paymentError.message || 'Invalid OTP. Please try again.';
|
|
703
|
+
const recoverable = paymentError.recoverable !== false;
|
|
704
|
+
if (recoverable) {
|
|
705
|
+
this.showError('otp', message);
|
|
706
|
+
} else {
|
|
707
|
+
this.showErrorModal(code, message, false);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
private setOTPProcessing(isProcessing: boolean): void {
|
|
713
|
+
const verifyBtn = this.container?.querySelector('#voxepay-verify-otp') as HTMLButtonElement;
|
|
714
|
+
|
|
715
|
+
if (verifyBtn) {
|
|
716
|
+
verifyBtn.disabled = isProcessing;
|
|
717
|
+
verifyBtn.innerHTML = isProcessing
|
|
718
|
+
? '<div class="voxepay-spinner"></div><span>Verifying...</span>'
|
|
719
|
+
: '<span>✓ Confirm OTP</span>';
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
private async verifyOTP(): Promise<void> {
|
|
724
|
+
if (!this.apiClient || !this.options._sdkConfig) {
|
|
725
|
+
throw { code: 'SDK_ERROR', message: 'SDK not properly initialized', recoverable: false };
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
if (this.state.otp.length !== 6) {
|
|
729
|
+
throw { code: 'INVALID_OTP', message: 'Please enter the complete 6-digit code', recoverable: true };
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
if (!this.state.paymentId || !this.state.transactionRef) {
|
|
733
|
+
throw { code: 'MISSING_PAYMENT_DATA', message: 'Payment session expired. Please try again.', recoverable: false };
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
await this.apiClient.validateOTP(this.options._sdkConfig.paymentLinkSlug!, {
|
|
737
|
+
paymentId: this.state.paymentId, // data.id UUID from /pay response
|
|
738
|
+
otp: this.state.otp,
|
|
739
|
+
transactionId: this.state.transactionRef, // same as transactionRef
|
|
740
|
+
transactionRef: this.state.transactionRef,
|
|
741
|
+
eciFlag: this.state.eciFlag || undefined,
|
|
742
|
+
organizationId: this.options._sdkConfig.organizationId,
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
private async handleResendOTP(): Promise<void> {
|
|
747
|
+
const timerContainer = this.container?.querySelector('#voxepay-otp-timer') as HTMLElement;
|
|
748
|
+
const resendBtn = this.container?.querySelector('#voxepay-resend-otp') as HTMLButtonElement;
|
|
749
|
+
|
|
750
|
+
// Call resend OTP API
|
|
751
|
+
if (this.apiClient && this.options._sdkConfig && this.state.transactionRef) {
|
|
752
|
+
try {
|
|
753
|
+
if (resendBtn) resendBtn.disabled = true;
|
|
754
|
+
await this.apiClient.resendOTP(this.options._sdkConfig.paymentLinkSlug!, {
|
|
755
|
+
transactionRef: this.state.transactionRef,
|
|
756
|
+
organizationId: this.options._sdkConfig.organizationId,
|
|
757
|
+
});
|
|
758
|
+
} catch (error: any) {
|
|
759
|
+
console.error('[VoxePay] Failed to resend OTP:', error);
|
|
760
|
+
// Continue with timer reset even if API fails
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
this.state.otpTimer = 60;
|
|
765
|
+
this.state.canResendOtp = false;
|
|
766
|
+
|
|
767
|
+
if (timerContainer) timerContainer.style.display = 'block';
|
|
768
|
+
if (resendBtn) resendBtn.disabled = true;
|
|
769
|
+
|
|
770
|
+
const inputs = this.container?.querySelectorAll('.voxepay-otp-digit') as NodeListOf<HTMLInputElement>;
|
|
771
|
+
inputs?.forEach(input => input.value = '');
|
|
772
|
+
this.state.otp = '';
|
|
773
|
+
|
|
774
|
+
this.startOTPTimer();
|
|
775
|
+
(inputs?.[0] as HTMLInputElement)?.focus();
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
private handleBackToCard(): void {
|
|
779
|
+
if (this.state.otpTimerInterval) {
|
|
780
|
+
clearInterval(this.state.otpTimerInterval);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
this.state.isOtpStep = false;
|
|
784
|
+
this.state.otp = '';
|
|
785
|
+
|
|
786
|
+
if (this.container) {
|
|
787
|
+
this.container.innerHTML = this.getModalHTML();
|
|
788
|
+
this.overlay = this.container.querySelector('.voxepay-overlay');
|
|
789
|
+
this.overlay?.classList.add('voxepay-visible');
|
|
790
|
+
this.attachEventListeners();
|
|
791
|
+
|
|
792
|
+
const cardInput = this.container.querySelector('#voxepay-card-number') as HTMLInputElement;
|
|
793
|
+
const expiryInput = this.container.querySelector('#voxepay-expiry') as HTMLInputElement;
|
|
794
|
+
const cvvInput = this.container.querySelector('#voxepay-cvv') as HTMLInputElement;
|
|
795
|
+
const pinInput = this.container.querySelector('#voxepay-pin') as HTMLInputElement;
|
|
796
|
+
|
|
797
|
+
if (cardInput) cardInput.value = formatCardNumber(this.state.cardNumber);
|
|
798
|
+
if (expiryInput) expiryInput.value = this.state.expiry;
|
|
799
|
+
if (cvvInput) cvvInput.value = this.state.cvv;
|
|
800
|
+
if (pinInput) pinInput.value = this.state.pin;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Attach event listeners
|
|
806
|
+
*/
|
|
807
|
+
private attachEventListeners(): void {
|
|
808
|
+
const closeBtn = this.container?.querySelector('[data-action="close"]');
|
|
809
|
+
closeBtn?.addEventListener('click', () => this.close());
|
|
810
|
+
|
|
811
|
+
this.overlay?.addEventListener('click', (e) => {
|
|
812
|
+
if (e.target === this.overlay) {
|
|
813
|
+
this.close();
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
document.addEventListener('keydown', this.handleEscape);
|
|
818
|
+
|
|
819
|
+
// Payment method tabs
|
|
820
|
+
const tabs = this.container?.querySelectorAll('.voxepay-method-tab');
|
|
821
|
+
tabs?.forEach(tab => {
|
|
822
|
+
tab.addEventListener('click', () => {
|
|
823
|
+
const method = (tab as HTMLElement).dataset.method as PaymentMethod;
|
|
824
|
+
if (method && method !== this.state.paymentMethod) {
|
|
825
|
+
this.switchPaymentMethod(method);
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
// Card-specific listeners
|
|
831
|
+
if (this.state.paymentMethod === 'card') {
|
|
832
|
+
const cardInput = this.container?.querySelector('#voxepay-card-number') as HTMLInputElement;
|
|
833
|
+
cardInput?.addEventListener('input', (e) => this.handleCardInput(e));
|
|
834
|
+
cardInput?.addEventListener('blur', () => this.validateField('cardNumber'));
|
|
835
|
+
|
|
836
|
+
const expiryInput = this.container?.querySelector('#voxepay-expiry') as HTMLInputElement;
|
|
837
|
+
expiryInput?.addEventListener('input', (e) => this.handleExpiryInput(e));
|
|
838
|
+
expiryInput?.addEventListener('blur', () => this.validateField('expiry'));
|
|
839
|
+
|
|
840
|
+
const cvvInput = this.container?.querySelector('#voxepay-cvv') as HTMLInputElement;
|
|
841
|
+
cvvInput?.addEventListener('input', (e) => this.handleCVVInput(e));
|
|
842
|
+
cvvInput?.addEventListener('blur', () => this.validateField('cvv'));
|
|
843
|
+
|
|
844
|
+
const pinInput = this.container?.querySelector('#voxepay-pin') as HTMLInputElement;
|
|
845
|
+
pinInput?.addEventListener('input', (e) => this.handlePinInput(e));
|
|
846
|
+
pinInput?.addEventListener('blur', () => this.validateField('pin'));
|
|
847
|
+
|
|
848
|
+
const form = this.container?.querySelector('#voxepay-payment-form') as HTMLFormElement;
|
|
849
|
+
form?.addEventListener('submit', (e) => this.handleSubmit(e));
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// Bank transfer-specific listeners
|
|
853
|
+
if (this.state.paymentMethod === 'bank_transfer') {
|
|
854
|
+
this.attachBankTransferListeners();
|
|
855
|
+
|
|
856
|
+
// If no details yet, load them
|
|
857
|
+
if (!this.state.bankTransferDetails) {
|
|
858
|
+
this.loadBankTransferDetails();
|
|
859
|
+
} else {
|
|
860
|
+
this.startTransferTimer();
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Attach bank transfer specific event listeners
|
|
867
|
+
*/
|
|
868
|
+
private attachBankTransferListeners(): void {
|
|
869
|
+
const copyBtn = this.container?.querySelector('#voxepay-copy-btn');
|
|
870
|
+
copyBtn?.addEventListener('click', () => {
|
|
871
|
+
const accountNum = (copyBtn as HTMLElement).dataset.copy || '';
|
|
872
|
+
this.copyToClipboard(accountNum);
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
const confirmBtn = this.container?.querySelector('#voxepay-transfer-confirm');
|
|
876
|
+
confirmBtn?.addEventListener('click', () => this.handleTransferConfirm());
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Switch between payment methods
|
|
881
|
+
*/
|
|
882
|
+
private switchPaymentMethod(method: PaymentMethod): void {
|
|
883
|
+
this.stopTransferTimer();
|
|
884
|
+
this.state.paymentMethod = method;
|
|
885
|
+
|
|
886
|
+
// Re-render the whole modal
|
|
887
|
+
if (this.container) {
|
|
888
|
+
this.container.innerHTML = this.getModalHTML();
|
|
889
|
+
this.overlay = this.container.querySelector('.voxepay-overlay');
|
|
890
|
+
this.overlay?.classList.add('voxepay-visible');
|
|
891
|
+
this.attachEventListeners();
|
|
892
|
+
|
|
893
|
+
// Restore card values if switching back to card
|
|
894
|
+
if (method === 'card' && this.state.cardNumber) {
|
|
895
|
+
const cardInput = this.container.querySelector('#voxepay-card-number') as HTMLInputElement;
|
|
896
|
+
const expiryInput = this.container.querySelector('#voxepay-expiry') as HTMLInputElement;
|
|
897
|
+
const cvvInput = this.container.querySelector('#voxepay-cvv') as HTMLInputElement;
|
|
898
|
+
const pinInput = this.container.querySelector('#voxepay-pin') as HTMLInputElement;
|
|
899
|
+
if (cardInput) cardInput.value = formatCardNumber(this.state.cardNumber);
|
|
900
|
+
if (expiryInput) expiryInput.value = this.state.expiry;
|
|
901
|
+
if (cvvInput) cvvInput.value = this.state.cvv;
|
|
902
|
+
if (pinInput) pinInput.value = this.state.pin;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Load bank transfer details (from callback or via API)
|
|
909
|
+
*/
|
|
910
|
+
private async loadBankTransferDetails(): Promise<void> {
|
|
911
|
+
try {
|
|
912
|
+
let details: BankTransferDetails;
|
|
913
|
+
|
|
914
|
+
if (this.options.onBankTransferRequested) {
|
|
915
|
+
// Use merchant-provided callback
|
|
916
|
+
details = await this.options.onBankTransferRequested();
|
|
917
|
+
} else if (this.apiClient && this.options._sdkConfig) {
|
|
918
|
+
if (!this.options._sdkConfig.paymentLinkSlug) {
|
|
919
|
+
throw {
|
|
920
|
+
code: 'MISSING_PAYMENT_LINK_SLUG',
|
|
921
|
+
message: 'paymentLinkSlug is required in VoxePay.init() for bank transfer.',
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// Call real DVA API
|
|
926
|
+
const transactionRef = `VP-${Date.now().toString(36).toUpperCase()}-${Math.random().toString(36).substring(2, 8).toUpperCase()}`;
|
|
927
|
+
|
|
928
|
+
const response = await this.apiClient.initiateTransferPayment(
|
|
929
|
+
this.options._sdkConfig.paymentLinkSlug,
|
|
930
|
+
{
|
|
931
|
+
organizationId: this.options._sdkConfig.organizationId,
|
|
932
|
+
transactionRef,
|
|
933
|
+
customerId: this.options.customerEmail || '',
|
|
934
|
+
customerEmail: this.options.customerEmail,
|
|
935
|
+
customerPhone: this.options.customerPhone,
|
|
936
|
+
customerName: this.options.customerName,
|
|
937
|
+
amount: this.options.amount / 100,
|
|
938
|
+
currency: this.options.currency,
|
|
939
|
+
paymentMethod: 'BANK_TRANSFER',
|
|
940
|
+
authData: btoa(JSON.stringify({ source: 'web', method: 'bank_transfer' })),
|
|
941
|
+
narration: this.options.description,
|
|
942
|
+
durationMinutes: 30,
|
|
943
|
+
}
|
|
944
|
+
);
|
|
945
|
+
|
|
946
|
+
// Store transaction ref for status polling
|
|
947
|
+
// API may return 'id' (DVA) or 'paymentId' (card) depending on payment method
|
|
948
|
+
this.state.transactionRef = response.transactionRef || transactionRef;
|
|
949
|
+
this.state.paymentId = response.paymentId || (response as any).id || null;
|
|
950
|
+
|
|
951
|
+
const va = response.virtualAccount;
|
|
952
|
+
if (!va) {
|
|
953
|
+
throw { code: 'MISSING_VIRTUAL_ACCOUNT', message: 'No virtual account returned from server.' };
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// Compute expiresIn from the ISO timestamp
|
|
957
|
+
const expiresAtDate = new Date(va.expires_at);
|
|
958
|
+
const nowMs = Date.now();
|
|
959
|
+
const expiresInSeconds = Math.max(0, Math.floor((expiresAtDate.getTime() - nowMs) / 1000));
|
|
960
|
+
|
|
961
|
+
details = {
|
|
962
|
+
accountNumber: va.account_number,
|
|
963
|
+
bankName: va.bank_name,
|
|
964
|
+
accountName: va.account_name,
|
|
965
|
+
reference: this.state.transactionRef!,
|
|
966
|
+
expiresIn: expiresInSeconds,
|
|
967
|
+
expiresAt: va.expires_at,
|
|
968
|
+
feeDetails: response.feeDetails,
|
|
969
|
+
totalPayableAmount: response.feeDetails ? (response.feeDetails.grossAmount + response.feeDetails.totalFees) : undefined,
|
|
970
|
+
};
|
|
971
|
+
} else {
|
|
972
|
+
throw { code: 'SDK_ERROR', message: 'SDK not properly initialized. Missing required organizationId.' };
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
this.state.bankTransferDetails = details;
|
|
976
|
+
|
|
977
|
+
// Re-render the bank transfer view
|
|
978
|
+
const formContainer = this.container?.querySelector('#voxepay-form-container');
|
|
979
|
+
if (formContainer) {
|
|
980
|
+
const formattedAmount = formatAmount(this.options.amount, this.options.currency);
|
|
981
|
+
formContainer.innerHTML = this.getBankTransferHTML(formattedAmount);
|
|
982
|
+
this.attachBankTransferListeners();
|
|
983
|
+
this.startTransferTimer();
|
|
984
|
+
|
|
985
|
+
const titleEl = this.container?.querySelector('#voxepay-title');
|
|
986
|
+
if (titleEl && details.totalPayableAmount) {
|
|
987
|
+
titleEl.textContent = `Pay ${formatMainUnitAmount(details.totalPayableAmount, details.feeDetails!.currency)}`;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
} catch (error: any) {
|
|
991
|
+
const errorCode = error?.code || 'BANK_TRANSFER_INIT_FAILED';
|
|
992
|
+
const errorMessage = error?.message || 'Could not generate bank transfer details. Please try again.';
|
|
993
|
+
|
|
994
|
+
// Show error in the loading area
|
|
995
|
+
const formContainer = this.container?.querySelector('#voxepay-form-container');
|
|
996
|
+
if (formContainer) {
|
|
997
|
+
formContainer.innerHTML = `
|
|
998
|
+
<div class="voxepay-transfer-view">
|
|
999
|
+
<div style="text-align: center; padding: 40px 16px;">
|
|
1000
|
+
<div style="font-size: 2.5rem; margin-bottom: 16px;">⚠️</div>
|
|
1001
|
+
<h3 style="font-size: 1.125rem; font-weight: 600; margin-bottom: 8px; color: var(--voxepay-text);">${this.getDVAErrorTitle(errorCode)}</h3>
|
|
1002
|
+
<p style="font-size: 0.875rem; color: var(--voxepay-text-muted); margin-bottom: 24px;">${errorMessage}</p>
|
|
1003
|
+
<button class="voxepay-submit-btn" id="voxepay-retry-transfer"><span>Try Again</span></button>
|
|
1004
|
+
</div>
|
|
1005
|
+
</div>
|
|
1006
|
+
`;
|
|
1007
|
+
const retryBtn = formContainer.querySelector('#voxepay-retry-transfer');
|
|
1008
|
+
retryBtn?.addEventListener('click', () => {
|
|
1009
|
+
formContainer.innerHTML = `
|
|
1010
|
+
<div class="voxepay-transfer-view">
|
|
1011
|
+
<div class="voxepay-transfer-loading">
|
|
1012
|
+
<div class="voxepay-spinner"></div>
|
|
1013
|
+
<p style="margin-top: 16px; color: var(--voxepay-text-muted);">Generating account details...</p>
|
|
1014
|
+
</div>
|
|
1015
|
+
</div>
|
|
1016
|
+
`;
|
|
1017
|
+
this.loadBankTransferDetails();
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
this.options.onError({
|
|
1022
|
+
code: errorCode,
|
|
1023
|
+
message: errorMessage,
|
|
1024
|
+
recoverable: true,
|
|
1025
|
+
details: error?.data,
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* Get user-friendly error title for DVA error codes
|
|
1032
|
+
*/
|
|
1033
|
+
private getDVAErrorTitle(code: string): string {
|
|
1034
|
+
const titles: Record<string, string> = {
|
|
1035
|
+
'ACCOUNT_CREATION_FAILED': 'Account Generation Failed',
|
|
1036
|
+
'ACCOUNT_EXPIRED': 'Account Expired',
|
|
1037
|
+
'INVALID_AMOUNT': 'Invalid Amount',
|
|
1038
|
+
'UNAUTHORIZED': 'Authentication Failed',
|
|
1039
|
+
'ORGANIZATION_NOT_FOUND': 'Configuration Error',
|
|
1040
|
+
'MISSING_VIRTUAL_ACCOUNT': 'Account Generation Failed',
|
|
1041
|
+
'SDK_ERROR': 'Configuration Error',
|
|
1042
|
+
};
|
|
1043
|
+
return titles[code] || 'Something Went Wrong';
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Copy text to clipboard with visual feedback
|
|
1048
|
+
*/
|
|
1049
|
+
private async copyToClipboard(text: string): Promise<void> {
|
|
1050
|
+
try {
|
|
1051
|
+
await navigator.clipboard.writeText(text);
|
|
1052
|
+
const copyBtn = this.container?.querySelector('#voxepay-copy-btn') as HTMLElement;
|
|
1053
|
+
if (copyBtn) {
|
|
1054
|
+
copyBtn.innerHTML = `${ICONS.check}`;
|
|
1055
|
+
copyBtn.classList.add('voxepay-copied');
|
|
1056
|
+
setTimeout(() => {
|
|
1057
|
+
copyBtn.innerHTML = `${ICONS.copy}`;
|
|
1058
|
+
copyBtn.classList.remove('voxepay-copied');
|
|
1059
|
+
}, 2000);
|
|
1060
|
+
}
|
|
1061
|
+
} catch {
|
|
1062
|
+
// Fallback for older browsers
|
|
1063
|
+
const textarea = document.createElement('textarea');
|
|
1064
|
+
textarea.value = text;
|
|
1065
|
+
textarea.style.position = 'fixed';
|
|
1066
|
+
textarea.style.opacity = '0';
|
|
1067
|
+
document.body.appendChild(textarea);
|
|
1068
|
+
textarea.select();
|
|
1069
|
+
document.execCommand('copy');
|
|
1070
|
+
document.body.removeChild(textarea);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
/** Polling interval ID for DVA status checks */
|
|
1075
|
+
private statusPollingInterval: number | null = null;
|
|
1076
|
+
/** Polling timeout (auto-stop after 30 minutes) */
|
|
1077
|
+
private statusPollingTimeout: number | null = null;
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* Handle "I've sent the money" confirmation — starts polling for payment status
|
|
1081
|
+
*/
|
|
1082
|
+
private async handleTransferConfirm(): Promise<void> {
|
|
1083
|
+
const confirmBtn = this.container?.querySelector('#voxepay-transfer-confirm') as HTMLButtonElement;
|
|
1084
|
+
if (confirmBtn) {
|
|
1085
|
+
confirmBtn.disabled = true;
|
|
1086
|
+
confirmBtn.innerHTML = '<div class="voxepay-spinner"></div><span>Confirming transfer...</span>';
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// If no API client or no transaction ref, fall back to pending result
|
|
1090
|
+
if (!this.apiClient || !this.state.transactionRef) {
|
|
1091
|
+
this.stopTransferTimer();
|
|
1092
|
+
const result: PaymentResult = {
|
|
1093
|
+
id: this.state.paymentId || `pay_transfer_${Date.now()}`,
|
|
1094
|
+
status: 'pending',
|
|
1095
|
+
amount: this.options.amount,
|
|
1096
|
+
currency: this.options.currency,
|
|
1097
|
+
timestamp: new Date().toISOString(),
|
|
1098
|
+
reference: this.state.bankTransferDetails?.reference,
|
|
1099
|
+
paymentMethod: 'bank_transfer',
|
|
1100
|
+
};
|
|
1101
|
+
this.state.isSuccess = true;
|
|
1102
|
+
this.renderSuccessView();
|
|
1103
|
+
this.options.onSuccess(result);
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// Show polling UI
|
|
1108
|
+
this.renderPollingView();
|
|
1109
|
+
this.startStatusPolling();
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Render the "waiting for payment confirmation" polling view
|
|
1114
|
+
*/
|
|
1115
|
+
private renderPollingView(): void {
|
|
1116
|
+
const formContainer = this.container?.querySelector('#voxepay-form-container');
|
|
1117
|
+
if (!formContainer) return;
|
|
1118
|
+
|
|
1119
|
+
const formattedAmount = formatAmount(this.options.amount, this.options.currency);
|
|
1120
|
+
|
|
1121
|
+
formContainer.innerHTML = `
|
|
1122
|
+
<div class="voxepay-transfer-view">
|
|
1123
|
+
<div style="text-align: center; padding: 32px 16px;">
|
|
1124
|
+
<div class="voxepay-spinner" style="width: 40px; height: 40px; margin: 0 auto 20px; border-width: 3px;"></div>
|
|
1125
|
+
<h3 style="font-size: 1.125rem; font-weight: 600; margin-bottom: 8px; color: var(--voxepay-text);">Waiting for Payment</h3>
|
|
1126
|
+
<p style="font-size: 0.875rem; color: var(--voxepay-text-muted); margin-bottom: 4px;">
|
|
1127
|
+
We're checking for your transfer of <strong>${formattedAmount}</strong>
|
|
1128
|
+
</p>
|
|
1129
|
+
<p style="font-size: 0.813rem; color: var(--voxepay-text-subtle); margin-bottom: 24px;" id="voxepay-polling-status">
|
|
1130
|
+
This usually takes a few seconds...
|
|
1131
|
+
</p>
|
|
1132
|
+
<button class="voxepay-submit-btn" id="voxepay-cancel-polling" style="background: var(--voxepay-surface); border: 1px solid var(--voxepay-border); color: var(--voxepay-text-muted); box-shadow: none;">
|
|
1133
|
+
<span>Cancel</span>
|
|
1134
|
+
</button>
|
|
1135
|
+
</div>
|
|
1136
|
+
</div>
|
|
1137
|
+
`;
|
|
1138
|
+
|
|
1139
|
+
const cancelBtn = formContainer.querySelector('#voxepay-cancel-polling');
|
|
1140
|
+
cancelBtn?.addEventListener('click', () => {
|
|
1141
|
+
this.stopStatusPolling();
|
|
1142
|
+
// Re-render bank transfer view so user can try again
|
|
1143
|
+
if (this.state.bankTransferDetails) {
|
|
1144
|
+
const amt = formatAmount(this.options.amount, this.options.currency);
|
|
1145
|
+
formContainer.innerHTML = this.getBankTransferHTML(amt);
|
|
1146
|
+
this.attachBankTransferListeners();
|
|
1147
|
+
this.startTransferTimer();
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Start polling payment status every 5 seconds
|
|
1154
|
+
*/
|
|
1155
|
+
private startStatusPolling(): void {
|
|
1156
|
+
this.stopStatusPolling(); // clear any existing poll
|
|
1157
|
+
|
|
1158
|
+
const poll = async () => {
|
|
1159
|
+
if (!this.apiClient || !this.state.transactionRef) return;
|
|
1160
|
+
|
|
1161
|
+
try {
|
|
1162
|
+
const statusData = await this.apiClient.getPaymentStatus(
|
|
1163
|
+
this.state.transactionRef,
|
|
1164
|
+
{
|
|
1165
|
+
simulateWebhook: this.options._sdkConfig?.simulateWebhook,
|
|
1166
|
+
bypassKey: this.options._sdkConfig?.bypassKey,
|
|
1167
|
+
}
|
|
1168
|
+
);
|
|
1169
|
+
this.handlePollingStatusUpdate(statusData.status, statusData);
|
|
1170
|
+
} catch (error: any) {
|
|
1171
|
+
console.error('[VoxePay] Status polling error:', error);
|
|
1172
|
+
// Don't stop polling on transient errors — let it retry
|
|
1173
|
+
const statusEl = this.container?.querySelector('#voxepay-polling-status');
|
|
1174
|
+
if (statusEl) {
|
|
1175
|
+
statusEl.textContent = 'Still checking... Please wait.';
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
// Initial check immediately
|
|
1181
|
+
poll();
|
|
1182
|
+
|
|
1183
|
+
// Then poll every 5 seconds
|
|
1184
|
+
this.statusPollingInterval = window.setInterval(poll, 5000);
|
|
1185
|
+
|
|
1186
|
+
// Auto-stop after 30 minutes
|
|
1187
|
+
this.statusPollingTimeout = window.setTimeout(() => {
|
|
1188
|
+
this.stopStatusPolling();
|
|
1189
|
+
this.handlePollingStatusUpdate('EXPIRED', null);
|
|
1190
|
+
}, 30 * 60 * 1000);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* Stop payment status polling
|
|
1195
|
+
*/
|
|
1196
|
+
private stopStatusPolling(): void {
|
|
1197
|
+
if (this.statusPollingInterval) {
|
|
1198
|
+
clearInterval(this.statusPollingInterval);
|
|
1199
|
+
this.statusPollingInterval = null;
|
|
1200
|
+
}
|
|
1201
|
+
if (this.statusPollingTimeout) {
|
|
1202
|
+
clearTimeout(this.statusPollingTimeout);
|
|
1203
|
+
this.statusPollingTimeout = null;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Handle status updates from polling
|
|
1209
|
+
*/
|
|
1210
|
+
private handlePollingStatusUpdate(status: string, data: any): void {
|
|
1211
|
+
const terminalStatuses = ['COMPLETED', 'FAILED', 'EXPIRED', 'CANCELLED'];
|
|
1212
|
+
|
|
1213
|
+
if (terminalStatuses.includes(status)) {
|
|
1214
|
+
this.stopStatusPolling();
|
|
1215
|
+
this.stopTransferTimer();
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
switch (status) {
|
|
1219
|
+
case 'COMPLETED': {
|
|
1220
|
+
const result: PaymentResult = {
|
|
1221
|
+
id: data?.id || this.state.paymentId || `pay_transfer_${Date.now()}`,
|
|
1222
|
+
status: 'success',
|
|
1223
|
+
amount: this.options.amount,
|
|
1224
|
+
currency: this.options.currency,
|
|
1225
|
+
timestamp: data?.completedAt || new Date().toISOString(),
|
|
1226
|
+
reference: this.state.transactionRef || undefined,
|
|
1227
|
+
paymentMethod: 'bank_transfer',
|
|
1228
|
+
data: data || undefined,
|
|
1229
|
+
};
|
|
1230
|
+
this.state.isSuccess = true;
|
|
1231
|
+
this.renderSuccessView();
|
|
1232
|
+
this.options.onSuccess(result);
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
case 'PAYMENT_RECEIVED': {
|
|
1237
|
+
// Almost done — update the polling UI message
|
|
1238
|
+
const statusEl = this.container?.querySelector('#voxepay-polling-status');
|
|
1239
|
+
if (statusEl) {
|
|
1240
|
+
statusEl.textContent = 'Payment received! Processing...';
|
|
1241
|
+
}
|
|
1242
|
+
break;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
case 'PARTIAL_PAYMENT': {
|
|
1246
|
+
this.stopStatusPolling();
|
|
1247
|
+
this.renderTransferErrorView(
|
|
1248
|
+
'Partial Payment Received',
|
|
1249
|
+
'The amount transferred is less than the required amount. Please transfer the remaining balance or contact support.'
|
|
1250
|
+
);
|
|
1251
|
+
break;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
case 'OVERPAID': {
|
|
1255
|
+
// Overpayment is still successful — show success but note the overpayment
|
|
1256
|
+
const result: PaymentResult = {
|
|
1257
|
+
id: data?.id || this.state.paymentId || `pay_transfer_${Date.now()}`,
|
|
1258
|
+
status: 'success',
|
|
1259
|
+
amount: this.options.amount,
|
|
1260
|
+
currency: this.options.currency,
|
|
1261
|
+
timestamp: data?.completedAt || new Date().toISOString(),
|
|
1262
|
+
reference: this.state.transactionRef || undefined,
|
|
1263
|
+
paymentMethod: 'bank_transfer',
|
|
1264
|
+
data: { ...data, overpaid: true },
|
|
1265
|
+
};
|
|
1266
|
+
this.state.isSuccess = true;
|
|
1267
|
+
this.renderSuccessView();
|
|
1268
|
+
this.options.onSuccess(result);
|
|
1269
|
+
break;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
case 'EXPIRED': {
|
|
1273
|
+
this.renderTransferErrorView(
|
|
1274
|
+
'Payment Expired',
|
|
1275
|
+
'The virtual account has expired. Please try again to generate a new account.'
|
|
1276
|
+
);
|
|
1277
|
+
this.options.onError({
|
|
1278
|
+
code: 'ACCOUNT_EXPIRED',
|
|
1279
|
+
message: 'Virtual account expired before payment was received.',
|
|
1280
|
+
recoverable: true,
|
|
1281
|
+
});
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
case 'FAILED': {
|
|
1286
|
+
this.renderTransferErrorView(
|
|
1287
|
+
'Payment Failed',
|
|
1288
|
+
data?.message || 'The payment could not be processed. Please try again.'
|
|
1289
|
+
);
|
|
1290
|
+
this.options.onError({
|
|
1291
|
+
code: 'PAYMENT_FAILED',
|
|
1292
|
+
message: data?.message || 'Payment failed.',
|
|
1293
|
+
recoverable: true,
|
|
1294
|
+
});
|
|
1295
|
+
break;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
case 'CANCELLED': {
|
|
1299
|
+
this.renderTransferErrorView(
|
|
1300
|
+
'Payment Cancelled',
|
|
1301
|
+
'This payment has been cancelled.'
|
|
1302
|
+
);
|
|
1303
|
+
this.options.onError({
|
|
1304
|
+
code: 'PAYMENT_CANCELLED',
|
|
1305
|
+
message: 'Payment was cancelled.',
|
|
1306
|
+
recoverable: false,
|
|
1307
|
+
});
|
|
1308
|
+
break;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
default:
|
|
1312
|
+
// INITIATED, PENDING_PAYMENT — keep polling
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
/**
|
|
1318
|
+
* Render error view for transfer issues with retry option
|
|
1319
|
+
*/
|
|
1320
|
+
private renderTransferErrorView(title: string, message: string): void {
|
|
1321
|
+
const formContainer = this.container?.querySelector('#voxepay-form-container');
|
|
1322
|
+
if (!formContainer) return;
|
|
1323
|
+
|
|
1324
|
+
formContainer.innerHTML = `
|
|
1325
|
+
<div class="voxepay-transfer-view">
|
|
1326
|
+
<div style="text-align: center; padding: 40px 16px;">
|
|
1327
|
+
<div style="font-size: 2.5rem; margin-bottom: 16px;">❌</div>
|
|
1328
|
+
<h3 style="font-size: 1.125rem; font-weight: 600; margin-bottom: 8px; color: var(--voxepay-text);">${title}</h3>
|
|
1329
|
+
<p style="font-size: 0.875rem; color: var(--voxepay-text-muted); margin-bottom: 24px;">${message}</p>
|
|
1330
|
+
<button class="voxepay-submit-btn" id="voxepay-retry-transfer"><span>Try Again</span></button>
|
|
1331
|
+
</div>
|
|
1332
|
+
</div>
|
|
1333
|
+
`;
|
|
1334
|
+
|
|
1335
|
+
const retryBtn = formContainer.querySelector('#voxepay-retry-transfer');
|
|
1336
|
+
retryBtn?.addEventListener('click', () => {
|
|
1337
|
+
// Reset state for new attempt
|
|
1338
|
+
this.state.bankTransferDetails = null;
|
|
1339
|
+
this.state.transactionRef = null;
|
|
1340
|
+
this.state.paymentId = null;
|
|
1341
|
+
formContainer.innerHTML = `
|
|
1342
|
+
<div class="voxepay-transfer-view">
|
|
1343
|
+
<div class="voxepay-transfer-loading">
|
|
1344
|
+
<div class="voxepay-spinner"></div>
|
|
1345
|
+
<p style="margin-top: 16px; color: var(--voxepay-text-muted);">Generating account details...</p>
|
|
1346
|
+
</div>
|
|
1347
|
+
</div>
|
|
1348
|
+
`;
|
|
1349
|
+
this.loadBankTransferDetails();
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Start the transfer countdown timer
|
|
1355
|
+
*/
|
|
1356
|
+
private startTransferTimer(): void {
|
|
1357
|
+
if (!this.state.bankTransferDetails) return;
|
|
1358
|
+
|
|
1359
|
+
this.state.transferTimer = this.state.bankTransferDetails.expiresIn;
|
|
1360
|
+
|
|
1361
|
+
this.state.transferTimerInterval = window.setInterval(() => {
|
|
1362
|
+
this.state.transferTimer--;
|
|
1363
|
+
|
|
1364
|
+
const countdownEl = this.container?.querySelector('#voxepay-transfer-countdown');
|
|
1365
|
+
if (countdownEl) {
|
|
1366
|
+
countdownEl.textContent = this.formatCountdown(this.state.transferTimer);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
if (this.state.transferTimer <= 0) {
|
|
1370
|
+
this.stopTransferTimer();
|
|
1371
|
+
// Show expired state
|
|
1372
|
+
const timerEl = this.container?.querySelector('#voxepay-transfer-timer') as HTMLElement;
|
|
1373
|
+
if (timerEl) {
|
|
1374
|
+
timerEl.innerHTML = `${ICONS.clock} <span style="color: var(--voxepay-error);">Account expired. Please try again.</span>`;
|
|
1375
|
+
}
|
|
1376
|
+
const confirmBtn = this.container?.querySelector('#voxepay-transfer-confirm') as HTMLButtonElement;
|
|
1377
|
+
if (confirmBtn) confirmBtn.disabled = true;
|
|
1378
|
+
}
|
|
1379
|
+
}, 1000);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
/**
|
|
1383
|
+
* Stop the transfer countdown timer
|
|
1384
|
+
*/
|
|
1385
|
+
private stopTransferTimer(): void {
|
|
1386
|
+
if (this.state.transferTimerInterval) {
|
|
1387
|
+
clearInterval(this.state.transferTimerInterval);
|
|
1388
|
+
this.state.transferTimerInterval = null;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
private handleEscape = (e: KeyboardEvent): void => {
|
|
1393
|
+
if (e.key === 'Escape') {
|
|
1394
|
+
this.close();
|
|
1395
|
+
document.removeEventListener('keydown', this.handleEscape);
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
private handleCardInput(e: Event): void {
|
|
1400
|
+
const input = e.target as HTMLInputElement;
|
|
1401
|
+
const formatted = formatCardNumber(input.value);
|
|
1402
|
+
input.value = formatted;
|
|
1403
|
+
this.state.cardNumber = formatted.replace(/\s/g, '');
|
|
1404
|
+
|
|
1405
|
+
const brandEl = this.container?.querySelector('#voxepay-card-brand') as HTMLElement;
|
|
1406
|
+
const brand = detectCardBrand(this.state.cardNumber);
|
|
1407
|
+
if (brandEl) {
|
|
1408
|
+
brandEl.textContent = brand ? CARD_BRAND_DISPLAY[brand.code] || '' : '';
|
|
1409
|
+
brandEl.style.opacity = brand ? '1' : '0';
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
this.clearError('cardNumber');
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
private handleExpiryInput(e: Event): void {
|
|
1416
|
+
const input = e.target as HTMLInputElement;
|
|
1417
|
+
const formatted = formatExpiry(input.value);
|
|
1418
|
+
input.value = formatted;
|
|
1419
|
+
this.state.expiry = formatted;
|
|
1420
|
+
this.clearError('expiry');
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
private handleCVVInput(e: Event): void {
|
|
1424
|
+
const input = e.target as HTMLInputElement;
|
|
1425
|
+
const formatted = formatCVV(input.value);
|
|
1426
|
+
input.value = formatted;
|
|
1427
|
+
this.state.cvv = formatted;
|
|
1428
|
+
this.clearError('cvv');
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
private handlePinInput(e: Event): void {
|
|
1432
|
+
const input = e.target as HTMLInputElement;
|
|
1433
|
+
const formatted = formatPIN(input.value);
|
|
1434
|
+
input.value = formatted;
|
|
1435
|
+
this.state.pin = formatted;
|
|
1436
|
+
this.clearError('pin');
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
private validateField(field: keyof ModalState['errors']): boolean {
|
|
1440
|
+
let result: { valid: boolean; error?: string };
|
|
1441
|
+
|
|
1442
|
+
switch (field) {
|
|
1443
|
+
case 'cardNumber':
|
|
1444
|
+
result = validateCardNumber(this.state.cardNumber);
|
|
1445
|
+
break;
|
|
1446
|
+
case 'expiry':
|
|
1447
|
+
result = validateExpiry(this.state.expiry);
|
|
1448
|
+
break;
|
|
1449
|
+
case 'cvv':
|
|
1450
|
+
result = validateCVV(this.state.cvv, this.state.cardNumber);
|
|
1451
|
+
break;
|
|
1452
|
+
case 'pin':
|
|
1453
|
+
result = validatePIN(this.state.pin);
|
|
1454
|
+
break;
|
|
1455
|
+
default:
|
|
1456
|
+
return true;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
if (!result.valid) {
|
|
1460
|
+
this.showError(field, result.error || 'Invalid');
|
|
1461
|
+
return false;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
this.clearError(field);
|
|
1465
|
+
return true;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
private showError(field: string, message: string): void {
|
|
1469
|
+
const errorEl = this.container?.querySelector(`#voxepay-${field === 'cardNumber' ? 'card' : field}-error`) as HTMLElement;
|
|
1470
|
+
const inputEl = this.container?.querySelector(`#voxepay-${field === 'cardNumber' ? 'card-number' : field}`) as HTMLElement;
|
|
1471
|
+
|
|
1472
|
+
if (errorEl) {
|
|
1473
|
+
errorEl.innerHTML = `${ICONS.error} ${message}`;
|
|
1474
|
+
errorEl.style.display = 'flex';
|
|
1475
|
+
}
|
|
1476
|
+
inputEl?.classList.add('voxepay-error');
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
private clearError(field: string): void {
|
|
1480
|
+
const errorEl = this.container?.querySelector(`#voxepay-${field === 'cardNumber' ? 'card' : field}-error`) as HTMLElement;
|
|
1481
|
+
const inputEl = this.container?.querySelector(`#voxepay-${field === 'cardNumber' ? 'card-number' : field}`) as HTMLElement;
|
|
1482
|
+
|
|
1483
|
+
if (errorEl) {
|
|
1484
|
+
errorEl.style.display = 'none';
|
|
1485
|
+
}
|
|
1486
|
+
inputEl?.classList.remove('voxepay-error');
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
private async handleSubmit(e: Event): Promise<void> {
|
|
1490
|
+
e.preventDefault();
|
|
1491
|
+
|
|
1492
|
+
const isCardValid = this.validateField('cardNumber');
|
|
1493
|
+
const isExpiryValid = this.validateField('expiry');
|
|
1494
|
+
const isCVVValid = this.validateField('cvv');
|
|
1495
|
+
const isPinValid = this.validateField('pin');
|
|
1496
|
+
|
|
1497
|
+
if (!isCardValid || !isExpiryValid || !isCVVValid || !isPinValid) {
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
if (!this.apiClient || !this.options._sdkConfig) {
|
|
1502
|
+
this.showError('cardNumber', 'SDK not properly initialized. Missing API key or organization ID.');
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
if (!this.options._sdkConfig.paymentLinkSlug) {
|
|
1507
|
+
this.showError('cardNumber', 'Payment link not configured. Please provide a paymentLinkSlug.');
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
const { paymentLinkSlug } = this.options._sdkConfig;
|
|
1512
|
+
this.setProcessing(true);
|
|
1513
|
+
|
|
1514
|
+
try {
|
|
1515
|
+
// Encrypt card data
|
|
1516
|
+
const pan = cleanPan(this.state.cardNumber);
|
|
1517
|
+
const expiryDate = formatExpiryForApi(this.state.expiry);
|
|
1518
|
+
const payload = {
|
|
1519
|
+
version: '1',
|
|
1520
|
+
pan,
|
|
1521
|
+
pin: this.state.pin,
|
|
1522
|
+
expiryDate,
|
|
1523
|
+
cvv: this.state.cvv,
|
|
1524
|
+
};
|
|
1525
|
+
console.log('Before encryption:', payload);
|
|
1526
|
+
|
|
1527
|
+
const authData = await generateAuthData(payload);
|
|
1528
|
+
|
|
1529
|
+
// Generate a unique transaction reference
|
|
1530
|
+
const transactionRef = `VP-${Date.now().toString(36).toUpperCase()}-${Math.random().toString(36).substring(2, 8).toUpperCase()}`;
|
|
1531
|
+
|
|
1532
|
+
// Call initiate payment API via public payment-link endpoint
|
|
1533
|
+
const response = await this.apiClient.initiatePayment(
|
|
1534
|
+
paymentLinkSlug,
|
|
1535
|
+
{
|
|
1536
|
+
organizationId: this.options._sdkConfig.organizationId,
|
|
1537
|
+
transactionRef,
|
|
1538
|
+
customerId: this.options.customerEmail,
|
|
1539
|
+
customerEmail: this.options.customerEmail,
|
|
1540
|
+
customerPhone: this.options.customerPhone,
|
|
1541
|
+
customerName: this.options.customerName,
|
|
1542
|
+
amount: this.options.amount / 100, // Convert from kobo/cents to main unit
|
|
1543
|
+
currency: this.options.currency,
|
|
1544
|
+
paymentMethod: 'CARD',
|
|
1545
|
+
authData,
|
|
1546
|
+
narration: this.options.description,
|
|
1547
|
+
}
|
|
1548
|
+
);
|
|
1549
|
+
|
|
1550
|
+
// Store response data for OTP verification
|
|
1551
|
+
// `paymentId` in the response is the gateway's payment ID — this is what validate-otp expects
|
|
1552
|
+
// `id` is the internal payment record UUID (not used for OTP)
|
|
1553
|
+
this.state.paymentId = response.paymentId || null;
|
|
1554
|
+
// transactionId and transactionRef are the same value — both sent to validate-otp
|
|
1555
|
+
this.state.transactionId = response.transactionRef || transactionRef;
|
|
1556
|
+
this.state.transactionRef = response.transactionRef || transactionRef;
|
|
1557
|
+
this.state.eciFlag = response.eciFlag || null;
|
|
1558
|
+
this.state.otpDeliveryMessage = response.message || null;
|
|
1559
|
+
this.state.feeDetails = response.feeDetails;
|
|
1560
|
+
|
|
1561
|
+
this.setProcessing(false);
|
|
1562
|
+
this.renderOTPView();
|
|
1563
|
+
} catch (error: any) {
|
|
1564
|
+
this.setProcessing(false);
|
|
1565
|
+
const code = error?.code || 'PAYMENT_INITIATE_FAILED';
|
|
1566
|
+
const message = error?.message || 'Payment failed. Please try again.';
|
|
1567
|
+
const recoverable = error?.recoverable !== false;
|
|
1568
|
+
this.showErrorModal(code, message, recoverable);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
private setProcessing(isProcessing: boolean): void {
|
|
1573
|
+
this.state.isProcessing = isProcessing;
|
|
1574
|
+
const submitBtn = this.container?.querySelector('#voxepay-submit') as HTMLButtonElement;
|
|
1575
|
+
|
|
1576
|
+
if (submitBtn) {
|
|
1577
|
+
submitBtn.disabled = isProcessing;
|
|
1578
|
+
submitBtn.innerHTML = isProcessing
|
|
1579
|
+
? '<div class="voxepay-spinner"></div><span>Processing...</span>'
|
|
1580
|
+
: `<span>Pay Now ${formatAmount(this.options.amount, this.options.currency)}</span>`;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
private async processPayment(): Promise<PaymentResult> {
|
|
1585
|
+
return {
|
|
1586
|
+
id: this.state.paymentId || `pay_${Date.now()}`,
|
|
1587
|
+
status: 'success',
|
|
1588
|
+
amount: this.options.amount,
|
|
1589
|
+
currency: this.options.currency,
|
|
1590
|
+
timestamp: new Date().toISOString(),
|
|
1591
|
+
reference: this.state.transactionRef || undefined,
|
|
1592
|
+
paymentMethod: 'card',
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
/**
|
|
1597
|
+
* Get VoxePay branded styles
|
|
1598
|
+
*/
|
|
1599
|
+
private getStyles(): string {
|
|
1600
|
+
return `
|
|
1601
|
+
:root {
|
|
1602
|
+
/* VoxePay Blue Color Palette */
|
|
1603
|
+
--voxepay-primary: #0061FF;
|
|
1604
|
+
--voxepay-primary-hover: #0056E0;
|
|
1605
|
+
--voxepay-secondary: #0047CC;
|
|
1606
|
+
--voxepay-accent: #60A5FA;
|
|
1607
|
+
--voxepay-glow: rgba(0, 97, 255, 0.35);
|
|
1608
|
+
--voxepay-success: #10B981;
|
|
1609
|
+
--voxepay-success-bg: rgba(16, 185, 129, 0.1);
|
|
1610
|
+
--voxepay-error: #EF4444;
|
|
1611
|
+
|
|
1612
|
+
/* Dark Mode (Default) */
|
|
1613
|
+
--voxepay-bg: #0C0C1D;
|
|
1614
|
+
--voxepay-surface: rgba(255, 255, 255, 0.04);
|
|
1615
|
+
--voxepay-surface-hover: rgba(255, 255, 255, 0.08);
|
|
1616
|
+
--voxepay-border: rgba(255, 255, 255, 0.08);
|
|
1617
|
+
--voxepay-text: #FFFFFF;
|
|
1618
|
+
--voxepay-text-muted: #B4B4C7;
|
|
1619
|
+
--voxepay-text-subtle: #6B7280;
|
|
1620
|
+
--voxepay-input-bg: rgba(255, 255, 255, 0.06);
|
|
1621
|
+
|
|
1622
|
+
/* Effects */
|
|
1623
|
+
--voxepay-backdrop-blur: blur(24px);
|
|
1624
|
+
--voxepay-border-radius: 12px;
|
|
1625
|
+
--voxepay-border-radius-lg: 16px;
|
|
1626
|
+
--voxepay-border-radius-xl: 24px;
|
|
1627
|
+
--voxepay-glow-shadow: 0 0 60px var(--voxepay-glow);
|
|
1628
|
+
--voxepay-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.6);
|
|
1629
|
+
--voxepay-transition-fast: 150ms ease;
|
|
1630
|
+
--voxepay-transition: 300ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
/* Light Mode */
|
|
1634
|
+
html.voxepay-light {
|
|
1635
|
+
--voxepay-primary: #0061FF;
|
|
1636
|
+
--voxepay-primary-hover: #0056E0;
|
|
1637
|
+
--voxepay-secondary: #0047CC;
|
|
1638
|
+
--voxepay-glow: rgba(0, 97, 255, 0.2);
|
|
1639
|
+
|
|
1640
|
+
--voxepay-bg: #FFFFFF;
|
|
1641
|
+
--voxepay-surface: #F8FAFC;
|
|
1642
|
+
--voxepay-surface-hover: #F1F5F9;
|
|
1643
|
+
--voxepay-border: #E2E8F0;
|
|
1644
|
+
--voxepay-text: #0F172A;
|
|
1645
|
+
--voxepay-text-muted: #475569;
|
|
1646
|
+
--voxepay-text-subtle: #94A3B8;
|
|
1647
|
+
--voxepay-input-bg: #F8FAFC;
|
|
1648
|
+
|
|
1649
|
+
--voxepay-glow-shadow: 0 0 40px rgba(0, 97, 255, 0.12);
|
|
1650
|
+
--voxepay-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
.voxepay-checkout * { box-sizing: border-box; margin: 0; padding: 0; }
|
|
1654
|
+
.voxepay-checkout { font-family: 'DM Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 1rem; color: var(--voxepay-text); line-height: 1.5; -webkit-font-smoothing: antialiased; }
|
|
1655
|
+
|
|
1656
|
+
.voxepay-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); backdrop-filter: var(--voxepay-backdrop-blur); -webkit-backdrop-filter: var(--voxepay-backdrop-blur); display: flex; align-items: center; justify-content: center; z-index: 999999; opacity: 0; visibility: hidden; transition: opacity var(--voxepay-transition), visibility var(--voxepay-transition); }
|
|
1657
|
+
html.voxepay-light .voxepay-overlay { background: rgba(15, 23, 42, 0.4); }
|
|
1658
|
+
.voxepay-overlay.voxepay-visible { opacity: 1; visibility: visible; }
|
|
1659
|
+
|
|
1660
|
+
.voxepay-modal { background: var(--voxepay-bg); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius-xl); width: 100%; max-width: 420px; max-height: 90vh; overflow: hidden; box-shadow: var(--voxepay-shadow), var(--voxepay-glow-shadow); transform: scale(0.95) translateY(20px); opacity: 0; transition: transform var(--voxepay-transition), opacity var(--voxepay-transition); }
|
|
1661
|
+
.voxepay-overlay.voxepay-visible .voxepay-modal { transform: scale(1) translateY(0); opacity: 1; }
|
|
1662
|
+
|
|
1663
|
+
.voxepay-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }
|
|
1664
|
+
.voxepay-header-left { display: flex; align-items: center; gap: 12px; }
|
|
1665
|
+
.voxepay-logo { width: 36px; height: 36px; border-radius: var(--voxepay-border-radius); background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.25rem; color: white; box-shadow: 0 4px 12px rgba(0, 97, 255, 0.3); }
|
|
1666
|
+
.voxepay-amount { font-size: 1.25rem; font-weight: 600; }
|
|
1667
|
+
.voxepay-close { width: 36px; height: 36px; border: none; background: var(--voxepay-surface-hover); border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--voxepay-text-muted); transition: all var(--voxepay-transition-fast); }
|
|
1668
|
+
.voxepay-close:hover { background: var(--voxepay-border); color: var(--voxepay-text); transform: rotate(90deg); }
|
|
1669
|
+
.voxepay-close svg { width: 18px; height: 18px; }
|
|
1670
|
+
|
|
1671
|
+
.voxepay-body { padding: 24px; background: var(--voxepay-bg); overflow-y: auto; max-height: calc(90vh - 140px); }
|
|
1672
|
+
.voxepay-sticky-actions { position: sticky; bottom: -24px; padding: 16px 24px 24px 24px; margin: 16px -24px -24px -24px; background: var(--voxepay-bg); border-top: 1px solid var(--voxepay-border); z-index: 10; display: flex; flex-direction: column; gap: 12px; }
|
|
1673
|
+
.voxepay-form-group { margin-bottom: 20px; }
|
|
1674
|
+
.voxepay-label { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; font-weight: 500; color: var(--voxepay-text-muted); margin-bottom: 8px; }
|
|
1675
|
+
.voxepay-label-icon { font-size: 1rem; }
|
|
1676
|
+
|
|
1677
|
+
.voxepay-input { width: 100%; padding: 14px 16px; background: var(--voxepay-input-bg); border: 1.5px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text); font-size: 1rem; font-family: inherit; outline: none; transition: border-color var(--voxepay-transition-fast), box-shadow var(--voxepay-transition-fast), background var(--voxepay-transition-fast); }
|
|
1678
|
+
.voxepay-input::placeholder { color: var(--voxepay-text-subtle); }
|
|
1679
|
+
.voxepay-input:hover { border-color: var(--voxepay-text-subtle); }
|
|
1680
|
+
.voxepay-input:focus { border-color: var(--voxepay-primary); box-shadow: 0 0 0 4px var(--voxepay-glow); background: var(--voxepay-bg); }
|
|
1681
|
+
.voxepay-input.voxepay-error { border-color: var(--voxepay-error); box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15); }
|
|
1682
|
+
|
|
1683
|
+
.voxepay-card-input-wrapper { position: relative; }
|
|
1684
|
+
.voxepay-card-brand { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); padding: 4px 8px; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); border-radius: 6px; font-size: 0.7rem; font-weight: 700; color: white; opacity: 0; transition: opacity var(--voxepay-transition-fast); letter-spacing: 0.5px; }
|
|
1685
|
+
.voxepay-card-input-wrapper .voxepay-input { padding-right: 70px; }
|
|
1686
|
+
|
|
1687
|
+
.voxepay-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
|
|
1688
|
+
|
|
1689
|
+
.voxepay-error-message { display: flex; align-items: center; gap: 6px; font-size: 0.813rem; color: var(--voxepay-error); margin-top: 8px; animation: voxepay-shake 0.4s ease; }
|
|
1690
|
+
.voxepay-error-message svg { width: 16px; height: 16px; flex-shrink: 0; }
|
|
1691
|
+
@keyframes voxepay-shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
|
|
1692
|
+
|
|
1693
|
+
.voxepay-submit-btn { width: 100%; padding: 16px 24px; background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); border: none; border-radius: var(--voxepay-border-radius); color: white; font-size: 1.063rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: all var(--voxepay-transition-fast); position: relative; overflow: hidden; box-shadow: 0 4px 15px rgba(0, 97, 255, 0.35); }
|
|
1694
|
+
.voxepay-submit-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(0, 97, 255, 0.45); }
|
|
1695
|
+
.voxepay-submit-btn:active:not(:disabled) { transform: translateY(0); }
|
|
1696
|
+
.voxepay-submit-btn:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; }
|
|
1697
|
+
.voxepay-submit-btn span { position: relative; z-index: 1; }
|
|
1698
|
+
|
|
1699
|
+
.voxepay-spinner { width: 20px; height: 20px; border: 2.5px solid rgba(255, 255, 255, 0.3); border-top-color: white; border-radius: 50%; animation: voxepay-spin 0.8s linear infinite; }
|
|
1700
|
+
@keyframes voxepay-spin { to { transform: rotate(360deg); } }
|
|
1701
|
+
|
|
1702
|
+
.voxepay-footer { text-align: center; padding: 16px 24px 20px; border-top: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }
|
|
1703
|
+
.voxepay-powered-by { font-size: 0.75rem; color: var(--voxepay-text-subtle); display: flex; align-items: center; justify-content: center; gap: 6px; }
|
|
1704
|
+
.voxepay-powered-by svg { width: 14px; height: 14px; color: var(--voxepay-primary); }
|
|
1705
|
+
.voxepay-powered-by strong { color: var(--voxepay-primary); font-weight: 600; }
|
|
1706
|
+
|
|
1707
|
+
.voxepay-success-view { text-align: center; padding: 40px 24px; }
|
|
1708
|
+
.voxepay-success-icon { width: 80px; height: 80px; margin: 0 auto 24px; background: linear-gradient(135deg, var(--voxepay-success), #059669); border-radius: 50%; display: flex; align-items: center; justify-content: center; animation: voxepay-success-pop 0.5s ease; box-shadow: 0 8px 25px rgba(16, 185, 129, 0.35); }
|
|
1709
|
+
@keyframes voxepay-success-pop { 0% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
|
|
1710
|
+
.voxepay-success-icon svg { width: 40px; height: 40px; color: white; }
|
|
1711
|
+
.voxepay-success-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; color: var(--voxepay-text); }
|
|
1712
|
+
.voxepay-success-message { font-size: 1rem; color: var(--voxepay-text-muted); margin-bottom: 24px; }
|
|
1713
|
+
.voxepay-success-btn { padding: 12px 32px; background: var(--voxepay-surface); border: 1.5px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text); font-size: 1rem; font-weight: 500; cursor: pointer; transition: all var(--voxepay-transition-fast); }
|
|
1714
|
+
.voxepay-success-btn:hover { background: var(--voxepay-surface-hover); border-color: var(--voxepay-primary); color: var(--voxepay-primary); }
|
|
1715
|
+
|
|
1716
|
+
/* Error View */
|
|
1717
|
+
.voxepay-error-view { text-align: center; padding: 40px 24px; }
|
|
1718
|
+
.voxepay-error-icon-large { width: 80px; height: 80px; margin: 0 auto 24px; background: linear-gradient(135deg, #ef4444, #dc2626); border-radius: 50%; display: flex; align-items: center; justify-content: center; animation: voxepay-error-pop 0.5s ease; box-shadow: 0 8px 25px rgba(239, 68, 68, 0.35); }
|
|
1719
|
+
@keyframes voxepay-error-pop { 0% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
|
|
1720
|
+
.voxepay-error-icon-large svg { width: 40px; height: 40px; color: white; }
|
|
1721
|
+
.voxepay-error-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; color: var(--voxepay-text); }
|
|
1722
|
+
.voxepay-error-message { font-size: 1rem; color: var(--voxepay-text-muted); margin-bottom: 8px; line-height: 1.5; }
|
|
1723
|
+
.voxepay-error-code { font-size: 0.75rem; color: var(--voxepay-text-subtle); font-family: monospace; margin-bottom: 24px; }
|
|
1724
|
+
.voxepay-error-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; }
|
|
1725
|
+
|
|
1726
|
+
/* OTP View */
|
|
1727
|
+
.voxepay-otp-view { text-align: center; padding: 24px 16px; }
|
|
1728
|
+
.voxepay-otp-header { margin-bottom: 24px; }
|
|
1729
|
+
.voxepay-otp-icon { font-size: 3rem; margin-bottom: 12px; }
|
|
1730
|
+
.voxepay-otp-title { font-size: 1.25rem; font-weight: 700; color: var(--voxepay-text); margin-bottom: 8px; }
|
|
1731
|
+
.voxepay-otp-subtitle { font-size: 0.875rem; color: var(--voxepay-text-muted); }
|
|
1732
|
+
|
|
1733
|
+
.voxepay-otp-inputs-container { margin-bottom: 16px; }
|
|
1734
|
+
.voxepay-otp-inputs { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
|
|
1735
|
+
.voxepay-otp-digit { width: 48px; height: 56px; text-align: center; font-size: 1.5rem; font-weight: 700; border: 2px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); background: var(--voxepay-input-bg); color: var(--voxepay-text); outline: none; transition: all var(--voxepay-transition-fast); }
|
|
1736
|
+
.voxepay-otp-digit:focus { border-color: var(--voxepay-primary); box-shadow: 0 0 0 4px var(--voxepay-glow); }
|
|
1737
|
+
|
|
1738
|
+
.voxepay-otp-timer { font-size: 0.875rem; color: var(--voxepay-text-muted); margin-bottom: 12px; }
|
|
1739
|
+
.voxepay-otp-timer span { font-weight: 700; color: var(--voxepay-primary); }
|
|
1740
|
+
|
|
1741
|
+
.voxepay-resend-btn { padding: 8px 16px; background: transparent; border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text-muted); font-size: 0.875rem; cursor: pointer; margin-bottom: 16px; transition: all var(--voxepay-transition-fast); }
|
|
1742
|
+
.voxepay-resend-btn:hover:not(:disabled) { border-color: var(--voxepay-primary); color: var(--voxepay-primary); }
|
|
1743
|
+
.voxepay-resend-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
1744
|
+
|
|
1745
|
+
.voxepay-back-btn { display: block; width: 100%; padding: 12px; background: transparent; border: none; color: var(--voxepay-text-muted); font-size: 0.875rem; cursor: pointer; margin-top: 12px; transition: color var(--voxepay-transition-fast); }
|
|
1746
|
+
.voxepay-back-btn:hover { color: var(--voxepay-primary); }
|
|
1747
|
+
|
|
1748
|
+
/* Payment Method Tabs */
|
|
1749
|
+
.voxepay-method-tabs { display: flex; border-bottom: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }
|
|
1750
|
+
.voxepay-method-tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 12px; border: none; background: transparent; color: var(--voxepay-text-muted); font-size: 0.813rem; font-weight: 500; font-family: inherit; cursor: pointer; transition: all var(--voxepay-transition-fast); border-bottom: 2px solid transparent; white-space: nowrap; }
|
|
1751
|
+
.voxepay-method-tab svg { width: 16px; height: 16px; flex-shrink: 0; }
|
|
1752
|
+
.voxepay-method-tab:hover { color: var(--voxepay-text); background: var(--voxepay-surface-hover); }
|
|
1753
|
+
.voxepay-method-tab.active { color: var(--voxepay-primary); border-bottom-color: var(--voxepay-primary); background: var(--voxepay-bg); }
|
|
1754
|
+
|
|
1755
|
+
/* Bank Transfer View */
|
|
1756
|
+
.voxepay-transfer-view { padding: 4px 0; }
|
|
1757
|
+
.voxepay-transfer-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 0; }
|
|
1758
|
+
.voxepay-transfer-instruction { text-align: center; margin-bottom: 20px; font-size: 0.938rem; color: var(--voxepay-text-muted); }
|
|
1759
|
+
.voxepay-transfer-instruction strong { color: var(--voxepay-text); font-size: 1.063rem; }
|
|
1760
|
+
.voxepay-transfer-details { background: var(--voxepay-surface); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); overflow: hidden; margin-bottom: 16px; }
|
|
1761
|
+
.voxepay-transfer-detail { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--voxepay-border); }
|
|
1762
|
+
.voxepay-transfer-detail:last-child { border-bottom: none; }
|
|
1763
|
+
.voxepay-transfer-label { font-size: 0.813rem; color: var(--voxepay-text-muted); font-weight: 500; }
|
|
1764
|
+
.voxepay-transfer-value { font-size: 0.938rem; font-weight: 600; color: var(--voxepay-text); }
|
|
1765
|
+
.voxepay-transfer-value-row { display: flex; align-items: center; gap: 8px; }
|
|
1766
|
+
.voxepay-transfer-account { font-size: 1.125rem; font-weight: 700; color: var(--voxepay-primary); letter-spacing: 1.5px; font-family: 'DM Sans', monospace; }
|
|
1767
|
+
.voxepay-transfer-amount { color: var(--voxepay-primary); }
|
|
1768
|
+
|
|
1769
|
+
/* Copy Button */
|
|
1770
|
+
.voxepay-copy-btn { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid var(--voxepay-border); border-radius: 8px; background: var(--voxepay-surface-hover); color: var(--voxepay-text-muted); cursor: pointer; transition: all var(--voxepay-transition-fast); flex-shrink: 0; }
|
|
1771
|
+
.voxepay-copy-btn svg { width: 16px; height: 16px; }
|
|
1772
|
+
.voxepay-copy-btn:hover { border-color: var(--voxepay-primary); color: var(--voxepay-primary); background: rgba(0, 97, 255, 0.1); }
|
|
1773
|
+
.voxepay-copy-btn.voxepay-copied { border-color: var(--voxepay-success); color: var(--voxepay-success); background: var(--voxepay-success-bg); }
|
|
1774
|
+
|
|
1775
|
+
/* Transfer Timer */
|
|
1776
|
+
.voxepay-transfer-timer { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; background: var(--voxepay-surface); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); margin-bottom: 16px; font-size: 0.875rem; color: var(--voxepay-text-muted); }
|
|
1777
|
+
.voxepay-transfer-timer svg { width: 16px; height: 16px; color: var(--voxepay-primary); flex-shrink: 0; }
|
|
1778
|
+
.voxepay-transfer-timer strong { color: var(--voxepay-primary); font-weight: 700; font-family: monospace; font-size: 0.938rem; }
|
|
1779
|
+
|
|
1780
|
+
@media (max-width: 480px) { .voxepay-modal { max-width: 100%; max-height: 100%; border-radius: 0; height: 100%; } .voxepay-body { padding: 20px; } .voxepay-otp-digit { width: 42px; height: 50px; font-size: 1.25rem; } .voxepay-transfer-detail { flex-direction: column; align-items: flex-start; gap: 4px; } }
|
|
1781
|
+
`;
|
|
1782
|
+
}
|
|
1783
|
+
}
|