broxpay 1.0.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 +80 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +44 -0
- package/package.json +25 -0
- package/src/index.tsx +108 -0
- package/tsconfig.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# BroxPay React
|
|
2
|
+
|
|
3
|
+
Simple React component for BroxPay payments.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install broxpay
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
1. **Install:** `npm install broxpay`
|
|
12
|
+
2. **Use:** Import `BroxPayButton` and pass your `apiKey`.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
### Option 1: Simple (Public Key)
|
|
17
|
+
|
|
18
|
+
```jsx
|
|
19
|
+
import { BroxPayButton } from 'broxpay';
|
|
20
|
+
|
|
21
|
+
function App() {
|
|
22
|
+
const config = {
|
|
23
|
+
apiKey: 'pk_test_123',
|
|
24
|
+
amount: 50,
|
|
25
|
+
email: 'user@example.com'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<BroxPayButton
|
|
30
|
+
config={config}
|
|
31
|
+
onSuccess={(data) => console.log('Paid!', data)}
|
|
32
|
+
>
|
|
33
|
+
Pay Now
|
|
34
|
+
</BroxPayButton>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Option 2: Custom Button
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
import { useBroxPay } from 'broxpay';
|
|
43
|
+
|
|
44
|
+
function App() {
|
|
45
|
+
const { checkout } = useBroxPay();
|
|
46
|
+
|
|
47
|
+
const handlePay = () => {
|
|
48
|
+
checkout({
|
|
49
|
+
apiKey: 'pk_live_...', // Your Public Key
|
|
50
|
+
amount: 50,
|
|
51
|
+
email: 'user@example.com',
|
|
52
|
+
onSuccess: (data) => console.log('Paid!', data),
|
|
53
|
+
onError: (error) => console.log('Failed', error)
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return <button onClick={handlePay}>Pay Now</button>;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Props
|
|
62
|
+
|
|
63
|
+
### BroxPayButton
|
|
64
|
+
|
|
65
|
+
| Prop | Type | Required | Description |
|
|
66
|
+
|------|------|----------|-------------|
|
|
67
|
+
| `config` | object | No* | Configuration object (apiKey, amount, etc.) |
|
|
68
|
+
| `token` | string | No* | Checkout token from backend |
|
|
69
|
+
| `onSuccess` | function | No | Called on success |
|
|
70
|
+
| `onError` | function | No | Called on error |
|
|
71
|
+
| `onClose` | function | No | Called on close |
|
|
72
|
+
| `children` | ReactNode | Yes | Button content |
|
|
73
|
+
| `className` | string | No | CSS class |
|
|
74
|
+
| `disabled` | boolean | No | Disable button |
|
|
75
|
+
|
|
76
|
+
*\*Either `config` or `token` is required.*
|
|
77
|
+
|
|
78
|
+
## Support
|
|
79
|
+
|
|
80
|
+
Email: support@broxpay.com
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
interface BroxPayConfig {
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
interface BroxPayCallbacks {
|
|
6
|
+
onSuccess?: (data: any) => void;
|
|
7
|
+
onError?: (error: any) => void;
|
|
8
|
+
onClose?: () => void;
|
|
9
|
+
}
|
|
10
|
+
interface CheckoutConfig {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
amount: number;
|
|
13
|
+
email: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
declare global {
|
|
17
|
+
interface Window {
|
|
18
|
+
BroxPay: {
|
|
19
|
+
checkout: (tokenOrConfig: string | CheckoutConfig, callbacks: BroxPayCallbacks) => void;
|
|
20
|
+
close: () => void;
|
|
21
|
+
config: (options: BroxPayConfig) => void;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export declare function useBroxPay(): {
|
|
26
|
+
checkout: (tokenOrConfig: string | CheckoutConfig, callbacks?: BroxPayCallbacks) => void;
|
|
27
|
+
};
|
|
28
|
+
interface BroxPayButtonProps {
|
|
29
|
+
token?: string;
|
|
30
|
+
config?: CheckoutConfig;
|
|
31
|
+
onSuccess?: (data: any) => void;
|
|
32
|
+
onError?: (error: any) => void;
|
|
33
|
+
onClose?: () => void;
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
className?: string;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare function BroxPayButton({ token, config, onSuccess, onError, onClose, children, className, disabled }: BroxPayButtonProps): React.JSX.Element;
|
|
39
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
// Load BroxPay script
|
|
3
|
+
function loadBroxPay(callback) {
|
|
4
|
+
if (window.BroxPay) {
|
|
5
|
+
callback();
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const script = document.createElement('script');
|
|
9
|
+
script.src = 'https://pay.broxpay.com/inline.js';
|
|
10
|
+
script.onload = callback;
|
|
11
|
+
document.head.appendChild(script);
|
|
12
|
+
}
|
|
13
|
+
// Hook to use BroxPay
|
|
14
|
+
export function useBroxPay() {
|
|
15
|
+
const loaded = useRef(false);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
loadBroxPay(() => {
|
|
18
|
+
loaded.current = true;
|
|
19
|
+
});
|
|
20
|
+
}, []);
|
|
21
|
+
const checkout = (tokenOrConfig, callbacks) => {
|
|
22
|
+
if (!window.BroxPay) {
|
|
23
|
+
console.error('BroxPay not loaded yet');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
window.BroxPay.checkout(tokenOrConfig, callbacks || {});
|
|
27
|
+
};
|
|
28
|
+
return { checkout };
|
|
29
|
+
}
|
|
30
|
+
export function BroxPayButton({ token, config, onSuccess, onError, onClose, children, className, disabled }) {
|
|
31
|
+
const { checkout } = useBroxPay();
|
|
32
|
+
const handleClick = () => {
|
|
33
|
+
if (token) {
|
|
34
|
+
checkout(token, { onSuccess, onError, onClose });
|
|
35
|
+
}
|
|
36
|
+
else if (config) {
|
|
37
|
+
checkout(config, { onSuccess, onError, onClose });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.error('BroxPay: Either token or config must be provided');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return (React.createElement("button", { onClick: handleClick, className: className, disabled: disabled }, children));
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "broxpay",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Simple React component for BroxPay inline checkout",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"broxpay",
|
|
12
|
+
"payment",
|
|
13
|
+
"checkout",
|
|
14
|
+
"react"
|
|
15
|
+
],
|
|
16
|
+
"author": "BroxPay",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": "^18.0.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/react": "^18.0.0",
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React, { useEffect, useRef, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface BroxPayConfig {
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface BroxPayCallbacks {
|
|
8
|
+
onSuccess?: (data: any) => void;
|
|
9
|
+
onError?: (error: any) => void;
|
|
10
|
+
onClose?: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface CheckoutConfig {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
amount: number;
|
|
16
|
+
email: string;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Declare BroxPay global
|
|
21
|
+
declare global {
|
|
22
|
+
interface Window {
|
|
23
|
+
BroxPay: {
|
|
24
|
+
checkout: (tokenOrConfig: string | CheckoutConfig, callbacks: BroxPayCallbacks) => void;
|
|
25
|
+
close: () => void;
|
|
26
|
+
config: (options: BroxPayConfig) => void;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Load BroxPay script
|
|
32
|
+
function loadBroxPay(callback: () => void) {
|
|
33
|
+
if (window.BroxPay) {
|
|
34
|
+
callback();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const script = document.createElement('script');
|
|
39
|
+
script.src = 'https://pay.broxpay.com/inline.js';
|
|
40
|
+
script.onload = callback;
|
|
41
|
+
document.head.appendChild(script);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Hook to use BroxPay
|
|
45
|
+
export function useBroxPay() {
|
|
46
|
+
const loaded = useRef(false);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
loadBroxPay(() => {
|
|
50
|
+
loaded.current = true;
|
|
51
|
+
});
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
const checkout = (tokenOrConfig: string | CheckoutConfig, callbacks?: BroxPayCallbacks) => {
|
|
55
|
+
if (!window.BroxPay) {
|
|
56
|
+
console.error('BroxPay not loaded yet');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
window.BroxPay.checkout(tokenOrConfig, callbacks || {});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return { checkout };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Button component
|
|
66
|
+
interface BroxPayButtonProps {
|
|
67
|
+
token?: string;
|
|
68
|
+
config?: CheckoutConfig;
|
|
69
|
+
onSuccess?: (data: any) => void;
|
|
70
|
+
onError?: (error: any) => void;
|
|
71
|
+
onClose?: () => void;
|
|
72
|
+
children: ReactNode;
|
|
73
|
+
className?: string;
|
|
74
|
+
disabled?: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function BroxPayButton({
|
|
78
|
+
token,
|
|
79
|
+
config,
|
|
80
|
+
onSuccess,
|
|
81
|
+
onError,
|
|
82
|
+
onClose,
|
|
83
|
+
children,
|
|
84
|
+
className,
|
|
85
|
+
disabled
|
|
86
|
+
}: BroxPayButtonProps) {
|
|
87
|
+
const { checkout } = useBroxPay();
|
|
88
|
+
|
|
89
|
+
const handleClick = () => {
|
|
90
|
+
if (token) {
|
|
91
|
+
checkout(token, { onSuccess, onError, onClose });
|
|
92
|
+
} else if (config) {
|
|
93
|
+
checkout(config, { onSuccess, onError, onClose });
|
|
94
|
+
} else {
|
|
95
|
+
console.error('BroxPay: Either token or config must be provided');
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<button
|
|
101
|
+
onClick={handleClick}
|
|
102
|
+
className={className}
|
|
103
|
+
disabled={disabled}
|
|
104
|
+
>
|
|
105
|
+
{children}
|
|
106
|
+
</button>
|
|
107
|
+
);
|
|
108
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2015",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2015",
|
|
7
|
+
"DOM"
|
|
8
|
+
],
|
|
9
|
+
"jsx": "react",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"moduleResolution": "node"
|
|
16
|
+
},
|
|
17
|
+
"include": [
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"exclude": [
|
|
21
|
+
"node_modules",
|
|
22
|
+
"dist"
|
|
23
|
+
]
|
|
24
|
+
}
|