-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathpaystack-button.tsx
More file actions
39 lines (36 loc) · 1012 Bytes
/
paystack-button.tsx
File metadata and controls
39 lines (36 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, {ReactNode} from 'react';
import usePaystackPayment from './use-paystack';
import {callback, PaystackProps} from './types';
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;
}
const PaystackButton = ({
text,
className,
children,
onSuccess,
onClose,
onClick,
...others
}: PaystackButtonProps): JSX.Element => {
const initializePayment = usePaystackPayment(others);
return (
<button className={className} onClick={(): void => {
if (onClick) {
if(onClick()) { // proceed to payment if true
initializePayment(onSuccess, onClose);
}
} else {
initializePayment(onSuccess, onClose);
}
}}>
{text || children}
</button>
);
};
export default PaystackButton;