@zahlen/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/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@zahlen/checkout",
3
+ "version": "0.1.0",
4
+ "description": "Modern, Gen Z-friendly payment checkout modal for the web",
5
+ "author": "Zahlen",
6
+ "license": "MIT",
7
+ "main": "./index.cjs.js",
8
+ "module": "./index.esm.js",
9
+ "types": "./index.d.ts",
10
+ "sideEffects": false,
11
+ "keywords": [
12
+ "zahlen",
13
+ "checkout",
14
+ "payment",
15
+ "modal",
16
+ "fintech",
17
+ "nigeria",
18
+ "stripe-alternative",
19
+ "payment-gateway"
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/Havenix-Technologies-LTD/zahlen.git",
24
+ "directory": "libs/zahlen-checkout"
25
+ },
26
+ "homepage": "https://github.com/Havenix-Technologies-LTD/zahlen#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/Havenix-Technologies-LTD/zahlen/issues"
29
+ },
30
+ "files": [
31
+ "index.cjs.js",
32
+ "index.esm.js",
33
+ "index.d.ts",
34
+ "src/**/*.d.ts"
35
+ ],
36
+ "dependencies": {}
37
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Zahlen 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
+ errors: {
11
+ cardNumber?: string;
12
+ expiry?: string;
13
+ cvv?: string;
14
+ };
15
+ isProcessing: boolean;
16
+ isSuccess: boolean;
17
+ }
18
+ export declare class ZahlenModal {
19
+ private options;
20
+ private state;
21
+ private container;
22
+ private overlay;
23
+ constructor(options: CheckoutOptions);
24
+ /**
25
+ * Open the checkout modal
26
+ */
27
+ open(): void;
28
+ /**
29
+ * Close the checkout modal
30
+ */
31
+ close(): void;
32
+ /**
33
+ * Inject styles if not already present
34
+ */
35
+ private injectStyles;
36
+ /**
37
+ * Render the modal HTML
38
+ */
39
+ private render;
40
+ /**
41
+ * Get modal HTML
42
+ */
43
+ private getModalHTML;
44
+ /**
45
+ * Render success view
46
+ */
47
+ private renderSuccessView;
48
+ /**
49
+ * Attach event listeners
50
+ */
51
+ private attachEventListeners;
52
+ private handleEscape;
53
+ /**
54
+ * Handle card number input
55
+ */
56
+ private handleCardInput;
57
+ /**
58
+ * Handle expiry input
59
+ */
60
+ private handleExpiryInput;
61
+ /**
62
+ * Handle CVV input
63
+ */
64
+ private handleCVVInput;
65
+ /**
66
+ * Validate a specific field
67
+ */
68
+ private validateField;
69
+ /**
70
+ * Show error for a field
71
+ */
72
+ private showError;
73
+ /**
74
+ * Clear error for a field
75
+ */
76
+ private clearError;
77
+ /**
78
+ * Handle form submission
79
+ */
80
+ private handleSubmit;
81
+ /**
82
+ * Set processing state
83
+ */
84
+ private setProcessing;
85
+ /**
86
+ * Process payment (placeholder - integrate with your backend)
87
+ */
88
+ private processPayment;
89
+ /**
90
+ * Get base styles
91
+ */
92
+ private getStyles;
93
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @zahlen/checkout - Modern Payment Checkout SDK
3
+ *
4
+ * A beautiful, Gen Z-friendly payment modal for the web.
5
+ *
6
+ * @example
7
+ * ```html
8
+ * <script src="https://unpkg.com/@zahlen/checkout"></script>
9
+ * <script>
10
+ * Zahlen.init({ apiKey: 'pk_live_xxxxx' });
11
+ *
12
+ * Zahlen.checkout({
13
+ * amount: 4999,
14
+ * currency: 'NGN',
15
+ * onSuccess: (result) => console.log('Paid!', result),
16
+ * onError: (error) => console.error('Failed', error),
17
+ * });
18
+ * </script>
19
+ * ```
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+ export { Zahlen, ZahlenSDK } from './zahlen';
24
+ export type { ZahlenConfig, ZahlenTheme, CheckoutOptions, PaymentResult, PaymentError, CardInfo, } from './types';
25
+ export { detectCardBrand, validateCardNumber, validateExpiry, validateCVV, luhnCheck, } from './utils/card-validator';
26
+ export { formatCardNumber, formatExpiry, formatCVV, formatAmount, getCurrencySymbol, } from './utils/formatter';
27
+ export { Zahlen as default } from './zahlen';
package/src/types.d.ts ADDED
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Zahlen Checkout Type Definitions
3
+ */
4
+ /**
5
+ * Configuration for initializing Zahlen
6
+ */
7
+ export interface ZahlenConfig {
8
+ /** Your Zahlen API key (starts with pk_live_ or pk_test_) */
9
+ apiKey: string;
10
+ /** Theme mode: 'dark' (default), 'light', or 'auto' (follows system) */
11
+ theme?: 'dark' | 'light' | 'auto';
12
+ /** Locale for formatting (e.g., 'en-US', 'en-NG') */
13
+ locale?: string;
14
+ /** Custom CSS variables to override default theme */
15
+ customStyles?: Partial<ZahlenTheme>;
16
+ }
17
+ /**
18
+ * Custom theme variables
19
+ */
20
+ export interface ZahlenTheme {
21
+ '--zahlen-primary': string;
22
+ '--zahlen-secondary': string;
23
+ '--zahlen-accent': string;
24
+ '--zahlen-bg': string;
25
+ '--zahlen-surface': string;
26
+ '--zahlen-border': string;
27
+ '--zahlen-text': string;
28
+ '--zahlen-text-muted': string;
29
+ '--zahlen-border-radius': string;
30
+ }
31
+ /**
32
+ * Options for opening a checkout session
33
+ */
34
+ export interface CheckoutOptions {
35
+ /** Payment amount in smallest currency unit (e.g., kobo for NGN, cents for USD) */
36
+ amount: number;
37
+ /** ISO 4217 currency code (e.g., 'NGN', 'USD', 'EUR') */
38
+ currency: string;
39
+ /** Short description of the payment (shown in modal) */
40
+ description?: string;
41
+ /** Customer's email address (optional, for receipts) */
42
+ customerEmail?: string;
43
+ /** Additional metadata to attach to the payment */
44
+ metadata?: Record<string, unknown>;
45
+ /** Callback when payment succeeds */
46
+ onSuccess: (result: PaymentResult) => void;
47
+ /** Callback when payment fails */
48
+ onError: (error: PaymentError) => void;
49
+ /** Callback when modal is closed (optional) */
50
+ onClose?: () => void;
51
+ }
52
+ /**
53
+ * Result returned on successful payment
54
+ */
55
+ export interface PaymentResult {
56
+ /** Unique payment ID */
57
+ id: string;
58
+ /** Payment status */
59
+ status: 'success' | 'pending';
60
+ /** Amount charged in smallest currency unit */
61
+ amount: number;
62
+ /** Currency code */
63
+ currency: string;
64
+ /** ISO timestamp of the payment */
65
+ timestamp: string;
66
+ /** Transaction reference (if available) */
67
+ reference?: string;
68
+ /** Additional data from payment processor */
69
+ data?: Record<string, unknown>;
70
+ }
71
+ /**
72
+ * Error returned on payment failure
73
+ */
74
+ export interface PaymentError {
75
+ /** Error code */
76
+ code: string;
77
+ /** Human-readable error message */
78
+ message: string;
79
+ /** Whether the error is recoverable (user can retry) */
80
+ recoverable?: boolean;
81
+ /** Additional error details */
82
+ details?: Record<string, unknown>;
83
+ }
84
+ /**
85
+ * Card information (sanitized - no full card numbers)
86
+ */
87
+ export interface CardInfo {
88
+ /** Card brand (visa, mastercard, verve, etc.) */
89
+ brand: string;
90
+ /** Last 4 digits of the card */
91
+ last4: string;
92
+ /** Expiry month (1-12) */
93
+ expiryMonth: number;
94
+ /** Expiry year (full year) */
95
+ expiryYear: number;
96
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Card validation utilities for Zahlen Checkout
3
+ */
4
+ export interface CardBrand {
5
+ name: string;
6
+ code: string;
7
+ pattern: RegExp;
8
+ lengths: number[];
9
+ cvvLength: number;
10
+ }
11
+ export declare const CARD_BRANDS: CardBrand[];
12
+ /**
13
+ * Detect card brand from card number
14
+ */
15
+ export declare function detectCardBrand(cardNumber: string): CardBrand | null;
16
+ /**
17
+ * Luhn algorithm for card validation
18
+ */
19
+ export declare function luhnCheck(cardNumber: string): boolean;
20
+ /**
21
+ * Validate card number
22
+ */
23
+ export declare function validateCardNumber(cardNumber: string): {
24
+ valid: boolean;
25
+ error?: string;
26
+ };
27
+ /**
28
+ * Validate expiry date
29
+ */
30
+ export declare function validateExpiry(expiry: string): {
31
+ valid: boolean;
32
+ error?: string;
33
+ };
34
+ /**
35
+ * Validate CVV
36
+ */
37
+ export declare function validateCVV(cvv: string, cardNumber?: string): {
38
+ valid: boolean;
39
+ error?: string;
40
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Input formatting utilities for Zahlen Checkout
3
+ */
4
+ /**
5
+ * Format card number with spaces every 4 digits
6
+ */
7
+ export declare function formatCardNumber(value: string): string;
8
+ /**
9
+ * Format expiry date as MM/YY
10
+ */
11
+ export declare function formatExpiry(value: string): string;
12
+ /**
13
+ * Format CVV (numbers only, max 4 digits)
14
+ */
15
+ export declare function formatCVV(value: string): string;
16
+ /**
17
+ * Format currency amount
18
+ */
19
+ export declare function formatAmount(amount: number, currency: string): string;
20
+ /**
21
+ * Get currency symbol
22
+ */
23
+ export declare function getCurrencySymbol(currency: string): string;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Zahlen - Modern Payment Checkout SDK
3
+ *
4
+ * A beautiful, Gen Z-friendly payment modal for the web.
5
+ *
6
+ * @example
7
+ * ```javascript
8
+ * // Initialize Zahlen
9
+ * Zahlen.init({ apiKey: 'pk_live_xxxxx' });
10
+ *
11
+ * // Open checkout
12
+ * Zahlen.checkout({
13
+ * amount: 4999,
14
+ * currency: 'NGN',
15
+ * description: 'Premium Plan',
16
+ * onSuccess: (result) => console.log('Paid!', result),
17
+ * onError: (error) => console.error('Failed', error),
18
+ * });
19
+ * ```
20
+ */
21
+ import type { ZahlenConfig, CheckoutOptions } from './types';
22
+ declare class ZahlenSDK {
23
+ private config;
24
+ private currentModal;
25
+ private initialized;
26
+ /**
27
+ * Initialize Zahlen with your configuration
28
+ * @param config - Configuration object with API key and optional settings
29
+ */
30
+ init(config: ZahlenConfig): void;
31
+ /**
32
+ * Open the checkout modal
33
+ * @param options - Checkout options including amount, currency, and callbacks
34
+ */
35
+ checkout(options: CheckoutOptions): void;
36
+ /**
37
+ * Close the current checkout modal
38
+ */
39
+ closeModal(): void;
40
+ /**
41
+ * Set the theme
42
+ * @param theme - 'dark', 'light', or 'auto'
43
+ */
44
+ setTheme(theme: 'dark' | 'light' | 'auto'): void;
45
+ /**
46
+ * Apply system theme preference
47
+ */
48
+ private applyAutoTheme;
49
+ /**
50
+ * Apply custom CSS variables
51
+ */
52
+ private applyCustomStyles;
53
+ /**
54
+ * Get the SDK version
55
+ */
56
+ get version(): string;
57
+ /**
58
+ * Check if SDK is initialized
59
+ */
60
+ get isInitialized(): boolean;
61
+ }
62
+ declare const Zahlen: ZahlenSDK;
63
+ export { Zahlen, ZahlenSDK };
64
+ export type { ZahlenConfig, CheckoutOptions, ZahlenTheme } from './types';
65
+ export type { PaymentResult, PaymentError, CardInfo } from './types';