@pabgw/react 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/dist/index.d.ts +55 -0
- package/dist/index.js +100 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface PabPaymentProps {
|
|
2
|
+
/** Payment link token (use token OR session, not both) */
|
|
3
|
+
token?: string;
|
|
4
|
+
/** Checkout API session ID (use token OR session, not both) */
|
|
5
|
+
session?: string;
|
|
6
|
+
/** Pre-select payment method: 'cc' | 'ach' */
|
|
7
|
+
method?: string;
|
|
8
|
+
/** Locale: 'en' | 'es' */
|
|
9
|
+
locale?: string;
|
|
10
|
+
/** Base URL override (for development) */
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
/** Called when form is ready */
|
|
13
|
+
onReady?: (data: any) => void;
|
|
14
|
+
/** Called when payment succeeds */
|
|
15
|
+
onSuccess?: (data: PabSuccessData) => void;
|
|
16
|
+
/** Called when payment fails */
|
|
17
|
+
onError?: (data: PabErrorData) => void;
|
|
18
|
+
/** Called when payment is processing */
|
|
19
|
+
onProcessing?: () => void;
|
|
20
|
+
/** Called when fees are calculated */
|
|
21
|
+
onFeesCalculated?: (data: PabFeesData) => void;
|
|
22
|
+
/** Called when session expires (Checkout API only) */
|
|
23
|
+
onExpired?: () => void;
|
|
24
|
+
/** Container className */
|
|
25
|
+
className?: string;
|
|
26
|
+
/** Container style */
|
|
27
|
+
style?: React.CSSProperties;
|
|
28
|
+
}
|
|
29
|
+
export interface PabSuccessData {
|
|
30
|
+
transactionId?: string;
|
|
31
|
+
amount?: number;
|
|
32
|
+
authCode?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface PabErrorData {
|
|
35
|
+
code: string;
|
|
36
|
+
message: string;
|
|
37
|
+
}
|
|
38
|
+
export interface PabFeesData {
|
|
39
|
+
amount: number;
|
|
40
|
+
feeAmount: number;
|
|
41
|
+
totalAmount: number;
|
|
42
|
+
}
|
|
43
|
+
export declare function PabPayment({ token, session, method, locale, baseUrl, onReady, onSuccess, onError, onProcessing, onFeesCalculated, onExpired, className, style, }: PabPaymentProps): import("react/jsx-runtime").JSX.Element;
|
|
44
|
+
export declare function usePabPayment(): {
|
|
45
|
+
mount: (config: {
|
|
46
|
+
token?: string;
|
|
47
|
+
session?: string;
|
|
48
|
+
container: HTMLElement | string;
|
|
49
|
+
method?: string;
|
|
50
|
+
locale?: string;
|
|
51
|
+
baseUrl?: string;
|
|
52
|
+
}) => Promise<any>;
|
|
53
|
+
destroy: () => void;
|
|
54
|
+
pab: import("react").MutableRefObject<any>;
|
|
55
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PabPayment = PabPayment;
|
|
4
|
+
exports.usePabPayment = usePabPayment;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
// ============================================
|
|
8
|
+
// Inline pabgw.js loader
|
|
9
|
+
// ============================================
|
|
10
|
+
const PAB_SDK_URL = 'https://quick2pay.pabgw.com/assets/sdk/v1/pabgw.js';
|
|
11
|
+
function loadPabSdk() {
|
|
12
|
+
if (window.PABGW)
|
|
13
|
+
return Promise.resolve();
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const script = document.createElement('script');
|
|
16
|
+
script.src = PAB_SDK_URL;
|
|
17
|
+
script.onload = () => resolve();
|
|
18
|
+
script.onerror = () => reject(new Error('Failed to load PAB SDK'));
|
|
19
|
+
document.head.appendChild(script);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// ============================================
|
|
23
|
+
// React Component
|
|
24
|
+
// ============================================
|
|
25
|
+
function PabPayment({ token, session, method, locale = 'en', baseUrl, onReady, onSuccess, onError, onProcessing, onFeesCalculated, onExpired, className, style, }) {
|
|
26
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
27
|
+
const pabRef = (0, react_1.useRef)(null);
|
|
28
|
+
const stableOnReady = useCallbackRef(onReady);
|
|
29
|
+
const stableOnSuccess = useCallbackRef(onSuccess);
|
|
30
|
+
const stableOnError = useCallbackRef(onError);
|
|
31
|
+
const stableOnProcessing = useCallbackRef(onProcessing);
|
|
32
|
+
const stableOnFeesCalculated = useCallbackRef(onFeesCalculated);
|
|
33
|
+
const stableOnExpired = useCallbackRef(onExpired);
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
let destroyed = false;
|
|
36
|
+
loadPabSdk().then(() => {
|
|
37
|
+
if (destroyed || !containerRef.current)
|
|
38
|
+
return;
|
|
39
|
+
const config = {
|
|
40
|
+
container: containerRef.current,
|
|
41
|
+
method: method || undefined,
|
|
42
|
+
locale,
|
|
43
|
+
baseUrl: baseUrl || undefined,
|
|
44
|
+
};
|
|
45
|
+
if (token)
|
|
46
|
+
config.token = token;
|
|
47
|
+
if (session)
|
|
48
|
+
config.session = session;
|
|
49
|
+
const pab = new window.PABGW(config);
|
|
50
|
+
if (stableOnReady.current)
|
|
51
|
+
pab.on('ready', stableOnReady.current);
|
|
52
|
+
if (stableOnSuccess.current)
|
|
53
|
+
pab.on('success', stableOnSuccess.current);
|
|
54
|
+
if (stableOnError.current)
|
|
55
|
+
pab.on('error', stableOnError.current);
|
|
56
|
+
if (stableOnProcessing.current)
|
|
57
|
+
pab.on('processing', stableOnProcessing.current);
|
|
58
|
+
if (stableOnFeesCalculated.current)
|
|
59
|
+
pab.on('fees_calculated', stableOnFeesCalculated.current);
|
|
60
|
+
if (stableOnExpired.current)
|
|
61
|
+
pab.on('expired', stableOnExpired.current);
|
|
62
|
+
pab.mount();
|
|
63
|
+
pabRef.current = pab;
|
|
64
|
+
});
|
|
65
|
+
return () => {
|
|
66
|
+
destroyed = true;
|
|
67
|
+
if (pabRef.current) {
|
|
68
|
+
pabRef.current.destroy();
|
|
69
|
+
pabRef.current = null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}, [token, session, method, locale, baseUrl]);
|
|
73
|
+
return (0, jsx_runtime_1.jsx)("div", { ref: containerRef, className: className, style: style });
|
|
74
|
+
}
|
|
75
|
+
// ============================================
|
|
76
|
+
// Hook for programmatic control
|
|
77
|
+
// ============================================
|
|
78
|
+
function usePabPayment() {
|
|
79
|
+
const pabRef = (0, react_1.useRef)(null);
|
|
80
|
+
const mount = (0, react_1.useCallback)((config) => {
|
|
81
|
+
return loadPabSdk().then(() => {
|
|
82
|
+
const pab = new window.PABGW(config);
|
|
83
|
+
pabRef.current = pab;
|
|
84
|
+
return pab;
|
|
85
|
+
});
|
|
86
|
+
}, []);
|
|
87
|
+
const destroy = (0, react_1.useCallback)(() => {
|
|
88
|
+
if (pabRef.current) {
|
|
89
|
+
pabRef.current.destroy();
|
|
90
|
+
pabRef.current = null;
|
|
91
|
+
}
|
|
92
|
+
}, []);
|
|
93
|
+
return { mount, destroy, pab: pabRef };
|
|
94
|
+
}
|
|
95
|
+
// Helper to keep callback refs stable
|
|
96
|
+
function useCallbackRef(callback) {
|
|
97
|
+
const ref = (0, react_1.useRef)(callback);
|
|
98
|
+
ref.current = callback;
|
|
99
|
+
return ref;
|
|
100
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pabgw/react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "PAB Gateway Payment Form — React component",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"prepublishOnly": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"react": ">=17.0.0",
|
|
14
|
+
"react-dom": ">=17.0.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/react": "^18.0.0",
|
|
18
|
+
"react": "^18.0.0",
|
|
19
|
+
"typescript": "^5.0.0"
|
|
20
|
+
},
|
|
21
|
+
"keywords": ["pab", "payment", "gateway", "react", "stripe-elements-alternative"],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://dev.azure.com/pabgw/PAB-Gateway"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|