Skip to content

Commit

Permalink
refactor(paystack-connect): refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
iamraphson committed May 6, 2024
1 parent 5b389a7 commit 25efb48
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 240 deletions.
49 changes: 5 additions & 44 deletions dist/index.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.es.js.map

Large diffs are not rendered by default.

49 changes: 5 additions & 44 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/paystack-script.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/test/paystack-script.test.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export interface PaystackProps {
subaccount?: string;
transaction_charge?: number;
bearer?: Bearer;
'data-custom-button'?: string;
split_code?: string;
split?: Record<string, any>;
connect_split?: PaystackConnectSplit[];
connect_account?: string;
onBankTransferConfirmationPending?: callback;
}
export type InitializePayment = (options: {
onSuccess?: callback;
Expand Down
50 changes: 5 additions & 45 deletions example/src/dist/index.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/src/dist/index.es.js.map

Large diffs are not rendered by default.

50 changes: 5 additions & 45 deletions example/src/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/src/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/src/dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export interface PaystackProps {
subaccount?: string;
transaction_charge?: number;
bearer?: Bearer;
'data-custom-button'?: string;
split_code?: string;
split?: Record<string, any>;
connect_split?: PaystackConnectSplit[];
connect_account?: string;
onBankTransferConfirmationPending?: callback;
}
export type InitializePayment = (options: {
onSuccess?: callback;
Expand Down
1 change: 0 additions & 1 deletion libs/test/use-paystack.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('usePaystackPayment()', () => {
channels: ['mobile_money', 'ussd'],
plan: '1',
subaccount: 'ACCT_olodo',
'data-custom-button': 'savage',
quantity: 2,
split_code: 'SPL_ehshjerjh1232343',
firstname: '404',
Expand Down
2 changes: 1 addition & 1 deletion libs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export interface PaystackProps {
subaccount?: string;
transaction_charge?: number;
bearer?: Bearer;
'data-custom-button'?: string;
split_code?: string;
split?: Record<string, any>;
connect_split?: PaystackConnectSplit[];
connect_account?: string;
onBankTransferConfirmationPending?: callback;
}

export type InitializePayment = (options: {
Expand Down
75 changes: 26 additions & 49 deletions libs/use-paystack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,47 @@ export default function usePaystackPayment(hookConfig: HookConfig): InitializePa
email,
amount,
reference,
metadata = {},
metadata,
currency = 'NGN',
channels,
label = '',
plan = '',
quantity = '',
subaccount = '',
transaction_charge = 0,
bearer = 'account',
label,
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,
ref: reference,
email,
firstname,
lastname,
amount,
currency,
plan,
subaccount,
transaction_charge,
bearer,
label,
metadata,
...(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}),
};

if (phone) {
paystackArgs.phone = phone;
}

if (quantity) {
paystackArgs.quantity = quantity;
}

if (channels) {
paystackArgs.channels = channels;
}

if (split) {
paystackArgs.split = split;
}

if (split_code) {
paystackArgs.split_code = split_code;
}

if (connect_split) {
paystackArgs.connect_split = connect_split;
}

if (connect_account) {
paystackArgs.connect_account = connect_account;
}

if (args['data-custom-button']) {
paystackArgs['data-custom-button'] = args['data-custom-button'];
}

callPaystackPop(paystackArgs);
}

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
},
"homepage": "https://github.com/iamraphson/react-paystack#readme",
"peerDependencies": {
"@paystack/inline-js": "^2.18.0",
"react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@paystack/inline-js": "^2.18.0"
},
"devDependencies": {
"@babel/core": "^7.21.4",
"@babel/preset-env": "^7.21.4",
Expand Down Expand Up @@ -74,7 +76,6 @@
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-typescript2": "^0.36.0",
"ts-jest": "^29.1.0",
"typescript": "^5.0.3",
"@paystack/inline-js": "^2.18.0"
"typescript": "^5.0.3"
}
}

0 comments on commit 25efb48

Please sign in to comment.