-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathuse-paystack.ts
62 lines (59 loc) · 1.75 KB
/
use-paystack.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {HookConfig, InitializePayment} from './types';
import {callPaystackPop} from './paystack-actions';
export default function usePaystackPayment(hookConfig: HookConfig): InitializePayment {
function initializePayment({config, onSuccess, onClose}: Parameters<InitializePayment>[0]): void {
const args = {...hookConfig, ...config};
const {
publicKey,
firstname,
lastname,
phone,
email,
amount,
reference,
metadata,
currency = 'NGN',
channels,
label,
accessCode,
plan,
quantity,
subaccount,
transaction_charge,
bearer,
split,
split_code,
connect_account,
connect_split,
onBankTransferConfirmationPending,
} = args;
const paystackArgs: Record<string, any> = {
onSuccess: onSuccess ? onSuccess : () => null,
onCancel: onClose ? onClose : () => null,
key: publicKey,
email,
amount,
...(firstname && {firstname}),
...(lastname && {lastname}),
...(phone && {phone}),
...(reference && {ref: reference}),
...(currency && {currency}),
...(channels && {channels}),
...(metadata && {metadata}),
...(label && {label}),
...(onBankTransferConfirmationPending && {onBankTransferConfirmationPending}),
...(subaccount && {subaccount}),
...(transaction_charge && {transaction_charge}),
...(bearer && {bearer}),
...(split && {split}),
...(split_code && {split_code}),
...(plan && {plan}),
...(quantity && {quantity}),
...(connect_split && {connect_split}),
...(connect_account && {connect_account}),
...(accessCode && {accessCode}),
};
callPaystackPop(paystackArgs);
}
return initializePayment;
}