@zahlen/checkout-react 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 +219 -0
- package/index.d.ts +1 -0
- package/index.esm.js +3592 -0
- package/package.json +42 -0
- package/src/ZahlenButton.d.ts +25 -0
- package/src/ZahlenCheckout.d.ts +33 -0
- package/src/ZahlenProvider.d.ts +55 -0
- package/src/index.d.ts +27 -0
- package/src/types.d.ts +83 -0
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zahlen/checkout-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React components for Zahlen Checkout - Modern payment modal",
|
|
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
|
+
"react",
|
|
16
|
+
"modal",
|
|
17
|
+
"fintech",
|
|
18
|
+
"nigeria"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/Havenix-Technologies-LTD/zahlen.git",
|
|
23
|
+
"directory": "libs/zahlen-checkout-react"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/Havenix-Technologies-LTD/zahlen#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/Havenix-Technologies-LTD/zahlen/issues"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"index.cjs.js",
|
|
31
|
+
"index.esm.js",
|
|
32
|
+
"index.d.ts",
|
|
33
|
+
"src/**/*.d.ts",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": ">=17.0.0",
|
|
38
|
+
"react-dom": ">=17.0.0",
|
|
39
|
+
"@zahlen/checkout": ">=0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"type": "module"
|
|
42
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ZahlenButtonProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* ZahlenButton - A pre-styled button that opens the checkout modal
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* import { ZahlenButton } from '@zahlen/checkout-react';
|
|
8
|
+
*
|
|
9
|
+
* function ProductPage() {
|
|
10
|
+
* return (
|
|
11
|
+
* <ZahlenButton
|
|
12
|
+
* amount={4999}
|
|
13
|
+
* currency="NGN"
|
|
14
|
+
* description="Premium Plan"
|
|
15
|
+
* onSuccess={(result) => router.push('/success')}
|
|
16
|
+
* onError={(error) => toast.error(error.message)}
|
|
17
|
+
* >
|
|
18
|
+
* 💳 Pay ₦4,999
|
|
19
|
+
* </ZahlenButton>
|
|
20
|
+
* );
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function ZahlenButton({ amount, currency, description, customerEmail, metadata, onSuccess, onError, onClose, children, className, style, disabled, }: ZahlenButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
export default ZahlenButton;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ZahlenCheckoutProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* ZahlenCheckout - Controlled component for programmatic control
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* import { useState } from 'react';
|
|
8
|
+
* import { ZahlenCheckout } from '@zahlen/checkout-react';
|
|
9
|
+
*
|
|
10
|
+
* function ProductPage() {
|
|
11
|
+
* const [isOpen, setIsOpen] = useState(false);
|
|
12
|
+
*
|
|
13
|
+
* return (
|
|
14
|
+
* <>
|
|
15
|
+
* <button onClick={() => setIsOpen(true)}>Buy Now</button>
|
|
16
|
+
*
|
|
17
|
+
* <ZahlenCheckout
|
|
18
|
+
* open={isOpen}
|
|
19
|
+
* onClose={() => setIsOpen(false)}
|
|
20
|
+
* amount={4999}
|
|
21
|
+
* currency="NGN"
|
|
22
|
+
* onSuccess={(result) => {
|
|
23
|
+
* setIsOpen(false);
|
|
24
|
+
* router.push('/success');
|
|
25
|
+
* }}
|
|
26
|
+
* />
|
|
27
|
+
* </>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function ZahlenCheckout({ open, onClose, amount, currency, description, customerEmail, metadata, onSuccess, onError, }: ZahlenCheckoutProps): null;
|
|
33
|
+
export default ZahlenCheckout;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zahlen Provider - React Context for Zahlen Checkout
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import type { ZahlenProviderProps, ZahlenContextValue } from './types';
|
|
6
|
+
declare const ZahlenContext: React.Context<ZahlenContextValue | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* ZahlenProvider - Wrap your app with this provider to use Zahlen hooks
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { ZahlenProvider } from '@zahlen/checkout-react';
|
|
13
|
+
*
|
|
14
|
+
* function App() {
|
|
15
|
+
* return (
|
|
16
|
+
* <ZahlenProvider apiKey="pk_live_xxx" theme="dark">
|
|
17
|
+
* <YourApp />
|
|
18
|
+
* </ZahlenProvider>
|
|
19
|
+
* );
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function ZahlenProvider({ apiKey, theme, children }: ZahlenProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
/**
|
|
25
|
+
* useZahlen - Hook to access Zahlen checkout functionality
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { useZahlen } from '@zahlen/checkout-react';
|
|
30
|
+
*
|
|
31
|
+
* function PayButton() {
|
|
32
|
+
* const { openCheckout, isProcessing } = useZahlen();
|
|
33
|
+
*
|
|
34
|
+
* const handlePay = async () => {
|
|
35
|
+
* try {
|
|
36
|
+
* const result = await openCheckout({
|
|
37
|
+
* amount: 4999,
|
|
38
|
+
* currency: 'NGN',
|
|
39
|
+
* });
|
|
40
|
+
* console.log('Paid!', result);
|
|
41
|
+
* } catch (error) {
|
|
42
|
+
* console.error('Failed', error);
|
|
43
|
+
* }
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* return (
|
|
47
|
+
* <button onClick={handlePay} disabled={isProcessing}>
|
|
48
|
+
* {isProcessing ? 'Processing...' : 'Pay Now'}
|
|
49
|
+
* </button>
|
|
50
|
+
* );
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function useZahlen(): ZahlenContextValue;
|
|
55
|
+
export { ZahlenContext };
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zahlen/checkout-react - React components for Zahlen Checkout
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```tsx
|
|
6
|
+
* import { ZahlenProvider, ZahlenButton } from '@zahlen/checkout-react';
|
|
7
|
+
*
|
|
8
|
+
* function App() {
|
|
9
|
+
* return (
|
|
10
|
+
* <ZahlenProvider apiKey="pk_live_xxx">
|
|
11
|
+
* <ZahlenButton
|
|
12
|
+
* amount={4999}
|
|
13
|
+
* currency="NGN"
|
|
14
|
+
* onSuccess={(result) => console.log(result)}
|
|
15
|
+
* >
|
|
16
|
+
* Pay Now
|
|
17
|
+
* </ZahlenButton>
|
|
18
|
+
* </ZahlenProvider>
|
|
19
|
+
* );
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export { ZahlenProvider, useZahlen, ZahlenContext } from './ZahlenProvider';
|
|
24
|
+
export { ZahlenButton } from './ZahlenButton';
|
|
25
|
+
export { ZahlenCheckout } from './ZahlenCheckout';
|
|
26
|
+
export type { ZahlenProviderProps, ZahlenContextValue, ZahlenButtonProps, ZahlenCheckoutProps, CheckoutOptions, PaymentResult, PaymentError, ZahlenConfig, } from './types';
|
|
27
|
+
export { Zahlen, formatAmount, getCurrencySymbol } from '@zahlen/checkout';
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zahlen Checkout React Types
|
|
3
|
+
*/
|
|
4
|
+
import type { CheckoutOptions, PaymentResult, PaymentError, ZahlenConfig } from '@zahlen/checkout';
|
|
5
|
+
/**
|
|
6
|
+
* Props for ZahlenProvider
|
|
7
|
+
*/
|
|
8
|
+
export interface ZahlenProviderProps {
|
|
9
|
+
/** Your Zahlen API key */
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/** Theme mode */
|
|
12
|
+
theme?: 'dark' | 'light' | 'auto';
|
|
13
|
+
/** Children components */
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context value from useZahlen hook
|
|
18
|
+
*/
|
|
19
|
+
export interface ZahlenContextValue {
|
|
20
|
+
/** Whether Zahlen is initialized */
|
|
21
|
+
isInitialized: boolean;
|
|
22
|
+
/** Whether a payment is currently processing */
|
|
23
|
+
isProcessing: boolean;
|
|
24
|
+
/** Open the checkout modal programmatically */
|
|
25
|
+
openCheckout: (options: Omit<CheckoutOptions, 'onSuccess' | 'onError'>) => Promise<PaymentResult>;
|
|
26
|
+
/** Close the checkout modal */
|
|
27
|
+
closeCheckout: () => void;
|
|
28
|
+
/** Change the theme */
|
|
29
|
+
setTheme: (theme: 'dark' | 'light' | 'auto') => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Props for ZahlenButton component
|
|
33
|
+
*/
|
|
34
|
+
export interface ZahlenButtonProps {
|
|
35
|
+
/** Payment amount in smallest currency unit */
|
|
36
|
+
amount: number;
|
|
37
|
+
/** Currency code (e.g., 'NGN', 'USD') */
|
|
38
|
+
currency: string;
|
|
39
|
+
/** Payment description */
|
|
40
|
+
description?: string;
|
|
41
|
+
/** Customer email for receipts */
|
|
42
|
+
customerEmail?: string;
|
|
43
|
+
/** Additional metadata */
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
/** Callback on successful payment */
|
|
46
|
+
onSuccess?: (result: PaymentResult) => void;
|
|
47
|
+
/** Callback on payment error */
|
|
48
|
+
onError?: (error: PaymentError) => void;
|
|
49
|
+
/** Callback when modal closes */
|
|
50
|
+
onClose?: () => void;
|
|
51
|
+
/** Button children (text/elements) */
|
|
52
|
+
children?: React.ReactNode;
|
|
53
|
+
/** Additional CSS class names */
|
|
54
|
+
className?: string;
|
|
55
|
+
/** Inline styles */
|
|
56
|
+
style?: React.CSSProperties;
|
|
57
|
+
/** Disable the button */
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Props for ZahlenCheckout controlled component
|
|
62
|
+
*/
|
|
63
|
+
export interface ZahlenCheckoutProps {
|
|
64
|
+
/** Whether the modal is open */
|
|
65
|
+
open: boolean;
|
|
66
|
+
/** Callback to close the modal */
|
|
67
|
+
onClose: () => void;
|
|
68
|
+
/** Payment amount in smallest currency unit */
|
|
69
|
+
amount: number;
|
|
70
|
+
/** Currency code */
|
|
71
|
+
currency: string;
|
|
72
|
+
/** Payment description */
|
|
73
|
+
description?: string;
|
|
74
|
+
/** Customer email */
|
|
75
|
+
customerEmail?: string;
|
|
76
|
+
/** Additional metadata */
|
|
77
|
+
metadata?: Record<string, unknown>;
|
|
78
|
+
/** Callback on successful payment */
|
|
79
|
+
onSuccess: (result: PaymentResult) => void;
|
|
80
|
+
/** Callback on payment error */
|
|
81
|
+
onError?: (error: PaymentError) => void;
|
|
82
|
+
}
|
|
83
|
+
export type { CheckoutOptions, PaymentResult, PaymentError, ZahlenConfig };
|