@reevit/react 0.2.8 → 0.2.9
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.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +29 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,8 @@ interface ReevitCheckoutConfig {
|
|
|
23
23
|
metadata?: Record<string, unknown>;
|
|
24
24
|
/** Payment methods to display */
|
|
25
25
|
paymentMethods?: PaymentMethod[];
|
|
26
|
+
/** Optional existing payment intent to use instead of creating a new one */
|
|
27
|
+
initialPaymentIntent?: PaymentIntent;
|
|
26
28
|
}
|
|
27
29
|
interface ReevitCheckoutCallbacks {
|
|
28
30
|
/** Called when payment is successful */
|
|
@@ -39,6 +41,10 @@ interface ReevitCheckoutProps extends ReevitCheckoutConfig, ReevitCheckoutCallba
|
|
|
39
41
|
children?: React.ReactNode;
|
|
40
42
|
/** Whether to open automatically */
|
|
41
43
|
autoOpen?: boolean;
|
|
44
|
+
/** Controlled open state */
|
|
45
|
+
isOpen?: boolean;
|
|
46
|
+
/** Callback for open state changes */
|
|
47
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
42
48
|
/** Custom theme */
|
|
43
49
|
theme?: ReevitTheme;
|
|
44
50
|
/** Custom API base URL (for testing or self-hosted deployments) */
|
|
@@ -132,7 +138,7 @@ interface ReevitContextValue {
|
|
|
132
138
|
currency: string;
|
|
133
139
|
}
|
|
134
140
|
declare function useReevitContext(): ReevitContextValue;
|
|
135
|
-
declare function ReevitCheckout({ publicKey, amount, currency, email, phone, reference, metadata, paymentMethods, onSuccess, onError, onClose, onStateChange, children, autoOpen, theme, apiBaseUrl, }: ReevitCheckoutProps): react_jsx_runtime.JSX.Element;
|
|
141
|
+
declare function ReevitCheckout({ publicKey, amount, currency, email, phone, reference, metadata, paymentMethods, onSuccess, onError, onClose, onStateChange, children, autoOpen, isOpen: controlledIsOpen, onOpenChange, theme, apiBaseUrl, }: ReevitCheckoutProps): react_jsx_runtime.JSX.Element;
|
|
136
142
|
|
|
137
143
|
interface PaymentMethodSelectorProps {
|
|
138
144
|
methods: PaymentMethod[];
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ interface ReevitCheckoutConfig {
|
|
|
23
23
|
metadata?: Record<string, unknown>;
|
|
24
24
|
/** Payment methods to display */
|
|
25
25
|
paymentMethods?: PaymentMethod[];
|
|
26
|
+
/** Optional existing payment intent to use instead of creating a new one */
|
|
27
|
+
initialPaymentIntent?: PaymentIntent;
|
|
26
28
|
}
|
|
27
29
|
interface ReevitCheckoutCallbacks {
|
|
28
30
|
/** Called when payment is successful */
|
|
@@ -39,6 +41,10 @@ interface ReevitCheckoutProps extends ReevitCheckoutConfig, ReevitCheckoutCallba
|
|
|
39
41
|
children?: React.ReactNode;
|
|
40
42
|
/** Whether to open automatically */
|
|
41
43
|
autoOpen?: boolean;
|
|
44
|
+
/** Controlled open state */
|
|
45
|
+
isOpen?: boolean;
|
|
46
|
+
/** Callback for open state changes */
|
|
47
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
42
48
|
/** Custom theme */
|
|
43
49
|
theme?: ReevitTheme;
|
|
44
50
|
/** Custom API base URL (for testing or self-hosted deployments) */
|
|
@@ -132,7 +138,7 @@ interface ReevitContextValue {
|
|
|
132
138
|
currency: string;
|
|
133
139
|
}
|
|
134
140
|
declare function useReevitContext(): ReevitContextValue;
|
|
135
|
-
declare function ReevitCheckout({ publicKey, amount, currency, email, phone, reference, metadata, paymentMethods, onSuccess, onError, onClose, onStateChange, children, autoOpen, theme, apiBaseUrl, }: ReevitCheckoutProps): react_jsx_runtime.JSX.Element;
|
|
141
|
+
declare function ReevitCheckout({ publicKey, amount, currency, email, phone, reference, metadata, paymentMethods, onSuccess, onError, onClose, onStateChange, children, autoOpen, isOpen: controlledIsOpen, onOpenChange, theme, apiBaseUrl, }: ReevitCheckoutProps): react_jsx_runtime.JSX.Element;
|
|
136
142
|
|
|
137
143
|
interface PaymentMethodSelectorProps {
|
|
138
144
|
methods: PaymentMethod[];
|
package/dist/index.js
CHANGED
|
@@ -279,9 +279,19 @@ function mapToPaymentIntent(response, config) {
|
|
|
279
279
|
}
|
|
280
280
|
function useReevit(options) {
|
|
281
281
|
const { config, onSuccess, onError, onClose, onStateChange, apiBaseUrl } = options;
|
|
282
|
-
const [state, dispatch] = react.useReducer(reevitReducer,
|
|
282
|
+
const [state, dispatch] = react.useReducer(reevitReducer, {
|
|
283
|
+
...initialState,
|
|
284
|
+
status: config.initialPaymentIntent ? "ready" : "idle",
|
|
285
|
+
paymentIntent: config.initialPaymentIntent || null
|
|
286
|
+
});
|
|
283
287
|
const apiClientRef = react.useRef(null);
|
|
284
|
-
const initializingRef = react.useRef(
|
|
288
|
+
const initializingRef = react.useRef(!!config.initialPaymentIntent);
|
|
289
|
+
react.useEffect(() => {
|
|
290
|
+
if (config.initialPaymentIntent && (!state.paymentIntent || state.paymentIntent.id !== config.initialPaymentIntent.id)) {
|
|
291
|
+
dispatch({ type: "INIT_SUCCESS", payload: config.initialPaymentIntent });
|
|
292
|
+
initializingRef.current = true;
|
|
293
|
+
}
|
|
294
|
+
}, [config.initialPaymentIntent, state.paymentIntent?.id]);
|
|
285
295
|
if (!apiClientRef.current) {
|
|
286
296
|
apiClientRef.current = new ReevitAPIClient({
|
|
287
297
|
publicKey: config.publicKey,
|
|
@@ -769,10 +779,23 @@ function ReevitCheckout({
|
|
|
769
779
|
// UI
|
|
770
780
|
children,
|
|
771
781
|
autoOpen = false,
|
|
782
|
+
isOpen: controlledIsOpen,
|
|
783
|
+
onOpenChange,
|
|
772
784
|
theme,
|
|
773
785
|
apiBaseUrl
|
|
774
786
|
}) {
|
|
775
|
-
const [
|
|
787
|
+
const [internalIsOpen, setInternalIsOpen] = react.useState(autoOpen);
|
|
788
|
+
const isOpen = controlledIsOpen !== void 0 ? controlledIsOpen : internalIsOpen;
|
|
789
|
+
const setIsOpen = react.useCallback(
|
|
790
|
+
(value) => {
|
|
791
|
+
if (onOpenChange) {
|
|
792
|
+
onOpenChange(value);
|
|
793
|
+
} else {
|
|
794
|
+
setInternalIsOpen(value);
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
[onOpenChange]
|
|
798
|
+
);
|
|
776
799
|
const [showPSPBridge, setShowPSPBridge] = react.useState(false);
|
|
777
800
|
const [momoData, setMomoData] = react.useState(null);
|
|
778
801
|
const {
|
|
@@ -810,16 +833,17 @@ function ReevitCheckout({
|
|
|
810
833
|
}
|
|
811
834
|
}, [isOpen, status, initialize]);
|
|
812
835
|
const handleOpen = react.useCallback(() => {
|
|
836
|
+
if (controlledIsOpen !== void 0) return;
|
|
813
837
|
setIsOpen(true);
|
|
814
838
|
setShowPSPBridge(false);
|
|
815
839
|
setMomoData(null);
|
|
816
|
-
}, []);
|
|
840
|
+
}, [controlledIsOpen, setIsOpen]);
|
|
817
841
|
const handleClose = react.useCallback(() => {
|
|
818
842
|
closeCheckout();
|
|
819
843
|
setIsOpen(false);
|
|
820
844
|
setShowPSPBridge(false);
|
|
821
845
|
setMomoData(null);
|
|
822
|
-
}, [closeCheckout]);
|
|
846
|
+
}, [closeCheckout, setIsOpen]);
|
|
823
847
|
const handleMethodSelect = react.useCallback(
|
|
824
848
|
(method) => {
|
|
825
849
|
selectMethod(method);
|