@voxepay/checkout 0.1.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/README.md +143 -0
- package/dist/components/modal.d.ts +90 -0
- package/dist/index.cjs.js +1114 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.esm.js +1098 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/types.d.ts +96 -0
- package/dist/utils/card-validator.d.ts +40 -0
- package/dist/utils/formatter.d.ts +23 -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 +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @voxepay/checkout
|
|
2
|
+
|
|
3
|
+
Modern, beautiful payment checkout modal for the web by **VoxePay**.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @voxepay/checkout
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Via Script Tag (CDN)
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://unpkg.com/@voxepay/checkout/dist/voxepay-checkout.min.js"></script>
|
|
17
|
+
<script>
|
|
18
|
+
VoxePay.init({ apiKey: 'pk_live_xxxxx' });
|
|
19
|
+
|
|
20
|
+
document.getElementById('pay-btn').addEventListener('click', () => {
|
|
21
|
+
VoxePay.checkout({
|
|
22
|
+
amount: 500000, // ₦5,000 in kobo
|
|
23
|
+
currency: 'NGN',
|
|
24
|
+
description: 'Premium Plan',
|
|
25
|
+
customerEmail: 'customer@example.com',
|
|
26
|
+
onSuccess: (result) => {
|
|
27
|
+
console.log('Payment successful!', result);
|
|
28
|
+
},
|
|
29
|
+
onError: (error) => {
|
|
30
|
+
console.error('Payment failed:', error.message);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
</script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Via ES Modules
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
import { VoxePay } from '@voxepay/checkout';
|
|
41
|
+
|
|
42
|
+
// Initialize once
|
|
43
|
+
VoxePay.init({
|
|
44
|
+
apiKey: 'pk_live_xxxxx',
|
|
45
|
+
theme: 'dark', // 'dark' | 'light' | 'auto'
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Open checkout
|
|
49
|
+
VoxePay.checkout({
|
|
50
|
+
amount: 500000, // Amount in kobo (₦5,000)
|
|
51
|
+
currency: 'NGN',
|
|
52
|
+
description: 'Premium Plan',
|
|
53
|
+
customerEmail: 'customer@example.com',
|
|
54
|
+
onSuccess: (result) => {
|
|
55
|
+
console.log('Paid!', result);
|
|
56
|
+
},
|
|
57
|
+
onError: (error) => {
|
|
58
|
+
console.error('Failed:', error.message);
|
|
59
|
+
},
|
|
60
|
+
onClose: () => {
|
|
61
|
+
console.log('Modal closed');
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API Reference
|
|
67
|
+
|
|
68
|
+
### `VoxePay.init(config)`
|
|
69
|
+
|
|
70
|
+
Initialize the SDK. Call this once before using `checkout()`.
|
|
71
|
+
|
|
72
|
+
| Parameter | Type | Required | Description |
|
|
73
|
+
|-----------|------|----------|-------------|
|
|
74
|
+
| `apiKey` | `string` | ✅ | Your VoxePay API key |
|
|
75
|
+
| `theme` | `'dark' \| 'light' \| 'auto'` | ❌ | Theme mode (default: `'dark'`) |
|
|
76
|
+
| `locale` | `string` | ❌ | Locale for formatting (default: `'en-US'`) |
|
|
77
|
+
| `customStyles` | `Partial<VoxePayTheme>` | ❌ | Custom CSS variables |
|
|
78
|
+
|
|
79
|
+
### `VoxePay.checkout(options)`
|
|
80
|
+
|
|
81
|
+
Open the checkout modal.
|
|
82
|
+
|
|
83
|
+
| Parameter | Type | Required | Description |
|
|
84
|
+
|-----------|------|----------|-------------|
|
|
85
|
+
| `amount` | `number` | ✅ | Amount in smallest currency unit (kobo/cents) |
|
|
86
|
+
| `currency` | `string` | ✅ | ISO 4217 currency code (e.g., `'NGN'`, `'USD'`) |
|
|
87
|
+
| `description` | `string` | ❌ | Payment description shown in modal |
|
|
88
|
+
| `customerEmail` | `string` | ❌ | Customer email for receipts |
|
|
89
|
+
| `metadata` | `Record<string, unknown>` | ❌ | Additional metadata |
|
|
90
|
+
| `onSuccess` | `(result: PaymentResult) => void` | ✅ | Success callback |
|
|
91
|
+
| `onError` | `(error: PaymentError) => void` | ✅ | Error callback |
|
|
92
|
+
| `onClose` | `() => void` | ❌ | Modal close callback |
|
|
93
|
+
|
|
94
|
+
### `VoxePay.closeModal()`
|
|
95
|
+
|
|
96
|
+
Programmatically close the checkout modal.
|
|
97
|
+
|
|
98
|
+
### `VoxePay.setTheme(theme)`
|
|
99
|
+
|
|
100
|
+
Change the theme dynamically.
|
|
101
|
+
|
|
102
|
+
## Utilities
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
import {
|
|
106
|
+
formatAmount,
|
|
107
|
+
getCurrencySymbol,
|
|
108
|
+
validateCardNumber,
|
|
109
|
+
detectCardBrand,
|
|
110
|
+
} from '@voxepay/checkout';
|
|
111
|
+
|
|
112
|
+
formatAmount(500000, 'NGN'); // "₦5,000.00"
|
|
113
|
+
getCurrencySymbol('NGN'); // "₦"
|
|
114
|
+
validateCardNumber('4111111111111111'); // { valid: true }
|
|
115
|
+
detectCardBrand('4111111111111111'); // { name: 'Visa', code: 'visa', ... }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Theming
|
|
119
|
+
|
|
120
|
+
### Custom Colors
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
VoxePay.init({
|
|
124
|
+
apiKey: 'pk_live_xxxxx',
|
|
125
|
+
customStyles: {
|
|
126
|
+
'--voxepay-primary': '#0061FF',
|
|
127
|
+
'--voxepay-secondary': '#0047CC',
|
|
128
|
+
'--voxepay-border-radius': '16px',
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Supported Cards
|
|
134
|
+
|
|
135
|
+
- Visa
|
|
136
|
+
- Mastercard
|
|
137
|
+
- Verve
|
|
138
|
+
- American Express
|
|
139
|
+
- Discover
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
MIT © VoxePay
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VoxePay Checkout Modal Component
|
|
3
|
+
* A modern, glassmorphism payment modal
|
|
4
|
+
*/
|
|
5
|
+
import type { CheckoutOptions } from '../types';
|
|
6
|
+
export interface ModalState {
|
|
7
|
+
cardNumber: string;
|
|
8
|
+
expiry: string;
|
|
9
|
+
cvv: string;
|
|
10
|
+
otp: string;
|
|
11
|
+
errors: {
|
|
12
|
+
cardNumber?: string;
|
|
13
|
+
expiry?: string;
|
|
14
|
+
cvv?: string;
|
|
15
|
+
otp?: string;
|
|
16
|
+
};
|
|
17
|
+
isProcessing: boolean;
|
|
18
|
+
isSuccess: boolean;
|
|
19
|
+
isOtpStep: boolean;
|
|
20
|
+
otpTimer: number;
|
|
21
|
+
canResendOtp: boolean;
|
|
22
|
+
otpTimerInterval: number | null;
|
|
23
|
+
}
|
|
24
|
+
export declare class VoxePayModal {
|
|
25
|
+
private options;
|
|
26
|
+
private state;
|
|
27
|
+
private container;
|
|
28
|
+
private overlay;
|
|
29
|
+
constructor(options: CheckoutOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Open the checkout modal
|
|
32
|
+
*/
|
|
33
|
+
open(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Close the checkout modal
|
|
36
|
+
*/
|
|
37
|
+
close(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Inject styles if not already present
|
|
40
|
+
*/
|
|
41
|
+
private injectStyles;
|
|
42
|
+
/**
|
|
43
|
+
* Render the modal HTML
|
|
44
|
+
*/
|
|
45
|
+
private render;
|
|
46
|
+
/**
|
|
47
|
+
* Get modal HTML
|
|
48
|
+
*/
|
|
49
|
+
private getModalHTML;
|
|
50
|
+
/**
|
|
51
|
+
* Render success view
|
|
52
|
+
*/
|
|
53
|
+
private renderSuccessView;
|
|
54
|
+
/**
|
|
55
|
+
* Render OTP verification view
|
|
56
|
+
*/
|
|
57
|
+
private renderOTPView;
|
|
58
|
+
/**
|
|
59
|
+
* Attach OTP-specific event listeners
|
|
60
|
+
*/
|
|
61
|
+
private attachOTPEventListeners;
|
|
62
|
+
private handleOTPInput;
|
|
63
|
+
private handleOTPKeydown;
|
|
64
|
+
private handleOTPPaste;
|
|
65
|
+
private updateOTPState;
|
|
66
|
+
private startOTPTimer;
|
|
67
|
+
private handleOTPSubmit;
|
|
68
|
+
private setOTPProcessing;
|
|
69
|
+
private verifyOTP;
|
|
70
|
+
private handleResendOTP;
|
|
71
|
+
private handleBackToCard;
|
|
72
|
+
/**
|
|
73
|
+
* Attach event listeners
|
|
74
|
+
*/
|
|
75
|
+
private attachEventListeners;
|
|
76
|
+
private handleEscape;
|
|
77
|
+
private handleCardInput;
|
|
78
|
+
private handleExpiryInput;
|
|
79
|
+
private handleCVVInput;
|
|
80
|
+
private validateField;
|
|
81
|
+
private showError;
|
|
82
|
+
private clearError;
|
|
83
|
+
private handleSubmit;
|
|
84
|
+
private setProcessing;
|
|
85
|
+
private processPayment;
|
|
86
|
+
/**
|
|
87
|
+
* Get VoxePay branded styles
|
|
88
|
+
*/
|
|
89
|
+
private getStyles;
|
|
90
|
+
}
|