Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade inline to v2 #100

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
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
97 changes: 7 additions & 90 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.

95 changes: 6 additions & 89 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.

2 changes: 1 addition & 1 deletion dist/paystack-actions.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare let callPaystackPop: (paystackArgs: Record<string, any>) => void;
export declare const callPaystackPop: (paystackArgs: Record<string, any>) => void;
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
329 changes: 74 additions & 255 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.

325 changes: 72 additions & 253 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/paystack-actions.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare let callPaystackPop: (paystackArgs: Record<string, any>) => void;
export declare const callPaystackPop: (paystackArgs: Record<string, any>) => void;
19 changes: 13 additions & 6 deletions example/src/dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type Currency = 'NGN' | 'GHS' | 'USD' | 'ZAR' | 'KES' | 'XOF';
type PaymentChannels = 'bank' | 'card' | 'qr' | 'ussd' | 'mobile_money' | 'eft' | 'bank_transfer' | 'payattitude';
export type Currency = 'NGN' | 'GHS' | 'USD' | 'ZAR' | 'KES' | 'XOF';
export type PaymentChannels = 'bank' | 'card' | 'qr' | 'ussd' | 'mobile_money' | 'eft' | 'bank_transfer' | 'payattitude';
type Bearer = 'account' | 'subaccount';
type phone = number | string;
interface PaystackCustomFields {
Expand All @@ -13,6 +13,10 @@ interface PaystackMetadata {
interface PaystackMetadata {
[key: string]: any;
}
interface PaystackConnectSplit {
account_id: string;
share: number;
}
export type callback = (response?: any) => void;
export interface PaystackProps {
publicKey: string;
Expand All @@ -23,21 +27,24 @@ export interface PaystackProps {
phone?: phone;
reference?: string;
metadata?: PaystackMetadata;
currency?: Currency;
channels?: PaymentChannels[];
currency?: Currency | string;
channels?: PaymentChannels[] | string[];
label?: string;
plan?: string;
quantity?: number;
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;
onClose?: callback;
config?: PaystackProps;
config?: Omit<PaystackProps, 'publicKey'>;
}) => void;
export type HookConfig = Omit<Partial<PaystackProps>, 'publicKey'> & Pick<PaystackProps, 'publicKey'>;
export {};
4 changes: 2 additions & 2 deletions example/src/dist/use-paystack.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { InitializePayment, PaystackProps } from './types';
export default function usePaystackPayment(hookConfig: Partial<PaystackProps>): InitializePayment;
import { HookConfig, InitializePayment } from './types';
export default function usePaystackPayment(hookConfig: HookConfig): InitializePayment;
10 changes: 5 additions & 5 deletions libs/paystack-actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
export let callPaystackPop = (paystackArgs: Record<string, any>): void => {
// @ts-ignore
const handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs);
handler && handler.openIframe();
import PaystackPop from '@paystack/inline-js';

export const callPaystackPop = (paystackArgs: Record<string, any>): void => {
const paystack = new PaystackPop();
paystack.newTransaction(paystackArgs);
};
62 changes: 0 additions & 62 deletions libs/paystack-script.ts

This file was deleted.

2 changes: 2 additions & 0 deletions libs/src/types/@paystack/inline-js/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//@paystack/inline-js/index.d.ts
declare module '@paystack/inline-js';
5 changes: 1 addition & 4 deletions libs/test/paystack-button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';
// @ts-ignore
import {renderHook, cleanup, act} from '@testing-library/react-hooks';
import {cleanup} from '@testing-library/react-hooks';
import {render, fireEvent} from '@testing-library/react';
import {callPaystackPop} from '../paystack-actions';
import usePaystackScript from '../paystack-script';
import PaystackButton from '../paystack-button';
import {config} from './fixtures';

Expand All @@ -21,7 +19,6 @@ describe('<PaystackButton />', () => {
beforeEach(() => {
// @ts-ignore
callPaystackPop = jest.fn();
renderHook(() => usePaystackScript());
});

afterAll(() => {
Expand Down
5 changes: 1 addition & 4 deletions libs/test/paystack-provider.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';
// @ts-ignore
import {renderHook, cleanup, act} from '@testing-library/react-hooks';
import {cleanup} from '@testing-library/react-hooks';
import {render, fireEvent} from '@testing-library/react';
import {callPaystackPop} from '../paystack-actions';
import usePaystackScript from '../paystack-script';
import PaystackConsumer from '../paystack-consumer';
import {config} from './fixtures';

Expand All @@ -20,7 +18,6 @@ describe('<PaystackProvider />', () => {
beforeEach(() => {
// @ts-ignore
callPaystackPop = jest.fn();
renderHook(() => usePaystackScript());
});

afterAll(() => {
Expand Down
28 changes: 0 additions & 28 deletions libs/test/paystack-script.test.ts

This file was deleted.

4 changes: 0 additions & 4 deletions libs/test/use-paystack.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// @ts-ignore
import {renderHook, cleanup, act} from '@testing-library/react-hooks';
import {render, fireEvent} from '@testing-library/react';
import React from 'react';
import usePaystackPayment from '../use-paystack';
import {callPaystackPop} from '../paystack-actions';
import usePaystackScript from '../paystack-script';
import {config} from './fixtures';
import {Currency, PaymentChannels} from '../types';

Expand All @@ -16,7 +14,6 @@ describe('usePaystackPayment()', () => {
beforeEach(() => {
// @ts-ignore
callPaystackPop = jest.fn();
renderHook(() => usePaystackScript());
});

afterAll(() => {
Expand Down Expand Up @@ -66,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
83 changes: 34 additions & 49 deletions libs/use-paystack.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {useEffect} from 'react';
import {HookConfig, InitializePayment} from './types';
import usePaystackScript from './paystack-script';
import {callPaystackPop} from './paystack-actions';

export default function usePaystackPayment(hookConfig: HookConfig): InitializePayment {
const [scriptLoaded, scriptError] = usePaystackScript();

function initializePayment({config, onSuccess, onClose}: Parameters<InitializePayment>[0]): void {
if (scriptError) {
throw new Error('Unable to load paystack inline script');
}

const args = {...hookConfig, ...config};

const {
Expand All @@ -21,56 +13,49 @@ 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,
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}),
};

if (scriptLoaded) {
const paystackArgs: Record<string, any> = {
callback: onSuccess ? onSuccess : () => null,
onClose: onClose ? onClose : () => null,
key: publicKey,
ref: reference,
email,
firstname,
lastname,
phone,
amount,
currency,
plan,
quantity,
channels,
subaccount,
transaction_charge,
bearer,
label,
metadata,
split,
split_code,
connect_split,
connect_account,
'data-custom-button': args['data-custom-button'] || '',
};
callPaystackPop(paystackArgs);
}
callPaystackPop(paystackArgs);
}

useEffect(() => {
if (scriptError) {
throw new Error('Unable to load paystack inline script');
}
}, [scriptError]);

return initializePayment;
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-paystack",
"version": "5.0.0",
"version": "6.0.0",
"description": "This is an reactJS library for implementing paystack payment gateway",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down Expand Up @@ -28,7 +28,7 @@
"paystack",
"Gateway"
],
"author": "Ayeni Olusegun <[email protected]>",
"author": "Olusegun Ayeni <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/iamraphson/react-paystack/issues"
Expand All @@ -38,6 +38,9 @@
"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
Loading