zips-react-native-sdk-test
Version:
Lightweight ZIPS Payment Gateway SDK for React Native - Complete payment solution with card payments, wallet payments (AfrMoney & ZApp), netbanking, and native UI design
61 lines (60 loc) • 2.25 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useState } from 'react';
const zipsContext = createContext(undefined);
export const useZipsContext = () => {
const context = useContext(zipsContext);
if (!context) {
throw new Error('useZipsContext must be used within a ZipsProvider');
}
return context;
};
export const ZipsProvider = ({ children }) => {
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
const [order, setOrder] = useState(null);
const [paymentMethod, setPaymentMethod] = useState({});
const [paymentDetails, setPaymentDetails] = useState({});
const [transactionDetails, setTransactionDetails] = useState(null);
const [environment, setEnvironment] = useState('sandbox');
const [apiKey, setApiKey] = useState(undefined);
const [currentStep, setCurrentStep] = useState('method-selection');
const setZips = (zips) => {
setPaymentMethod(zips === null || zips === void 0 ? void 0 : zips.paymentMethod);
setPaymentDetails(zips === null || zips === void 0 ? void 0 : zips.paymentDetails);
setEnvironment((zips === null || zips === void 0 ? void 0 : zips.environment) || 'sandbox');
setApiKey(zips === null || zips === void 0 ? void 0 : zips.apiKey);
};
const resetZips = () => {
setIsLoading(true);
setError(null);
setOrder(null);
setPaymentMethod({});
setPaymentDetails({});
setApiKey(undefined);
setTransactionDetails(null);
setEnvironment('sandbox');
setCurrentStep('method-selection');
};
return (_jsx(zipsContext.Provider, { value: {
isLoading,
setIsLoading,
error,
setError,
order,
setOrder,
paymentMethod,
setPaymentMethod,
paymentDetails,
setPaymentDetails,
environment,
setEnvironment,
transactionDetails,
setTransactionDetails,
apiKey,
setApiKey,
currentStep,
setCurrentStep,
setZips,
resetZips,
}, children: children }));
};