UNPKG

react-isw-webpay

Version:

React integration for Interswitch WebPay payment gateway

117 lines (111 loc) 3.24 kB
type PaymentEnvironment = 'production' | 'staging' | 'development'; interface PaymentRequest { merchant_code: string; pay_item_id: string; txn_ref: string; site_redirect_url?: string; amount: number; currency: number | string; mode: 'TEST' | 'LIVE'; cust_id?: string; split_accounts?: string; onComplete?: (response: PaymentResponse) => void; [key: string]: any; } interface PaymentResponse { resp: string; desc: string; txnref: string; payRef: string; retRef: string; amount: number; apprAmt: number; cardNum?: string; mac?: string; bpResp?: string; bpTrxnRef?: string; rechPin?: string; } interface WebPayHookOptions { onSuccess?: (response: PaymentResponse) => void; onError?: (error: PaymentResponse) => void; onCancel?: () => void; } declare global { interface Window { webpayCheckout?: (data: any) => void; } } interface WebPayModalProps { isOpen: boolean; onClose: () => void; paymentRequest: PaymentRequest; options?: WebPayHookOptions; } declare const WebPayModal: React.FC<WebPayModalProps>; declare const useWebPay: () => { initiatePayment: (paymentRequest: PaymentRequest, options?: WebPayHookOptions) => Promise<void>; isLoading: boolean; error: string | null; clearError: () => void; }; interface WebPayModalState { isLoading: boolean; error: string | null; hasInitiated: boolean; initiatePayment: () => void; reset: () => void; close: () => void; } interface UseWebPayModalProps { isOpen: boolean; onClose: () => void; paymentRequest: PaymentRequest; options?: WebPayHookOptions; } declare const useWebPayModal: ({ isOpen, onClose, paymentRequest, options, }: UseWebPayModalProps) => WebPayModalState; /** * Creates a WebPay configuration object with environment-based settings */ /** * Validates a payment request object */ declare const validatePaymentRequest: (request: PaymentRequest) => { isValid: boolean; errors: string[]; }; /** * Validates WebPay configuration */ declare const validateWebPayConfig: (config: { merchantCode: string; payItemId: string; mode: string; scriptUrl?: string; }) => { isValid: boolean; errors: string[]; }; /** * Formats amount for display */ declare const formatAmount: (amount: number, currency?: string, locale?: string) => string; /** * Generates a unique transaction reference */ declare const generateTransactionRef: (prefix?: string) => string; /** * Converts amount to kobo (for NGN) or cents (for other currencies) */ declare const convertToMinorUnits: (amount: number, currency?: string) => number; /** * Converts from kobo/cents back to major units */ declare const convertFromMinorUnits: (amount: number) => number; declare const validationPatterns: { readonly email: RegExp; readonly phone: RegExp; readonly transactionRef: RegExp; }; export { WebPayModal, convertFromMinorUnits, convertToMinorUnits, formatAmount, generateTransactionRef, useWebPay, useWebPayModal, validatePaymentRequest, validateWebPayConfig, validationPatterns }; export type { PaymentEnvironment, PaymentRequest, PaymentResponse, WebPayHookOptions };