Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion libs/paystack-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface PaystackButtonProps extends PaystackProps {
text?: string;
className?: string;
children?: ReactNode;
onClick?: Function; // a function that is run before the payment function, if true is returned proceed to the payment function
onSuccess?: callback;
onClose?: callback;
}
Expand All @@ -16,11 +17,20 @@ const PaystackButton = ({
children,
onSuccess,
onClose,
onClick,
...others
}: PaystackButtonProps): JSX.Element => {
const initializePayment = usePaystackPayment(others);
return (
<button className={className} onClick={(): void => initializePayment(onSuccess, onClose)}>
<button className={className} onClick={(): void => {
if (onClick) {
if(onClick()) { // proceed to payment if true
initializePayment(onSuccess, onClose);
}
} else {
initializePayment(onSuccess, onClose);
}
}}>
{text || children}
</button>
);
Expand Down