@valuepay/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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +435 -0
- package/dist/cjs/components/ValuePayButton.js +14 -0
- package/dist/cjs/components/ValuePayButton.js.map +1 -0
- package/dist/cjs/components/ValuePayProvider.js +17 -0
- package/dist/cjs/components/ValuePayProvider.js.map +1 -0
- package/dist/cjs/hooks/useScript.js +40 -0
- package/dist/cjs/hooks/useScript.js.map +1 -0
- package/dist/cjs/hooks/useValuePay.js +90 -0
- package/dist/cjs/hooks/useValuePay.js.map +1 -0
- package/dist/cjs/index.js +16 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/utils/constants.js +12 -0
- package/dist/cjs/utils/constants.js.map +1 -0
- package/dist/cjs/utils/helpers.js +67 -0
- package/dist/cjs/utils/helpers.js.map +1 -0
- package/dist/esm/components/ValuePayButton.js +12 -0
- package/dist/esm/components/ValuePayButton.js.map +1 -0
- package/dist/esm/components/ValuePayProvider.js +15 -0
- package/dist/esm/components/ValuePayProvider.js.map +1 -0
- package/dist/esm/hooks/useScript.js +38 -0
- package/dist/esm/hooks/useScript.js.map +1 -0
- package/dist/esm/hooks/useValuePay.js +88 -0
- package/dist/esm/hooks/useValuePay.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils/constants.js +7 -0
- package/dist/esm/utils/constants.js.map +1 -0
- package/dist/esm/utils/helpers.js +63 -0
- package/dist/esm/utils/helpers.js.map +1 -0
- package/dist/types/components/ValuePayButton.d.ts +3 -0
- package/dist/types/components/ValuePayProvider.d.ts +2 -0
- package/dist/types/hooks/useScript.d.ts +5 -0
- package/dist/types/hooks/useValuePay.d.ts +2 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/types/index.d.ts +74 -0
- package/dist/types/utils/constants.d.ts +5 -0
- package/dist/types/utils/helpers.d.ts +32 -0
- package/package.json +84 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useValuePay.js","sources":["../../../../src/hooks/useValuePay.ts"],"sourcesContent":["import { useCallback, useState, useRef } from \"react\";\nimport { useScript } from \"./useScript\";\nimport { normalizeConfig, normalizeResponse } from \"../utils/helpers\";\nimport { DEFAULT_SCRIPT_URL } from \"../utils/constants\";\nimport type { ValuePayConfig, UseValuePayReturn } from \"../types\";\n\nexport const useValuePay = (config: ValuePayConfig): UseValuePayReturn => {\n const scriptUrl = config.scriptUrl || DEFAULT_SCRIPT_URL;\n const isReady = useScript(scriptUrl);\n const [isProcessing, setIsProcessing] = useState(false);\n const configRef = useRef(config);\n configRef.current = config;\n\n const initialize = useCallback(\n (overrides?: Partial<ValuePayConfig>) => {\n const cfg = configRef.current;\n\n if (typeof window === \"undefined\" || !window.ValuepayCheckout) {\n cfg.onError?.(new Error(\"ValuePay script not loaded. Ensure the script URL is accessible.\"));\n return;\n }\n\n if (isProcessing) return;\n\n setIsProcessing(true);\n\n const normalized = normalizeConfig(cfg, overrides);\n const ref = normalized.transactionRef;\n\n window.ValuepayCheckout({\n ...normalized,\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n oncallback: (response: any) => {\n const res = normalizeResponse(response, ref, cfg);\n setIsProcessing(false);\n\n if (cfg.redirectUrl) {\n const url = new URL(cfg.redirectUrl);\n url.searchParams.set(\"ref\", res.ref);\n url.searchParams.set(\"status\", res.status);\n window.location.href = url.toString();\n return;\n }\n\n cfg.onCallback?.(res);\n\n if (res.status === \"SUCCESS\" || res.status === \"COMPLETED\") {\n cfg.onSuccess?.(res);\n }\n },\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onCancelled: (response: any) => {\n const res = normalizeResponse(response, ref, cfg);\n res.status = \"CANCELLED\";\n setIsProcessing(false);\n\n if (cfg.redirectUrl) {\n const url = new URL(cfg.redirectUrl);\n url.searchParams.set(\"ref\", res.ref);\n url.searchParams.set(\"status\", \"CANCELLED\");\n window.location.href = url.toString();\n return;\n }\n\n cfg.onCancelled?.(res);\n },\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onAborted: (response: any) => {\n const res = normalizeResponse(response, ref, cfg);\n res.status = \"CANCELLED\";\n setIsProcessing(false);\n cfg.onCancelled?.(res);\n },\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onClosed: (response: any) => {\n const res = normalizeResponse(response, ref, cfg);\n setIsProcessing(false);\n\n if (cfg.redirectUrl) {\n const url = new URL(cfg.redirectUrl);\n url.searchParams.set(\"ref\", res.ref);\n url.searchParams.set(\"status\", \"CLOSED\");\n window.location.href = url.toString();\n return;\n }\n\n cfg.onClose?.(res);\n },\n });\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [isReady, isProcessing],\n );\n\n return { initialize, isReady, isProcessing };\n};\n"],"names":["DEFAULT_SCRIPT_URL","useScript","useState","useRef","useCallback","normalizeConfig","normalizeResponse"],"mappings":";;;;;;;AAMO,MAAM,WAAW,GAAG,CAAC,MAAsB,KAAuB;AACvE,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAIA,4BAAkB;AACxD,IAAA,MAAM,OAAO,GAAGC,mBAAS,CAAC,SAAS,CAAC;IACpC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;AACvD,IAAA,MAAM,SAAS,GAAGC,YAAM,CAAC,MAAM,CAAC;AAChC,IAAA,SAAS,CAAC,OAAO,GAAG,MAAM;AAE1B,IAAA,MAAM,UAAU,GAAGC,iBAAW,CAC5B,CAAC,SAAmC,KAAI;;AACtC,QAAA,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO;QAE7B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;YAC7D,CAAA,EAAA,GAAA,GAAG,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA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,KAAK,CAAC;AAEtB,gBAAA,IAAI,GAAG,CAAC,WAAW,EAAE;oBACnB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC;oBACpC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC;oBACpC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC;oBACxC,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE;oBACrC;gBACF;AAEA,gBAAA,CAAA,EAAA,GAAA,GAAG,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAA,IAAA,CAAA,GAAA,EAAG,GAAG,CAAC;YACpB,CAAC;AACF,SAAA,CAAC;IACJ,CAAC;;AAED,IAAA,CAAC,OAAO,EAAE,YAAY,CAAC,CACxB;AAED,IAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE;AAC9C;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ValuePayButton = require('./components/ValuePayButton.js');
|
|
4
|
+
var ValuePayProvider = require('./components/ValuePayProvider.js');
|
|
5
|
+
var useValuePay = require('./hooks/useValuePay.js');
|
|
6
|
+
var useScript = require('./hooks/useScript.js');
|
|
7
|
+
var helpers = require('./utils/helpers.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.ValuePayButton = ValuePayButton.ValuePayButton;
|
|
12
|
+
exports.ValuePayProvider = ValuePayProvider.ValuePayProvider;
|
|
13
|
+
exports.useValuePay = useValuePay.useValuePay;
|
|
14
|
+
exports.useScript = useScript.useScript;
|
|
15
|
+
exports.generateTransactionRef = helpers.generateTransactionRef;
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_SCRIPT_URL = "https://www.valuepayng.com/js/vp-v1.js?v=1.022334450";
|
|
4
|
+
const DEFAULT_CURRENCY = "NGN";
|
|
5
|
+
const DEFAULT_CHANNELS = ["card", "transfer", "qrcode", "ussd"];
|
|
6
|
+
const TRANSACTION_REF_PREFIX = "VPS_TX_";
|
|
7
|
+
|
|
8
|
+
exports.DEFAULT_CHANNELS = DEFAULT_CHANNELS;
|
|
9
|
+
exports.DEFAULT_CURRENCY = DEFAULT_CURRENCY;
|
|
10
|
+
exports.DEFAULT_SCRIPT_URL = DEFAULT_SCRIPT_URL;
|
|
11
|
+
exports.TRANSACTION_REF_PREFIX = TRANSACTION_REF_PREFIX;
|
|
12
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/utils/constants.ts"],"sourcesContent":["import type { PaymentChannel } from \"../types\";\n\nexport const DEFAULT_SCRIPT_URL = \"https://www.valuepayng.com/js/vp-v1.js?v=1.022334450\";\nexport const DEFAULT_CURRENCY = \"NGN\";\nexport const DEFAULT_CHANNELS: PaymentChannel[] = [\"card\", \"transfer\", \"qrcode\", \"ussd\"];\nexport const TRANSACTION_REF_PREFIX = \"VPS_TX_\";\n"],"names":[],"mappings":";;AAEO,MAAM,kBAAkB,GAAG;AAC3B,MAAM,gBAAgB,GAAG;AACzB,MAAM,gBAAgB,GAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM;AAChF,MAAM,sBAAsB,GAAG;;;;;;;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constants = require('./constants.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generate a unique transaction reference.
|
|
7
|
+
*/
|
|
8
|
+
const generateTransactionRef = (length = 20) => {
|
|
9
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
10
|
+
let result = constants.TRANSACTION_REF_PREFIX;
|
|
11
|
+
for (let i = 0; i < length; i++) {
|
|
12
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Normalize the SDK config into the shape expected by window.ValuepayCheckout.
|
|
18
|
+
*/
|
|
19
|
+
const normalizeConfig = (config, overrides) => {
|
|
20
|
+
const merged = { ...config, ...overrides };
|
|
21
|
+
const ref = merged.transactionRef || generateTransactionRef();
|
|
22
|
+
return {
|
|
23
|
+
public_key: merged.publicKey,
|
|
24
|
+
transactionRef: ref,
|
|
25
|
+
amount: merged.amount,
|
|
26
|
+
currency: merged.currency || constants.DEFAULT_CURRENCY,
|
|
27
|
+
channels: merged.channels || constants.DEFAULT_CHANNELS,
|
|
28
|
+
type: "default",
|
|
29
|
+
redirect_url: merged.redirectUrl,
|
|
30
|
+
metaData: merged.metaData,
|
|
31
|
+
customer: {
|
|
32
|
+
email: merged.customer.email,
|
|
33
|
+
fullName: merged.customer.fullName,
|
|
34
|
+
phone: merged.customer.phone,
|
|
35
|
+
},
|
|
36
|
+
customisedCheckout: merged.customization
|
|
37
|
+
? {
|
|
38
|
+
title: merged.customization.title,
|
|
39
|
+
description: merged.customization.description,
|
|
40
|
+
logoLink: merged.customization.logoUrl,
|
|
41
|
+
}
|
|
42
|
+
: undefined,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Normalize the raw ValuePay response into our SDK response shape.
|
|
47
|
+
*/
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
const normalizeResponse = (raw, ref, config) => {
|
|
50
|
+
var _a;
|
|
51
|
+
return {
|
|
52
|
+
ref: (raw === null || raw === void 0 ? void 0 : raw.ref) || (raw === null || raw === void 0 ? void 0 : raw.reference) || (raw === null || raw === void 0 ? void 0 : raw.tx_ref) || ref,
|
|
53
|
+
transactionRef: (raw === null || raw === void 0 ? void 0 : raw.transactionRef) || ref,
|
|
54
|
+
status: (raw === null || raw === void 0 ? void 0 : raw.status) || ((_a = raw === null || raw === void 0 ? void 0 : raw.validation) === null || _a === void 0 ? void 0 : _a.status) || "PENDING",
|
|
55
|
+
amount: config.amount,
|
|
56
|
+
currency: config.currency || constants.DEFAULT_CURRENCY,
|
|
57
|
+
customer: config.customer,
|
|
58
|
+
paymentMethod: raw === null || raw === void 0 ? void 0 : raw.paymentMethod,
|
|
59
|
+
validation: raw === null || raw === void 0 ? void 0 : raw.validation,
|
|
60
|
+
raw,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
exports.generateTransactionRef = generateTransactionRef;
|
|
65
|
+
exports.normalizeConfig = normalizeConfig;
|
|
66
|
+
exports.normalizeResponse = normalizeResponse;
|
|
67
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../../../src/utils/helpers.ts"],"sourcesContent":["import type { ValuePayConfig, ValuePayResponse } from \"../types\";\nimport { DEFAULT_CURRENCY, DEFAULT_CHANNELS, TRANSACTION_REF_PREFIX } from \"./constants\";\n\n/**\n * Generate a unique transaction reference.\n */\nexport const generateTransactionRef = (length: number = 20): string => {\n const chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n let result = TRANSACTION_REF_PREFIX;\n for (let i = 0; i < length; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length));\n }\n return result;\n};\n\n/**\n * Normalize the SDK config into the shape expected by window.ValuepayCheckout.\n */\nexport const normalizeConfig = (config: ValuePayConfig, overrides?: Partial<ValuePayConfig>) => {\n const merged = { ...config, ...overrides };\n const ref = merged.transactionRef || generateTransactionRef();\n\n return {\n public_key: merged.publicKey,\n transactionRef: ref,\n amount: merged.amount,\n currency: merged.currency || DEFAULT_CURRENCY,\n channels: merged.channels || DEFAULT_CHANNELS,\n type: \"default\",\n redirect_url: merged.redirectUrl,\n metaData: merged.metaData,\n customer: {\n email: merged.customer.email,\n fullName: merged.customer.fullName,\n phone: merged.customer.phone,\n },\n customisedCheckout: merged.customization\n ? {\n title: merged.customization.title,\n description: merged.customization.description,\n logoLink: merged.customization.logoUrl,\n }\n : undefined,\n };\n};\n\n/**\n * Normalize the raw ValuePay response into our SDK response shape.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const normalizeResponse = (raw: any, ref: string, config: ValuePayConfig): ValuePayResponse => {\n return {\n ref: raw?.ref || raw?.reference || raw?.tx_ref || ref,\n transactionRef: raw?.transactionRef || ref,\n status: raw?.status || raw?.validation?.status || \"PENDING\",\n amount: config.amount,\n currency: config.currency || DEFAULT_CURRENCY,\n customer: config.customer,\n paymentMethod: raw?.paymentMethod,\n validation: raw?.validation,\n raw,\n };\n};\n"],"names":["TRANSACTION_REF_PREFIX","DEFAULT_CURRENCY","DEFAULT_CHANNELS"],"mappings":";;;;AAGA;;AAEG;MACU,sBAAsB,GAAG,CAAC,MAAA,GAAiB,EAAE,KAAY;IACpE,MAAM,KAAK,GAAG,gEAAgE;IAC9E,IAAI,MAAM,GAAGA,gCAAsB;AACnC,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;AAC/B,QAAA,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAClE;AACA,IAAA,OAAO,MAAM;AACf;AAEA;;AAEG;MACU,eAAe,GAAG,CAAC,MAAsB,EAAE,SAAmC,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I,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,MAAM,CAAA,IAAI,GAAG;QACrD,cAAc,EAAE,CAAA,GAAG,KAAA,IAAA,IAAH,GAAG,uBAAH,GAAG,CAAE,cAAc,KAAI,GAAG;QAC1C,MAAM,EAAE,CAAA,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,MAAM,MAAI,CAAA,EAAA,GAAA,GAAG,KAAA,IAAA,IAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAE,MAAM,CAAA,IAAI,SAAS;QAC3D,MAAM,EAAE,MAAM,CAAC,MAAM;AACrB,QAAA,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAID,0BAAgB;QAC7C,QAAQ,EAAE,MAAM,CAAC,QAAQ;AACzB,QAAA,aAAa,EAAE,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,aAAa;AACjC,QAAA,UAAU,EAAE,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,UAAU;QAC3B,GAAG;KACJ;AACH;;;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useValuePay } from '../hooks/useValuePay.js';
|
|
3
|
+
|
|
4
|
+
const ValuePayButton = ({ text, className, style, disabled, children, ...config }) => {
|
|
5
|
+
const { initialize, isReady, isProcessing } = useValuePay(config);
|
|
6
|
+
const defaultText = `Pay \u20A6${config.amount.toLocaleString()} Now`;
|
|
7
|
+
const buttonText = children || text || defaultText;
|
|
8
|
+
return (jsx("button", { type: "button", onClick: () => initialize(), disabled: disabled || !isReady || isProcessing, className: className, style: style, "aria-busy": isProcessing, "aria-label": typeof buttonText === "string" ? buttonText : "Pay Now", children: isProcessing ? "Processing..." : buttonText }));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { ValuePayButton };
|
|
12
|
+
//# sourceMappingURL=ValuePayButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValuePayButton.js","sources":["../../../../src/components/ValuePayButton.tsx"],"sourcesContent":["import React from \"react\";\nimport { useValuePay } from \"../hooks/useValuePay\";\nimport type { ValuePayButtonProps } from \"../types\";\n\nexport const ValuePayButton: React.FC<ValuePayButtonProps> = ({\n text,\n className,\n style,\n disabled,\n children,\n ...config\n}) => {\n const { initialize, isReady, isProcessing } = useValuePay(config);\n\n const defaultText = `Pay \\u20A6${config.amount.toLocaleString()} Now`;\n const buttonText = children || text || defaultText;\n\n return (\n <button\n type=\"button\"\n onClick={() => initialize()}\n disabled={disabled || !isReady || isProcessing}\n className={className}\n style={style}\n aria-busy={isProcessing}\n aria-label={typeof buttonText === \"string\" ? buttonText : \"Pay Now\"}\n >\n {isProcessing ? \"Processing...\" : buttonText}\n </button>\n );\n};\n"],"names":["_jsx"],"mappings":";;;MAIa,cAAc,GAAkC,CAAC,EAC5D,IAAI,EACJ,SAAS,EACT,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,GAAG,MAAM,EACV,KAAI;AACH,IAAA,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC;IAEjE,MAAM,WAAW,GAAG,CAAA,UAAA,EAAa,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,CAAA,IAAA,CAAM;AACrE,IAAA,MAAM,UAAU,GAAG,QAAQ,IAAI,IAAI,IAAI,WAAW;IAElD,QACEA,GAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,MAAM,UAAU,EAAE,EAC3B,QAAQ,EAAE,QAAQ,IAAI,CAAC,OAAO,IAAI,YAAY,EAC9C,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,EAAA,WAAA,EACD,YAAY,EAAA,YAAA,EACX,OAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,SAAS,EAAA,QAAA,EAElE,YAAY,GAAG,eAAe,GAAG,UAAU,EAAA,CACrC;AAEb;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { useValuePay } from '../hooks/useValuePay.js';
|
|
3
|
+
|
|
4
|
+
const ValuePayProvider = forwardRef(({ config }, ref) => {
|
|
5
|
+
const { initialize } = useValuePay(config);
|
|
6
|
+
useImperativeHandle(ref, () => ({
|
|
7
|
+
initialize: (overrides) => initialize(overrides),
|
|
8
|
+
}), [initialize]);
|
|
9
|
+
// Renders nothing — purely a data/logic container
|
|
10
|
+
return null;
|
|
11
|
+
});
|
|
12
|
+
ValuePayProvider.displayName = "ValuePayProvider";
|
|
13
|
+
|
|
14
|
+
export { ValuePayProvider };
|
|
15
|
+
//# sourceMappingURL=ValuePayProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValuePayProvider.js","sources":["../../../../src/components/ValuePayProvider.tsx"],"sourcesContent":["import { useImperativeHandle, forwardRef } from \"react\";\nimport { useValuePay } from \"../hooks/useValuePay\";\nimport type { ValuePayProviderProps, ValuePayProviderRef } from \"../types\";\n\nexport const ValuePayProvider = forwardRef<ValuePayProviderRef, ValuePayProviderProps>(\n ({ config }, ref) => {\n const { initialize } = useValuePay(config);\n\n useImperativeHandle(\n ref,\n () => ({\n initialize: (overrides) => initialize(overrides),\n }),\n [initialize],\n );\n\n // Renders nothing — purely a data/logic container\n return null;\n },\n);\n\nValuePayProvider.displayName = \"ValuePayProvider\";\n"],"names":[],"mappings":";;;AAIO,MAAM,gBAAgB,GAAG,UAAU,CACxC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,KAAI;IAClB,MAAM,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC;AAE1C,IAAA,mBAAmB,CACjB,GAAG,EACH,OAAO;QACL,UAAU,EAAE,CAAC,SAAS,KAAK,UAAU,CAAC,SAAS,CAAC;AACjD,KAAA,CAAC,EACF,CAAC,UAAU,CAAC,CACb;;AAGD,IAAA,OAAO,IAAI;AACb,CAAC;AAGH,gBAAgB,CAAC,WAAW,GAAG,kBAAkB;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dynamically loads an external script and tracks its loaded state.
|
|
5
|
+
* Deduplicates — won't inject the same script twice.
|
|
6
|
+
*/
|
|
7
|
+
const useScript = (src) => {
|
|
8
|
+
const [loaded, setLoaded] = useState(false);
|
|
9
|
+
const scriptRef = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!src || typeof document === "undefined")
|
|
12
|
+
return;
|
|
13
|
+
// Check if already loaded
|
|
14
|
+
const existing = document.querySelector(`script[src="${src}"]`);
|
|
15
|
+
if (existing) {
|
|
16
|
+
setLoaded(true);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const script = document.createElement("script");
|
|
20
|
+
script.src = src;
|
|
21
|
+
script.async = true;
|
|
22
|
+
script.onload = () => setLoaded(true);
|
|
23
|
+
script.onerror = () => {
|
|
24
|
+
console.error(`[@valuepay/react] Failed to load script: ${src}`);
|
|
25
|
+
};
|
|
26
|
+
document.body.appendChild(script);
|
|
27
|
+
scriptRef.current = script;
|
|
28
|
+
return () => {
|
|
29
|
+
if (scriptRef.current && document.body.contains(scriptRef.current)) {
|
|
30
|
+
document.body.removeChild(scriptRef.current);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}, [src]);
|
|
34
|
+
return loaded;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { useScript };
|
|
38
|
+
//# sourceMappingURL=useScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScript.js","sources":["../../../../src/hooks/useScript.ts"],"sourcesContent":["import { useEffect, useState, useRef } from \"react\";\n\n/**\n * Dynamically loads an external script and tracks its loaded state.\n * Deduplicates — won't inject the same script twice.\n */\nexport const useScript = (src: string): boolean => {\n const [loaded, setLoaded] = useState(false);\n const scriptRef = useRef<HTMLScriptElement | null>(null);\n\n useEffect(() => {\n if (!src || typeof document === \"undefined\") return;\n\n // Check if already loaded\n const existing = document.querySelector<HTMLScriptElement>(`script[src=\"${src}\"]`);\n if (existing) {\n setLoaded(true);\n return;\n }\n\n const script = document.createElement(\"script\");\n script.src = src;\n script.async = true;\n script.onload = () => setLoaded(true);\n script.onerror = () => {\n console.error(`[@valuepay/react] Failed to load script: ${src}`);\n };\n\n document.body.appendChild(script);\n scriptRef.current = script;\n\n return () => {\n if (scriptRef.current && document.body.contains(scriptRef.current)) {\n document.body.removeChild(scriptRef.current);\n }\n };\n }, [src]);\n\n return loaded;\n};\n"],"names":[],"mappings":";;AAEA;;;AAGG;AACI,MAAM,SAAS,GAAG,CAAC,GAAW,KAAa;IAChD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;AAC3C,IAAA,MAAM,SAAS,GAAG,MAAM,CAA2B,IAAI,CAAC;IAExD,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,GAAG,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE;;QAG7C,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAoB,CAAA,YAAA,EAAe,GAAG,CAAA,EAAA,CAAI,CAAC;QAClF,IAAI,QAAQ,EAAE;YACZ,SAAS,CAAC,IAAI,CAAC;YACf;QACF;QAEA,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;AAC/C,QAAA,MAAM,CAAC,GAAG,GAAG,GAAG;AAChB,QAAA,MAAM,CAAC,KAAK,GAAG,IAAI;QACnB,MAAM,CAAC,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC;AACrC,QAAA,MAAM,CAAC,OAAO,GAAG,MAAK;AACpB,YAAA,OAAO,CAAC,KAAK,CAAC,4CAA4C,GAAG,CAAA,CAAE,CAAC;AAClE,QAAA,CAAC;AAED,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;AACjC,QAAA,SAAS,CAAC,OAAO,GAAG,MAAM;AAE1B,QAAA,OAAO,MAAK;AACV,YAAA,IAAI,SAAS,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;gBAClE,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC;YAC9C;AACF,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;AAET,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useState, useRef, useCallback } from 'react';
|
|
2
|
+
import { useScript } from './useScript.js';
|
|
3
|
+
import { normalizeConfig, normalizeResponse } from '../utils/helpers.js';
|
|
4
|
+
import { DEFAULT_SCRIPT_URL } from '../utils/constants.js';
|
|
5
|
+
|
|
6
|
+
const useValuePay = (config) => {
|
|
7
|
+
const scriptUrl = config.scriptUrl || DEFAULT_SCRIPT_URL;
|
|
8
|
+
const isReady = useScript(scriptUrl);
|
|
9
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
10
|
+
const configRef = useRef(config);
|
|
11
|
+
configRef.current = config;
|
|
12
|
+
const initialize = useCallback((overrides) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const cfg = configRef.current;
|
|
15
|
+
if (typeof window === "undefined" || !window.ValuepayCheckout) {
|
|
16
|
+
(_a = cfg.onError) === null || _a === void 0 ? void 0 : _a.call(cfg, new Error("ValuePay script not loaded. Ensure the script URL is accessible."));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (isProcessing)
|
|
20
|
+
return;
|
|
21
|
+
setIsProcessing(true);
|
|
22
|
+
const normalized = normalizeConfig(cfg, overrides);
|
|
23
|
+
const ref = normalized.transactionRef;
|
|
24
|
+
window.ValuepayCheckout({
|
|
25
|
+
...normalized,
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
oncallback: (response) => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const res = normalizeResponse(response, ref, cfg);
|
|
30
|
+
setIsProcessing(false);
|
|
31
|
+
if (cfg.redirectUrl) {
|
|
32
|
+
const url = new URL(cfg.redirectUrl);
|
|
33
|
+
url.searchParams.set("ref", res.ref);
|
|
34
|
+
url.searchParams.set("status", res.status);
|
|
35
|
+
window.location.href = url.toString();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
(_a = cfg.onCallback) === null || _a === void 0 ? void 0 : _a.call(cfg, res);
|
|
39
|
+
if (res.status === "SUCCESS" || res.status === "COMPLETED") {
|
|
40
|
+
(_b = cfg.onSuccess) === null || _b === void 0 ? void 0 : _b.call(cfg, res);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
onCancelled: (response) => {
|
|
45
|
+
var _a;
|
|
46
|
+
const res = normalizeResponse(response, ref, cfg);
|
|
47
|
+
res.status = "CANCELLED";
|
|
48
|
+
setIsProcessing(false);
|
|
49
|
+
if (cfg.redirectUrl) {
|
|
50
|
+
const url = new URL(cfg.redirectUrl);
|
|
51
|
+
url.searchParams.set("ref", res.ref);
|
|
52
|
+
url.searchParams.set("status", "CANCELLED");
|
|
53
|
+
window.location.href = url.toString();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
(_a = cfg.onCancelled) === null || _a === void 0 ? void 0 : _a.call(cfg, res);
|
|
57
|
+
},
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
onAborted: (response) => {
|
|
60
|
+
var _a;
|
|
61
|
+
const res = normalizeResponse(response, ref, cfg);
|
|
62
|
+
res.status = "CANCELLED";
|
|
63
|
+
setIsProcessing(false);
|
|
64
|
+
(_a = cfg.onCancelled) === null || _a === void 0 ? void 0 : _a.call(cfg, res);
|
|
65
|
+
},
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
onClosed: (response) => {
|
|
68
|
+
var _a;
|
|
69
|
+
const res = normalizeResponse(response, ref, cfg);
|
|
70
|
+
setIsProcessing(false);
|
|
71
|
+
if (cfg.redirectUrl) {
|
|
72
|
+
const url = new URL(cfg.redirectUrl);
|
|
73
|
+
url.searchParams.set("ref", res.ref);
|
|
74
|
+
url.searchParams.set("status", "CLOSED");
|
|
75
|
+
window.location.href = url.toString();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
(_a = cfg.onClose) === null || _a === void 0 ? void 0 : _a.call(cfg, res);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
[isReady, isProcessing]);
|
|
84
|
+
return { initialize, isReady, isProcessing };
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export { useValuePay };
|
|
88
|
+
//# sourceMappingURL=useValuePay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useValuePay.js","sources":["../../../../src/hooks/useValuePay.ts"],"sourcesContent":["import { useCallback, useState, useRef } from \"react\";\nimport { useScript } from \"./useScript\";\nimport { normalizeConfig, normalizeResponse } from \"../utils/helpers\";\nimport { DEFAULT_SCRIPT_URL } from \"../utils/constants\";\nimport type { ValuePayConfig, UseValuePayReturn } from \"../types\";\n\nexport const useValuePay = (config: ValuePayConfig): UseValuePayReturn => {\n const scriptUrl = config.scriptUrl || DEFAULT_SCRIPT_URL;\n const isReady = useScript(scriptUrl);\n const [isProcessing, setIsProcessing] = useState(false);\n const configRef = useRef(config);\n configRef.current = config;\n\n const initialize = useCallback(\n (overrides?: Partial<ValuePayConfig>) => {\n const cfg = configRef.current;\n\n if (typeof window === \"undefined\" || !window.ValuepayCheckout) {\n cfg.onError?.(new Error(\"ValuePay script not loaded. Ensure the script URL is accessible.\"));\n return;\n }\n\n if (isProcessing) return;\n\n setIsProcessing(true);\n\n const normalized = normalizeConfig(cfg, overrides);\n const ref = normalized.transactionRef;\n\n window.ValuepayCheckout({\n ...normalized,\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n oncallback: (response: any) => {\n const res = normalizeResponse(response, ref, cfg);\n setIsProcessing(false);\n\n if (cfg.redirectUrl) {\n const url = new URL(cfg.redirectUrl);\n url.searchParams.set(\"ref\", res.ref);\n url.searchParams.set(\"status\", res.status);\n window.location.href = url.toString();\n return;\n }\n\n cfg.onCallback?.(res);\n\n if (res.status === \"SUCCESS\" || res.status === \"COMPLETED\") {\n cfg.onSuccess?.(res);\n }\n },\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onCancelled: (response: any) => {\n const res = normalizeResponse(response, ref, cfg);\n res.status = \"CANCELLED\";\n setIsProcessing(false);\n\n if (cfg.redirectUrl) {\n const url = new URL(cfg.redirectUrl);\n url.searchParams.set(\"ref\", res.ref);\n url.searchParams.set(\"status\", \"CANCELLED\");\n window.location.href = url.toString();\n return;\n }\n\n cfg.onCancelled?.(res);\n },\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onAborted: (response: any) => {\n const res = normalizeResponse(response, ref, cfg);\n res.status = \"CANCELLED\";\n setIsProcessing(false);\n cfg.onCancelled?.(res);\n },\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onClosed: (response: any) => {\n const res = normalizeResponse(response, ref, cfg);\n setIsProcessing(false);\n\n if (cfg.redirectUrl) {\n const url = new URL(cfg.redirectUrl);\n url.searchParams.set(\"ref\", res.ref);\n url.searchParams.set(\"status\", \"CLOSED\");\n window.location.href = url.toString();\n return;\n }\n\n cfg.onClose?.(res);\n },\n });\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [isReady, isProcessing],\n );\n\n return { initialize, isReady, isProcessing };\n};\n"],"names":[],"mappings":";;;;;AAMO,MAAM,WAAW,GAAG,CAAC,MAAsB,KAAuB;AACvE,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,kBAAkB;AACxD,IAAA,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC;IACpC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;AACvD,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;AAChC,IAAA,SAAS,CAAC,OAAO,GAAG,MAAM;AAE1B,IAAA,MAAM,UAAU,GAAG,WAAW,CAC5B,CAAC,SAAmC,KAAI;;AACtC,QAAA,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO;QAE7B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;YAC7D,CAAA,EAAA,GAAA,GAAG,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAA,IAAA,CAAA,GAAA,EAAG,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;YAC5F;QACF;AAEA,QAAA,IAAI,YAAY;YAAE;QAElB,eAAe,CAAC,IAAI,CAAC;QAErB,MAAM,UAAU,GAAG,eAAe,CAAC,GAAG,EAAE,SAAS,CAAC;AAClD,QAAA,MAAM,GAAG,GAAG,UAAU,CAAC,cAAc;QAErC,MAAM,CAAC,gBAAgB,CAAC;AACtB,YAAA,GAAG,UAAU;;AAGb,YAAA,UAAU,EAAE,CAAC,QAAa,KAAI;;gBAC5B,MAAM,GAAG,GAAG,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC;gBACjD,eAAe,CAA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,IAAA,CAAA,GAAA,EAAG,GAAG,CAAC;YACpB,CAAC;AACF,SAAA,CAAC;IACJ,CAAC;;AAED,IAAA,CAAC,OAAO,EAAE,YAAY,CAAC,CACxB;AAED,IAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE;AAC9C;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ValuePayButton } from './components/ValuePayButton.js';
|
|
2
|
+
export { ValuePayProvider } from './components/ValuePayProvider.js';
|
|
3
|
+
export { useValuePay } from './hooks/useValuePay.js';
|
|
4
|
+
export { useScript } from './hooks/useScript.js';
|
|
5
|
+
export { generateTransactionRef } from './utils/helpers.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const DEFAULT_SCRIPT_URL = "https://www.valuepayng.com/js/vp-v1.js?v=1.022334450";
|
|
2
|
+
const DEFAULT_CURRENCY = "NGN";
|
|
3
|
+
const DEFAULT_CHANNELS = ["card", "transfer", "qrcode", "ussd"];
|
|
4
|
+
const TRANSACTION_REF_PREFIX = "VPS_TX_";
|
|
5
|
+
|
|
6
|
+
export { DEFAULT_CHANNELS, DEFAULT_CURRENCY, DEFAULT_SCRIPT_URL, TRANSACTION_REF_PREFIX };
|
|
7
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/utils/constants.ts"],"sourcesContent":["import type { PaymentChannel } from \"../types\";\n\nexport const DEFAULT_SCRIPT_URL = \"https://www.valuepayng.com/js/vp-v1.js?v=1.022334450\";\nexport const DEFAULT_CURRENCY = \"NGN\";\nexport const DEFAULT_CHANNELS: PaymentChannel[] = [\"card\", \"transfer\", \"qrcode\", \"ussd\"];\nexport const TRANSACTION_REF_PREFIX = \"VPS_TX_\";\n"],"names":[],"mappings":"AAEO,MAAM,kBAAkB,GAAG;AAC3B,MAAM,gBAAgB,GAAG;AACzB,MAAM,gBAAgB,GAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM;AAChF,MAAM,sBAAsB,GAAG;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { DEFAULT_CHANNELS, DEFAULT_CURRENCY, TRANSACTION_REF_PREFIX } from './constants.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate a unique transaction reference.
|
|
5
|
+
*/
|
|
6
|
+
const generateTransactionRef = (length = 20) => {
|
|
7
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
8
|
+
let result = TRANSACTION_REF_PREFIX;
|
|
9
|
+
for (let i = 0; i < length; i++) {
|
|
10
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Normalize the SDK config into the shape expected by window.ValuepayCheckout.
|
|
16
|
+
*/
|
|
17
|
+
const normalizeConfig = (config, overrides) => {
|
|
18
|
+
const merged = { ...config, ...overrides };
|
|
19
|
+
const ref = merged.transactionRef || generateTransactionRef();
|
|
20
|
+
return {
|
|
21
|
+
public_key: merged.publicKey,
|
|
22
|
+
transactionRef: ref,
|
|
23
|
+
amount: merged.amount,
|
|
24
|
+
currency: merged.currency || DEFAULT_CURRENCY,
|
|
25
|
+
channels: merged.channels || DEFAULT_CHANNELS,
|
|
26
|
+
type: "default",
|
|
27
|
+
redirect_url: merged.redirectUrl,
|
|
28
|
+
metaData: merged.metaData,
|
|
29
|
+
customer: {
|
|
30
|
+
email: merged.customer.email,
|
|
31
|
+
fullName: merged.customer.fullName,
|
|
32
|
+
phone: merged.customer.phone,
|
|
33
|
+
},
|
|
34
|
+
customisedCheckout: merged.customization
|
|
35
|
+
? {
|
|
36
|
+
title: merged.customization.title,
|
|
37
|
+
description: merged.customization.description,
|
|
38
|
+
logoLink: merged.customization.logoUrl,
|
|
39
|
+
}
|
|
40
|
+
: undefined,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Normalize the raw ValuePay response into our SDK response shape.
|
|
45
|
+
*/
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
const normalizeResponse = (raw, ref, config) => {
|
|
48
|
+
var _a;
|
|
49
|
+
return {
|
|
50
|
+
ref: (raw === null || raw === void 0 ? void 0 : raw.ref) || (raw === null || raw === void 0 ? void 0 : raw.reference) || (raw === null || raw === void 0 ? void 0 : raw.tx_ref) || ref,
|
|
51
|
+
transactionRef: (raw === null || raw === void 0 ? void 0 : raw.transactionRef) || ref,
|
|
52
|
+
status: (raw === null || raw === void 0 ? void 0 : raw.status) || ((_a = raw === null || raw === void 0 ? void 0 : raw.validation) === null || _a === void 0 ? void 0 : _a.status) || "PENDING",
|
|
53
|
+
amount: config.amount,
|
|
54
|
+
currency: config.currency || DEFAULT_CURRENCY,
|
|
55
|
+
customer: config.customer,
|
|
56
|
+
paymentMethod: raw === null || raw === void 0 ? void 0 : raw.paymentMethod,
|
|
57
|
+
validation: raw === null || raw === void 0 ? void 0 : raw.validation,
|
|
58
|
+
raw,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { generateTransactionRef, normalizeConfig, normalizeResponse };
|
|
63
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../../../src/utils/helpers.ts"],"sourcesContent":["import type { ValuePayConfig, ValuePayResponse } from \"../types\";\nimport { DEFAULT_CURRENCY, DEFAULT_CHANNELS, TRANSACTION_REF_PREFIX } from \"./constants\";\n\n/**\n * Generate a unique transaction reference.\n */\nexport const generateTransactionRef = (length: number = 20): string => {\n const chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n let result = TRANSACTION_REF_PREFIX;\n for (let i = 0; i < length; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length));\n }\n return result;\n};\n\n/**\n * Normalize the SDK config into the shape expected by window.ValuepayCheckout.\n */\nexport const normalizeConfig = (config: ValuePayConfig, overrides?: Partial<ValuePayConfig>) => {\n const merged = { ...config, ...overrides };\n const ref = merged.transactionRef || generateTransactionRef();\n\n return {\n public_key: merged.publicKey,\n transactionRef: ref,\n amount: merged.amount,\n currency: merged.currency || DEFAULT_CURRENCY,\n channels: merged.channels || DEFAULT_CHANNELS,\n type: \"default\",\n redirect_url: merged.redirectUrl,\n metaData: merged.metaData,\n customer: {\n email: merged.customer.email,\n fullName: merged.customer.fullName,\n phone: merged.customer.phone,\n },\n customisedCheckout: merged.customization\n ? {\n title: merged.customization.title,\n description: merged.customization.description,\n logoLink: merged.customization.logoUrl,\n }\n : undefined,\n };\n};\n\n/**\n * Normalize the raw ValuePay response into our SDK response shape.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const normalizeResponse = (raw: any, ref: string, config: ValuePayConfig): ValuePayResponse => {\n return {\n ref: raw?.ref || raw?.reference || raw?.tx_ref || ref,\n transactionRef: raw?.transactionRef || ref,\n status: raw?.status || raw?.validation?.status || \"PENDING\",\n amount: config.amount,\n currency: config.currency || DEFAULT_CURRENCY,\n customer: config.customer,\n paymentMethod: raw?.paymentMethod,\n validation: raw?.validation,\n raw,\n };\n};\n"],"names":[],"mappings":";;AAGA;;AAEG;MACU,sBAAsB,GAAG,CAAC,MAAA,GAAiB,EAAE,KAAY;IACpE,MAAM,KAAK,GAAG,gEAAgE;IAC9E,IAAI,MAAM,GAAG,sBAAsB;AACnC,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;AAC/B,QAAA,MAAM,IAAI,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QAAA,GAAG,EAAE,CAAA,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,GAAG,MAAI,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,SAAS,CAAA,KAAI,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,MAAM,CAAA,IAAI,GAAG;QACrD,cAAc,EAAE,CAAA,GAAG,KAAA,IAAA,IAAH,GAAG,uBAAH,GAAG,CAAE,cAAc,KAAI,GAAG;QAC1C,MAAM,EAAE,CAAA,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,MAAM,MAAI,CAAA,EAAA,GAAA,GAAG,KAAA,IAAA,IAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAE,MAAM,CAAA,IAAI,SAAS;QAC3D,MAAM,EAAE,MAAM,CAAC,MAAM;AACrB,QAAA,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,gBAAgB;QAC7C,QAAQ,EAAE,MAAM,CAAC,QAAQ;AACzB,QAAA,aAAa,EAAE,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,aAAa;AACjC,QAAA,UAAU,EAAE,GAAG,KAAA,IAAA,IAAH,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAE,UAAU;QAC3B,GAAG;KACJ;AACH;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ValuePayButton } from "./components/ValuePayButton";
|
|
2
|
+
export { ValuePayProvider } from "./components/ValuePayProvider";
|
|
3
|
+
export { useValuePay } from "./hooks/useValuePay";
|
|
4
|
+
export { useScript } from "./hooks/useScript";
|
|
5
|
+
export { generateTransactionRef } from "./utils/helpers";
|
|
6
|
+
export type { ValuePayConfig, ValuePayResponse, ValuePayStatus, ValuePayCustomer, ValuePayCustomization, PaymentChannel, UseValuePayReturn, ValuePayButtonProps, ValuePayProviderProps, ValuePayProviderRef, } from "./types";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
+
export type PaymentChannel = "card" | "transfer" | "qrcode" | "ussd" | "mobile_money";
|
|
3
|
+
export interface ValuePayCustomer {
|
|
4
|
+
email: string;
|
|
5
|
+
fullName: string;
|
|
6
|
+
phone?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ValuePayCustomization {
|
|
9
|
+
title?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
logoUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ValuePayResponse {
|
|
14
|
+
ref: string;
|
|
15
|
+
transactionRef: string;
|
|
16
|
+
status: ValuePayStatus;
|
|
17
|
+
amount: number;
|
|
18
|
+
currency: string;
|
|
19
|
+
customer: ValuePayCustomer;
|
|
20
|
+
paymentMethod?: string;
|
|
21
|
+
validation?: {
|
|
22
|
+
status: string;
|
|
23
|
+
};
|
|
24
|
+
raw?: unknown;
|
|
25
|
+
}
|
|
26
|
+
export type ValuePayStatus = "SUCCESS" | "COMPLETED" | "FAILED" | "CANCELLED" | "DUPLICATE" | "PENDING";
|
|
27
|
+
export interface ValuePayConfig {
|
|
28
|
+
publicKey: string;
|
|
29
|
+
amount: number;
|
|
30
|
+
customer: ValuePayCustomer;
|
|
31
|
+
currency?: string;
|
|
32
|
+
channels?: PaymentChannel[];
|
|
33
|
+
transactionRef?: string;
|
|
34
|
+
redirectUrl?: string;
|
|
35
|
+
metaData?: Record<string, unknown>;
|
|
36
|
+
customization?: ValuePayCustomization;
|
|
37
|
+
onSuccess?: (response: ValuePayResponse) => void;
|
|
38
|
+
onClose?: (response: ValuePayResponse) => void;
|
|
39
|
+
onCancelled?: (response: ValuePayResponse) => void;
|
|
40
|
+
onCallback?: (response: ValuePayResponse) => void;
|
|
41
|
+
onError?: (error: Error) => void;
|
|
42
|
+
scriptUrl?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface UseValuePayReturn {
|
|
45
|
+
/** Call this to open the ValuePay checkout modal */
|
|
46
|
+
initialize: (overrides?: Partial<ValuePayConfig>) => void;
|
|
47
|
+
/** True when the ValuePay script has finished loading */
|
|
48
|
+
isReady: boolean;
|
|
49
|
+
/** True while a payment is actively being processed */
|
|
50
|
+
isProcessing: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface ValuePayButtonProps extends ValuePayConfig {
|
|
53
|
+
/** Button text override. Default: "Pay ₦{amount}" */
|
|
54
|
+
text?: string;
|
|
55
|
+
/** Additional CSS class names */
|
|
56
|
+
className?: string;
|
|
57
|
+
/** Additional inline styles */
|
|
58
|
+
style?: CSSProperties;
|
|
59
|
+
/** Disable the button */
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
/** Custom children override the default button text */
|
|
62
|
+
children?: ReactNode;
|
|
63
|
+
}
|
|
64
|
+
export interface ValuePayProviderProps {
|
|
65
|
+
config: ValuePayConfig;
|
|
66
|
+
}
|
|
67
|
+
export interface ValuePayProviderRef {
|
|
68
|
+
initialize: (overrides?: Partial<ValuePayConfig>) => void;
|
|
69
|
+
}
|
|
70
|
+
declare global {
|
|
71
|
+
interface Window {
|
|
72
|
+
ValuepayCheckout: (config: Record<string, unknown>) => void;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PaymentChannel } from "../types";
|
|
2
|
+
export declare const DEFAULT_SCRIPT_URL = "https://www.valuepayng.com/js/vp-v1.js?v=1.022334450";
|
|
3
|
+
export declare const DEFAULT_CURRENCY = "NGN";
|
|
4
|
+
export declare const DEFAULT_CHANNELS: PaymentChannel[];
|
|
5
|
+
export declare const TRANSACTION_REF_PREFIX = "VPS_TX_";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ValuePayConfig, ValuePayResponse } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Generate a unique transaction reference.
|
|
4
|
+
*/
|
|
5
|
+
export declare const generateTransactionRef: (length?: number) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Normalize the SDK config into the shape expected by window.ValuepayCheckout.
|
|
8
|
+
*/
|
|
9
|
+
export declare const normalizeConfig: (config: ValuePayConfig, overrides?: Partial<ValuePayConfig>) => {
|
|
10
|
+
public_key: string;
|
|
11
|
+
transactionRef: string;
|
|
12
|
+
amount: number;
|
|
13
|
+
currency: string;
|
|
14
|
+
channels: import("../types").PaymentChannel[];
|
|
15
|
+
type: string;
|
|
16
|
+
redirect_url: string | undefined;
|
|
17
|
+
metaData: Record<string, unknown> | undefined;
|
|
18
|
+
customer: {
|
|
19
|
+
email: string;
|
|
20
|
+
fullName: string;
|
|
21
|
+
phone: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
customisedCheckout: {
|
|
24
|
+
title: string | undefined;
|
|
25
|
+
description: string | undefined;
|
|
26
|
+
logoLink: string | undefined;
|
|
27
|
+
} | undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Normalize the raw ValuePay response into our SDK response shape.
|
|
31
|
+
*/
|
|
32
|
+
export declare const normalizeResponse: (raw: any, ref: string, config: ValuePayConfig) => ValuePayResponse;
|