From 47955d6435efc2620dcaff5ee82fa6763559d092 Mon Sep 17 00:00:00 2001 From: Olusegun Ayeni Date: Thu, 25 Apr 2024 05:36:56 -0700 Subject: [PATCH] implement connect into react paystack --- dist/index.es.js | 4 +- dist/index.es.js.map | 2 +- dist/index.js | 4 +- dist/index.js.map | 2 +- dist/types.d.ts | 6 + example/src/App.js | 24 +- example/src/dist/index.es.js | 402 ++++++++++++++++++++------------ example/src/dist/index.js | 398 +++++++++++++++++++------------ libs/test/use-paystack.test.tsx | 24 +- libs/types.ts | 7 + libs/use-paystack.ts | 4 + 11 files changed, 560 insertions(+), 317 deletions(-) diff --git a/dist/index.es.js b/dist/index.es.js index b4441a4..efa2bfa 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -108,7 +108,7 @@ function usePaystackPayment(hookConfig) { throw new Error('Unable to load paystack inline script'); } var args = __assign(__assign({}, hookConfig), config); - var publicKey = args.publicKey, firstname = args.firstname, lastname = args.lastname, phone = args.phone, email = args.email, amount = args.amount, reference = args.reference, _b = args.metadata, metadata = _b === void 0 ? {} : _b, _c = args.currency, currency = _c === void 0 ? 'NGN' : _c, channels = args.channels, _d = args.label, label = _d === void 0 ? '' : _d, _e = args.plan, plan = _e === void 0 ? '' : _e, _f = args.quantity, quantity = _f === void 0 ? '' : _f, _g = args.subaccount, subaccount = _g === void 0 ? '' : _g, _h = args.transaction_charge, transaction_charge = _h === void 0 ? 0 : _h, _j = args.bearer, bearer = _j === void 0 ? 'account' : _j, split = args.split, split_code = args.split_code; + var publicKey = args.publicKey, firstname = args.firstname, lastname = args.lastname, phone = args.phone, email = args.email, amount = args.amount, reference = args.reference, _b = args.metadata, metadata = _b === void 0 ? {} : _b, _c = args.currency, currency = _c === void 0 ? 'NGN' : _c, channels = args.channels, _d = args.label, label = _d === void 0 ? '' : _d, _e = args.plan, plan = _e === void 0 ? '' : _e, _f = args.quantity, quantity = _f === void 0 ? '' : _f, _g = args.subaccount, subaccount = _g === void 0 ? '' : _g, _h = args.transaction_charge, transaction_charge = _h === void 0 ? 0 : _h, _j = args.bearer, bearer = _j === void 0 ? 'account' : _j, split = args.split, split_code = args.split_code, connect_account = args.connect_account, connect_split = args.connect_split; if (scriptLoaded) { var paystackArgs = { callback: onSuccess ? onSuccess : function () { return null; }, @@ -131,6 +131,8 @@ function usePaystackPayment(hookConfig) { metadata: metadata, split: split, split_code: split_code, + connect_split: connect_split, + connect_account: connect_account, 'data-custom-button': args['data-custom-button'] || '', }; callPaystackPop(paystackArgs); diff --git a/dist/index.es.js.map b/dist/index.es.js.map index f5e531b..6eecbb3 100644 --- a/dist/index.es.js.map +++ b/dist/index.es.js.map @@ -1 +1 @@ -{"version":3,"file":"index.es.js","sources":["../libs/paystack-script.ts","../libs/paystack-actions.ts","../libs/use-paystack.ts","../libs/paystack-button.tsx","../libs/paystack-context.ts","../libs/paystack-provider.tsx","../libs/paystack-consumer.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst cachedScripts: string[] = [];\ninterface IScriptResult {\n loaded: boolean;\n error: boolean;\n}\n\nexport default function usePaystackScript(): boolean[] {\n const src = 'https://js.paystack.co/v1/inline.js';\n\n const [state, setState] = useState({\n loaded: false,\n error: false,\n });\n\n useEffect((): any => {\n if (cachedScripts.includes(src)) {\n setState({\n loaded: true,\n error: false,\n });\n } else {\n cachedScripts.push(src);\n\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n\n const onScriptLoad = (): void => {\n setState({\n loaded: true,\n error: false,\n });\n };\n\n const onScriptError = (): void => {\n const index = cachedScripts.indexOf(src);\n if (index >= 0) cachedScripts.splice(index, 1);\n script.remove();\n\n setState({\n loaded: true,\n error: true,\n });\n };\n\n script.addEventListener('load', onScriptLoad);\n script.addEventListener('complete', onScriptLoad);\n script.addEventListener('error', onScriptError);\n\n document.body.appendChild(script);\n\n return (): void => {\n script.removeEventListener('load', onScriptLoad);\n script.removeEventListener('error', onScriptError);\n };\n }\n }, [src]);\n\n return [state.loaded, state.error];\n}\n","/* eslint-disable */\nexport let callPaystackPop = (paystackArgs: Record): void => {\n // @ts-ignore\n const handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs);\n handler && handler.openIframe();\n};\n","import {useEffect} from 'react';\nimport {HookConfig, InitializePayment} from './types';\nimport usePaystackScript from './paystack-script';\nimport {callPaystackPop} from './paystack-actions';\n\nexport default function usePaystackPayment(hookConfig: HookConfig): InitializePayment {\n const [scriptLoaded, scriptError] = usePaystackScript();\n\n function initializePayment({config, onSuccess, onClose}: Parameters[0]): void {\n if (scriptError) {\n throw new Error('Unable to load paystack inline script');\n }\n\n const args = {...hookConfig, ...config};\n\n const {\n publicKey,\n firstname,\n lastname,\n phone,\n email,\n amount,\n reference,\n metadata = {},\n currency = 'NGN',\n channels,\n label = '',\n plan = '',\n quantity = '',\n subaccount = '',\n transaction_charge = 0,\n bearer = 'account',\n split,\n split_code,\n } = args;\n\n if (scriptLoaded) {\n const paystackArgs: Record = {\n callback: onSuccess ? onSuccess : () => null,\n onClose: onClose ? onClose : () => null,\n key: publicKey,\n ref: reference,\n email,\n firstname,\n lastname,\n phone,\n amount,\n currency,\n plan,\n quantity,\n channels,\n subaccount,\n transaction_charge,\n bearer,\n label,\n metadata,\n split,\n split_code,\n 'data-custom-button': args['data-custom-button'] || '',\n };\n callPaystackPop(paystackArgs);\n }\n }\n\n useEffect(() => {\n if (scriptError) {\n throw new Error('Unable to load paystack inline script');\n }\n }, [scriptError]);\n\n return initializePayment;\n}\n","import React, {ReactNode} from 'react';\nimport usePaystackPayment from './use-paystack';\nimport {callback, PaystackProps} from './types';\n\ninterface PaystackButtonProps extends PaystackProps {\n text?: string;\n className?: string;\n children?: ReactNode;\n onSuccess?: callback;\n onClose?: callback;\n}\n\nconst PaystackButton = ({\n text,\n className,\n children,\n onSuccess,\n onClose,\n ...config\n}: PaystackButtonProps): JSX.Element => {\n const initializePayment = usePaystackPayment(config);\n\n return (\n initializePayment({config, onSuccess, onClose})}\n >\n {text || children}\n \n );\n};\n\nexport default PaystackButton;\n","import {createContext} from 'react';\nimport {InitializePayment, PaystackProps} from './types';\n\ntype IPaystackContext = {\n config: PaystackProps;\n initializePayment: InitializePayment;\n onSuccess: () => void;\n onClose: () => void;\n};\n\nconst PaystackContext = createContext({\n config: {} as PaystackProps,\n initializePayment: () => null,\n onSuccess: () => null,\n onClose: () => null,\n});\n\nexport default PaystackContext;\n","import React from 'react';\nimport PaystackContext from './paystack-context';\nimport usePaystackPayment from './use-paystack';\nimport {callback, PaystackProps} from './types';\n\ninterface PaystackProviderProps extends PaystackProps {\n children: JSX.Element;\n onSuccess: callback;\n onClose: callback;\n}\n\nconst PaystackProvider = ({\n children,\n onSuccess,\n onClose,\n ...config\n}: PaystackProviderProps): JSX.Element => {\n const initializePayment = usePaystackPayment(config);\n\n return (\n \n {children}\n \n );\n};\n\nexport default PaystackProvider;\n","import React, {forwardRef, useContext, FunctionComponentElement} from 'react';\nimport PaystackProvider from './paystack-provider';\nimport {PaystackProps} from './types';\nimport PaystackContext from './paystack-context';\n\ninterface PaystackConsumerProps extends PaystackProps {\n children: (arg: Record) => any;\n onSuccess?: () => void;\n onClose?: () => void;\n}\n\nconst PaystackConsumerChild = ({\n children,\n ref,\n}: {\n children: any;\n ref: any;\n}): FunctionComponentElement => {\n const {config, initializePayment, onSuccess, onClose} = useContext(PaystackContext);\n\n const completeInitializePayment = (): void => initializePayment({config, onSuccess, onClose});\n return children({initializePayment: completeInitializePayment, ref});\n};\n\n// eslint-disable-next-line react/display-name\nconst PaystackConsumer = forwardRef(\n (\n {children, onSuccess: paraSuccess, onClose: paraClose, ...others}: PaystackConsumerProps,\n ref: any,\n ): JSX.Element => {\n const onSuccess = paraSuccess ? paraSuccess : (): any => null;\n const onClose = paraClose ? paraClose : (): any => null;\n return (\n \n {children}\n \n );\n },\n);\n\nexport default PaystackConsumer;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,aAAa,GAAa,EAAE,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AAA,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAA,CAAA;QAClE,KAAC,CAAA,aAAA,CAAA,qBAAqB,EAAC,EAAA,GAAG,EAAE,GAAG,IAAG,QAAQ,CAAyB,CAClD,EACnB;AACJ,CAAC;;;;"} \ No newline at end of file +{"version":3,"file":"index.es.js","sources":["../libs/paystack-script.ts","../libs/paystack-actions.ts","../libs/use-paystack.ts","../libs/paystack-button.tsx","../libs/paystack-context.ts","../libs/paystack-provider.tsx","../libs/paystack-consumer.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst cachedScripts: string[] = [];\ninterface IScriptResult {\n loaded: boolean;\n error: boolean;\n}\n\nexport default function usePaystackScript(): boolean[] {\n const src = 'https://js.paystack.co/v1/inline.js';\n\n const [state, setState] = useState({\n loaded: false,\n error: false,\n });\n\n useEffect((): any => {\n if (cachedScripts.includes(src)) {\n setState({\n loaded: true,\n error: false,\n });\n } else {\n cachedScripts.push(src);\n\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n\n const onScriptLoad = (): void => {\n setState({\n loaded: true,\n error: false,\n });\n };\n\n const onScriptError = (): void => {\n const index = cachedScripts.indexOf(src);\n if (index >= 0) cachedScripts.splice(index, 1);\n script.remove();\n\n setState({\n loaded: true,\n error: true,\n });\n };\n\n script.addEventListener('load', onScriptLoad);\n script.addEventListener('complete', onScriptLoad);\n script.addEventListener('error', onScriptError);\n\n document.body.appendChild(script);\n\n return (): void => {\n script.removeEventListener('load', onScriptLoad);\n script.removeEventListener('error', onScriptError);\n };\n }\n }, [src]);\n\n return [state.loaded, state.error];\n}\n","/* eslint-disable */\nexport let callPaystackPop = (paystackArgs: Record): void => {\n // @ts-ignore\n const handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs);\n handler && handler.openIframe();\n};\n","import {useEffect} from 'react';\nimport {HookConfig, InitializePayment} from './types';\nimport usePaystackScript from './paystack-script';\nimport {callPaystackPop} from './paystack-actions';\n\nexport default function usePaystackPayment(hookConfig: HookConfig): InitializePayment {\n const [scriptLoaded, scriptError] = usePaystackScript();\n\n function initializePayment({config, onSuccess, onClose}: Parameters[0]): void {\n if (scriptError) {\n throw new Error('Unable to load paystack inline script');\n }\n\n const args = {...hookConfig, ...config};\n\n const {\n publicKey,\n firstname,\n lastname,\n phone,\n email,\n amount,\n reference,\n metadata = {},\n currency = 'NGN',\n channels,\n label = '',\n plan = '',\n quantity = '',\n subaccount = '',\n transaction_charge = 0,\n bearer = 'account',\n split,\n split_code,\n connect_account,\n connect_split,\n } = args;\n\n if (scriptLoaded) {\n const paystackArgs: Record = {\n callback: onSuccess ? onSuccess : () => null,\n onClose: onClose ? onClose : () => null,\n key: publicKey,\n ref: reference,\n email,\n firstname,\n lastname,\n phone,\n amount,\n currency,\n plan,\n quantity,\n channels,\n subaccount,\n transaction_charge,\n bearer,\n label,\n metadata,\n split,\n split_code,\n connect_split,\n connect_account,\n 'data-custom-button': args['data-custom-button'] || '',\n };\n callPaystackPop(paystackArgs);\n }\n }\n\n useEffect(() => {\n if (scriptError) {\n throw new Error('Unable to load paystack inline script');\n }\n }, [scriptError]);\n\n return initializePayment;\n}\n","import React, {ReactNode} from 'react';\nimport usePaystackPayment from './use-paystack';\nimport {callback, PaystackProps} from './types';\n\ninterface PaystackButtonProps extends PaystackProps {\n text?: string;\n className?: string;\n children?: ReactNode;\n onSuccess?: callback;\n onClose?: callback;\n}\n\nconst PaystackButton = ({\n text,\n className,\n children,\n onSuccess,\n onClose,\n ...config\n}: PaystackButtonProps): JSX.Element => {\n const initializePayment = usePaystackPayment(config);\n\n return (\n initializePayment({config, onSuccess, onClose})}\n >\n {text || children}\n \n );\n};\n\nexport default PaystackButton;\n","import {createContext} from 'react';\nimport {InitializePayment, PaystackProps} from './types';\n\ntype IPaystackContext = {\n config: PaystackProps;\n initializePayment: InitializePayment;\n onSuccess: () => void;\n onClose: () => void;\n};\n\nconst PaystackContext = createContext({\n config: {} as PaystackProps,\n initializePayment: () => null,\n onSuccess: () => null,\n onClose: () => null,\n});\n\nexport default PaystackContext;\n","import React from 'react';\nimport PaystackContext from './paystack-context';\nimport usePaystackPayment from './use-paystack';\nimport {callback, PaystackProps} from './types';\n\ninterface PaystackProviderProps extends PaystackProps {\n children: JSX.Element;\n onSuccess: callback;\n onClose: callback;\n}\n\nconst PaystackProvider = ({\n children,\n onSuccess,\n onClose,\n ...config\n}: PaystackProviderProps): JSX.Element => {\n const initializePayment = usePaystackPayment(config);\n\n return (\n \n {children}\n \n );\n};\n\nexport default PaystackProvider;\n","import React, {forwardRef, useContext, FunctionComponentElement} from 'react';\nimport PaystackProvider from './paystack-provider';\nimport {PaystackProps} from './types';\nimport PaystackContext from './paystack-context';\n\ninterface PaystackConsumerProps extends PaystackProps {\n children: (arg: Record) => any;\n onSuccess?: () => void;\n onClose?: () => void;\n}\n\nconst PaystackConsumerChild = ({\n children,\n ref,\n}: {\n children: any;\n ref: any;\n}): FunctionComponentElement => {\n const {config, initializePayment, onSuccess, onClose} = useContext(PaystackContext);\n\n const completeInitializePayment = (): void => initializePayment({config, onSuccess, onClose});\n return children({initializePayment: completeInitializePayment, ref});\n};\n\n// eslint-disable-next-line react/display-name\nconst PaystackConsumer = forwardRef(\n (\n {children, onSuccess: paraSuccess, onClose: paraClose, ...others}: PaystackConsumerProps,\n ref: any,\n ): JSX.Element => {\n const onSuccess = paraSuccess ? paraSuccess : (): any => null;\n const onClose = paraClose ? paraClose : (): any => null;\n return (\n \n {children}\n \n );\n },\n);\n\nexport default PaystackConsumer;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,aAAa,GAAa,EAAE,CAAC;AAMrB,SAAU,iBAAiB,GAAA;IACvC,IAAM,GAAG,GAAG,qCAAqC,CAAC;IAE5C,IAAA,EAAA,GAAoB,QAAQ,CAAgB;AAChD,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,KAAK,EAAE,KAAK;AACb,KAAA,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AA,CAAA;QAClE,KAAC,CAAA,aAAA,CAAA,qBAAqB,EAAC,EAAA,GAAG,EAAE,GAAG,IAAG,QAAQ,CAAyB,CAClD,EACnB;AACJ,CAAC;;;;"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index ee51386..1504f0f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -110,7 +110,7 @@ function usePaystackPayment(hookConfig) { throw new Error('Unable to load paystack inline script'); } var args = __assign(__assign({}, hookConfig), config); - var publicKey = args.publicKey, firstname = args.firstname, lastname = args.lastname, phone = args.phone, email = args.email, amount = args.amount, reference = args.reference, _b = args.metadata, metadata = _b === void 0 ? {} : _b, _c = args.currency, currency = _c === void 0 ? 'NGN' : _c, channels = args.channels, _d = args.label, label = _d === void 0 ? '' : _d, _e = args.plan, plan = _e === void 0 ? '' : _e, _f = args.quantity, quantity = _f === void 0 ? '' : _f, _g = args.subaccount, subaccount = _g === void 0 ? '' : _g, _h = args.transaction_charge, transaction_charge = _h === void 0 ? 0 : _h, _j = args.bearer, bearer = _j === void 0 ? 'account' : _j, split = args.split, split_code = args.split_code; + var publicKey = args.publicKey, firstname = args.firstname, lastname = args.lastname, phone = args.phone, email = args.email, amount = args.amount, reference = args.reference, _b = args.metadata, metadata = _b === void 0 ? {} : _b, _c = args.currency, currency = _c === void 0 ? 'NGN' : _c, channels = args.channels, _d = args.label, label = _d === void 0 ? '' : _d, _e = args.plan, plan = _e === void 0 ? '' : _e, _f = args.quantity, quantity = _f === void 0 ? '' : _f, _g = args.subaccount, subaccount = _g === void 0 ? '' : _g, _h = args.transaction_charge, transaction_charge = _h === void 0 ? 0 : _h, _j = args.bearer, bearer = _j === void 0 ? 'account' : _j, split = args.split, split_code = args.split_code, connect_account = args.connect_account, connect_split = args.connect_split; if (scriptLoaded) { var paystackArgs = { callback: onSuccess ? onSuccess : function () { return null; }, @@ -133,6 +133,8 @@ function usePaystackPayment(hookConfig) { metadata: metadata, split: split, split_code: split_code, + connect_split: connect_split, + connect_account: connect_account, 'data-custom-button': args['data-custom-button'] || '', }; callPaystackPop(paystackArgs); diff --git a/dist/index.js.map b/dist/index.js.map index f83250b..b5e2b89 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../libs/paystack-script.ts","../libs/paystack-actions.ts","../libs/use-paystack.ts","../libs/paystack-button.tsx","../libs/paystack-context.ts","../libs/paystack-provider.tsx","../libs/paystack-consumer.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst cachedScripts: string[] = [];\ninterface IScriptResult {\n loaded: boolean;\n error: boolean;\n}\n\nexport default function usePaystackScript(): boolean[] {\n const src = 'https://js.paystack.co/v1/inline.js';\n\n const [state, setState] = useState({\n loaded: false,\n error: false,\n });\n\n useEffect((): any => {\n if (cachedScripts.includes(src)) {\n setState({\n loaded: true,\n error: false,\n });\n } else {\n cachedScripts.push(src);\n\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n\n const onScriptLoad = (): void => {\n setState({\n loaded: true,\n error: false,\n });\n };\n\n const onScriptError = (): void => {\n const index = cachedScripts.indexOf(src);\n if (index >= 0) cachedScripts.splice(index, 1);\n script.remove();\n\n setState({\n loaded: true,\n error: true,\n });\n };\n\n script.addEventListener('load', onScriptLoad);\n script.addEventListener('complete', onScriptLoad);\n script.addEventListener('error', onScriptError);\n\n document.body.appendChild(script);\n\n return (): void => {\n script.removeEventListener('load', onScriptLoad);\n script.removeEventListener('error', onScriptError);\n };\n }\n }, [src]);\n\n return [state.loaded, state.error];\n}\n","/* eslint-disable */\nexport let callPaystackPop = (paystackArgs: Record): void => {\n // @ts-ignore\n const handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs);\n handler && handler.openIframe();\n};\n","import {useEffect} from 'react';\nimport {HookConfig, InitializePayment} from './types';\nimport usePaystackScript from './paystack-script';\nimport {callPaystackPop} from './paystack-actions';\n\nexport default function usePaystackPayment(hookConfig: HookConfig): InitializePayment {\n const [scriptLoaded, scriptError] = usePaystackScript();\n\n function initializePayment({config, onSuccess, onClose}: Parameters[0]): void {\n if (scriptError) {\n throw new Error('Unable to load paystack inline script');\n }\n\n const args = {...hookConfig, ...config};\n\n const {\n publicKey,\n firstname,\n lastname,\n phone,\n email,\n amount,\n reference,\n metadata = {},\n currency = 'NGN',\n channels,\n label = '',\n plan = '',\n quantity = '',\n subaccount = '',\n transaction_charge = 0,\n bearer = 'account',\n split,\n split_code,\n } = args;\n\n if (scriptLoaded) {\n const paystackArgs: Record = {\n callback: onSuccess ? onSuccess : () => null,\n onClose: onClose ? onClose : () => null,\n key: publicKey,\n ref: reference,\n email,\n firstname,\n lastname,\n phone,\n amount,\n currency,\n plan,\n quantity,\n channels,\n subaccount,\n transaction_charge,\n bearer,\n label,\n metadata,\n split,\n split_code,\n 'data-custom-button': args['data-custom-button'] || '',\n };\n callPaystackPop(paystackArgs);\n }\n }\n\n useEffect(() => {\n if (scriptError) {\n throw new Error('Unable to load paystack inline script');\n }\n }, [scriptError]);\n\n return initializePayment;\n}\n","import React, {ReactNode} from 'react';\nimport usePaystackPayment from './use-paystack';\nimport {callback, PaystackProps} from './types';\n\ninterface PaystackButtonProps extends PaystackProps {\n text?: string;\n className?: string;\n children?: ReactNode;\n onSuccess?: callback;\n onClose?: callback;\n}\n\nconst PaystackButton = ({\n text,\n className,\n children,\n onSuccess,\n onClose,\n ...config\n}: PaystackButtonProps): JSX.Element => {\n const initializePayment = usePaystackPayment(config);\n\n return (\n initializePayment({config, onSuccess, onClose})}\n >\n {text || children}\n \n );\n};\n\nexport default PaystackButton;\n","import {createContext} from 'react';\nimport {InitializePayment, PaystackProps} from './types';\n\ntype IPaystackContext = {\n config: PaystackProps;\n initializePayment: InitializePayment;\n onSuccess: () => void;\n onClose: () => void;\n};\n\nconst PaystackContext = createContext({\n config: {} as PaystackProps,\n initializePayment: () => null,\n onSuccess: () => null,\n onClose: () => null,\n});\n\nexport default PaystackContext;\n","import React from 'react';\nimport PaystackContext from './paystack-context';\nimport usePaystackPayment from './use-paystack';\nimport {callback, PaystackProps} from './types';\n\ninterface PaystackProviderProps extends PaystackProps {\n children: JSX.Element;\n onSuccess: callback;\n onClose: callback;\n}\n\nconst PaystackProvider = ({\n children,\n onSuccess,\n onClose,\n ...config\n}: PaystackProviderProps): JSX.Element => {\n const initializePayment = usePaystackPayment(config);\n\n return (\n \n {children}\n \n );\n};\n\nexport default PaystackProvider;\n","import React, {forwardRef, useContext, FunctionComponentElement} from 'react';\nimport PaystackProvider from './paystack-provider';\nimport {PaystackProps} from './types';\nimport PaystackContext from './paystack-context';\n\ninterface PaystackConsumerProps extends PaystackProps {\n children: (arg: Record) => any;\n onSuccess?: () => void;\n onClose?: () => void;\n}\n\nconst PaystackConsumerChild = ({\n children,\n ref,\n}: {\n children: any;\n ref: any;\n}): FunctionComponentElement => {\n const {config, initializePayment, onSuccess, onClose} = useContext(PaystackContext);\n\n const completeInitializePayment = (): void => initializePayment({config, onSuccess, onClose});\n return children({initializePayment: completeInitializePayment, ref});\n};\n\n// eslint-disable-next-line react/display-name\nconst PaystackConsumer = forwardRef(\n (\n {children, onSuccess: paraSuccess, onClose: paraClose, ...others}: PaystackConsumerProps,\n ref: any,\n ): JSX.Element => {\n const onSuccess = paraSuccess ? paraSuccess : (): any => null;\n const onClose = paraClose ? paraClose : (): any => null;\n return (\n \n {children}\n \n );\n },\n);\n\nexport default PaystackConsumer;\n"],"names":["useState","useEffect","createContext","useContext","forwardRef"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,aAAa,GAAa,EAAE,CAAC;AAMrB,SAAU,iBAAiB,GAAA;IACvC,IAAM,GAAG,GAAG,qCAAqC,CAAC;IAE5C,IAAA,EAAA,GAAoBA,cAAQ,CAAgB;AAChD,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,KAAK,EAAE,KAAK;AACb,KAAA,CAAC,EAHK,KAAK,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,QAA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.ts","../libs/paystack-actions.ts","../libs/use-paystack.ts","../libs/paystack-button.tsx","../libs/paystack-context.ts","../libs/paystack-provider.tsx","../libs/paystack-consumer.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst cachedScripts: string[] = [];\ninterface IScriptResult {\n loaded: boolean;\n error: boolean;\n}\n\nexport default function usePaystackScript(): boolean[] {\n const src = 'https://js.paystack.co/v1/inline.js';\n\n const [state, setState] = useState({\n loaded: false,\n error: false,\n });\n\n useEffect((): any => {\n if (cachedScripts.includes(src)) {\n setState({\n loaded: true,\n error: false,\n });\n } else {\n cachedScripts.push(src);\n\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n\n const onScriptLoad = (): void => {\n setState({\n loaded: true,\n error: false,\n });\n };\n\n const onScriptError = (): void => {\n const index = cachedScripts.indexOf(src);\n if (index >= 0) cachedScripts.splice(index, 1);\n script.remove();\n\n setState({\n loaded: true,\n error: true,\n });\n };\n\n script.addEventListener('load', onScriptLoad);\n script.addEventListener('complete', onScriptLoad);\n script.addEventListener('error', onScriptError);\n\n document.body.appendChild(script);\n\n return (): void => {\n script.removeEventListener('load', onScriptLoad);\n script.removeEventListener('error', onScriptError);\n };\n }\n }, [src]);\n\n return [state.loaded, state.error];\n}\n","/* eslint-disable */\nexport let callPaystackPop = (paystackArgs: Record): void => {\n // @ts-ignore\n const handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs);\n handler && handler.openIframe();\n};\n","import {useEffect} from 'react';\nimport {HookConfig, InitializePayment} from './types';\nimport usePaystackScript from './paystack-script';\nimport {callPaystackPop} from './paystack-actions';\n\nexport default function usePaystackPayment(hookConfig: HookConfig): InitializePayment {\n const [scriptLoaded, scriptError] = usePaystackScript();\n\n function initializePayment({config, onSuccess, onClose}: Parameters[0]): void {\n if (scriptError) {\n throw new Error('Unable to load paystack inline script');\n }\n\n const args = {...hookConfig, ...config};\n\n const {\n publicKey,\n firstname,\n lastname,\n phone,\n email,\n amount,\n reference,\n metadata = {},\n currency = 'NGN',\n channels,\n label = '',\n plan = '',\n quantity = '',\n subaccount = '',\n transaction_charge = 0,\n bearer = 'account',\n split,\n split_code,\n connect_account,\n connect_split,\n } = args;\n\n if (scriptLoaded) {\n const paystackArgs: Record = {\n callback: onSuccess ? onSuccess : () => null,\n onClose: onClose ? onClose : () => null,\n key: publicKey,\n ref: reference,\n email,\n firstname,\n lastname,\n phone,\n amount,\n currency,\n plan,\n quantity,\n channels,\n subaccount,\n transaction_charge,\n bearer,\n label,\n metadata,\n split,\n split_code,\n connect_split,\n connect_account,\n 'data-custom-button': args['data-custom-button'] || '',\n };\n callPaystackPop(paystackArgs);\n }\n }\n\n useEffect(() => {\n if (scriptError) {\n throw new Error('Unable to load paystack inline script');\n }\n }, [scriptError]);\n\n return initializePayment;\n}\n","import React, {ReactNode} from 'react';\nimport usePaystackPayment from './use-paystack';\nimport {callback, PaystackProps} from './types';\n\ninterface PaystackButtonProps extends PaystackProps {\n text?: string;\n className?: string;\n children?: ReactNode;\n onSuccess?: callback;\n onClose?: callback;\n}\n\nconst PaystackButton = ({\n text,\n className,\n children,\n onSuccess,\n onClose,\n ...config\n}: PaystackButtonProps): JSX.Element => {\n const initializePayment = usePaystackPayment(config);\n\n return (\n initializePayment({config, onSuccess, onClose})}\n >\n {text || children}\n \n );\n};\n\nexport default PaystackButton;\n","import {createContext} from 'react';\nimport {InitializePayment, PaystackProps} from './types';\n\ntype IPaystackContext = {\n config: PaystackProps;\n initializePayment: InitializePayment;\n onSuccess: () => void;\n onClose: () => void;\n};\n\nconst PaystackContext = createContext({\n config: {} as PaystackProps,\n initializePayment: () => null,\n onSuccess: () => null,\n onClose: () => null,\n});\n\nexport default PaystackContext;\n","import React from 'react';\nimport PaystackContext from './paystack-context';\nimport usePaystackPayment from './use-paystack';\nimport {callback, PaystackProps} from './types';\n\ninterface PaystackProviderProps extends PaystackProps {\n children: JSX.Element;\n onSuccess: callback;\n onClose: callback;\n}\n\nconst PaystackProvider = ({\n children,\n onSuccess,\n onClose,\n ...config\n}: PaystackProviderProps): JSX.Element => {\n const initializePayment = usePaystackPayment(config);\n\n return (\n \n {children}\n \n );\n};\n\nexport default PaystackProvider;\n","import React, {forwardRef, useContext, FunctionComponentElement} from 'react';\nimport PaystackProvider from './paystack-provider';\nimport {PaystackProps} from './types';\nimport PaystackContext from './paystack-context';\n\ninterface PaystackConsumerProps extends PaystackProps {\n children: (arg: Record) => any;\n onSuccess?: () => void;\n onClose?: () => void;\n}\n\nconst PaystackConsumerChild = ({\n children,\n ref,\n}: {\n children: any;\n ref: any;\n}): FunctionComponentElement => {\n const {config, initializePayment, onSuccess, onClose} = useContext(PaystackContext);\n\n const completeInitializePayment = (): void => initializePayment({config, onSuccess, onClose});\n return children({initializePayment: completeInitializePayment, ref});\n};\n\n// eslint-disable-next-line react/display-name\nconst PaystackConsumer = forwardRef(\n (\n {children, onSuccess: paraSuccess, onClose: paraClose, ...others}: PaystackConsumerProps,\n ref: any,\n ): JSX.Element => {\n const onSuccess = paraSuccess ? paraSuccess : (): any => null;\n const onClose = paraClose ? paraClose : (): any => null;\n return (\n \n {children}\n \n );\n },\n);\n\nexport default PaystackConsumer;\n"],"names":["useState","useEffect","createContext","useContext","forwardRef"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,aAAa,GAAa,EAAE,CAAC;AAMrB,SAAU,iBAAiB,GAAA;IACvC,IAAM,GAAG,GAAG,qCAAqC,CAAC;IAE5C,IAAA,EAAA,GAAoBA,cAAQ,CAAgB;AAChD,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,KAAK,EAAE,KAAK;AACb,KAAA,CAAC,EAHK,KAAK,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,QAAQ,QAGpB,CAAC;AAEH,IAAAC,eAAS,CAAC,YAAA;AACR,QAAA,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC/B,YAAA,QAAQ,CAAC;AACP,gBA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 --- a/dist/types.d.ts +++ b/dist/types.d.ts @@ -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; @@ -34,6 +38,8 @@ export interface PaystackProps { 'data-custom-button'?: string; split_code?: string; split?: Record; + connect_split?: PaystackConnectSplit[]; + connect_account?: string; } export type InitializePayment = (options: { onSuccess?: callback; diff --git a/example/src/App.js b/example/src/App.js index 36a2854..1ab7a7f 100644 --- a/example/src/App.js +++ b/example/src/App.js @@ -52,18 +52,18 @@ const PaystackHookExample = () => { }; const PaystackHookSplitParameterExample = () => { - const initializePayment = usePaystackPayment(config); - return ( -
- -
- ); + const initializePayment = usePaystackPayment(config); + return ( +
+ +
+ ); }; function App() { diff --git a/example/src/dist/index.es.js b/example/src/dist/index.es.js index b4441a4..82817ea 100644 --- a/example/src/dist/index.es.js +++ b/example/src/dist/index.es.js @@ -1,182 +1,282 @@ -import React, { useState, useEffect, createContext, forwardRef, useContext } from 'react'; +import React, {useState, useEffect, createContext, forwardRef, useContext} from 'react'; -/****************************************************************************** -Copyright (c) Microsoft Corporation. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */ -/* global Reflect, Promise, SuppressedError, Symbol */ - - -var __assign = function() { - __assign = Object.assign || function __assign(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; - -function __rest(s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -} - -typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { - var e = new Error(message); - return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; +/****************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ +/* global Reflect, Promise, SuppressedError, Symbol */ + +var __assign = function () { + __assign = + Object.assign || + function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); }; +function __rest(s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === 'function') + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +} + +typeof SuppressedError === 'function' + ? SuppressedError + : function (error, suppressed, message) { + var e = new Error(message); + return (e.name = 'SuppressedError'), (e.error = error), (e.suppressed = suppressed), e; + }; + var cachedScripts = []; function usePaystackScript() { - var src = 'https://js.paystack.co/v1/inline.js'; - var _a = useState({ - loaded: false, - error: false, - }), state = _a[0], setState = _a[1]; - useEffect(function () { - if (cachedScripts.includes(src)) { - setState({ - loaded: true, - error: false, - }); - } - else { - cachedScripts.push(src); - var script_1 = document.createElement('script'); - script_1.src = src; - script_1.async = true; - var onScriptLoad_1 = function () { - setState({ - loaded: true, - error: false, - }); - }; - var onScriptError_1 = function () { - var index = cachedScripts.indexOf(src); - if (index >= 0) - cachedScripts.splice(index, 1); - script_1.remove(); - setState({ - loaded: true, - error: true, - }); - }; - script_1.addEventListener('load', onScriptLoad_1); - script_1.addEventListener('complete', onScriptLoad_1); - script_1.addEventListener('error', onScriptError_1); - document.body.appendChild(script_1); - return function () { - script_1.removeEventListener('load', onScriptLoad_1); - script_1.removeEventListener('error', onScriptError_1); - }; - } - }, [src]); - return [state.loaded, state.error]; + var src = 'https://js.paystack.co/v1/inline.js'; + var _a = useState({ + loaded: false, + error: false, + }), + state = _a[0], + setState = _a[1]; + useEffect( + function () { + if (cachedScripts.includes(src)) { + setState({ + loaded: true, + error: false, + }); + } else { + cachedScripts.push(src); + var script_1 = document.createElement('script'); + script_1.src = src; + script_1.async = true; + var onScriptLoad_1 = function () { + setState({ + loaded: true, + error: false, + }); + }; + var onScriptError_1 = function () { + var index = cachedScripts.indexOf(src); + if (index >= 0) cachedScripts.splice(index, 1); + script_1.remove(); + setState({ + loaded: true, + error: true, + }); + }; + script_1.addEventListener('load', onScriptLoad_1); + script_1.addEventListener('complete', onScriptLoad_1); + script_1.addEventListener('error', onScriptError_1); + document.body.appendChild(script_1); + return function () { + script_1.removeEventListener('load', onScriptLoad_1); + script_1.removeEventListener('error', onScriptError_1); + }; + } + }, + [src], + ); + return [state.loaded, state.error]; } /* eslint-disable */ var callPaystackPop = function (paystackArgs) { - // @ts-ignore - var handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs); - handler && handler.openIframe(); + // @ts-ignore + var handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs); + handler && handler.openIframe(); }; function usePaystackPayment(hookConfig) { - var _a = usePaystackScript(), scriptLoaded = _a[0], scriptError = _a[1]; - function initializePayment(_a) { - var config = _a.config, onSuccess = _a.onSuccess, onClose = _a.onClose; - if (scriptError) { - throw new Error('Unable to load paystack inline script'); - } - var args = __assign(__assign({}, hookConfig), config); - var publicKey = args.publicKey, firstname = args.firstname, lastname = args.lastname, phone = args.phone, email = args.email, amount = args.amount, reference = args.reference, _b = args.metadata, metadata = _b === void 0 ? {} : _b, _c = args.currency, currency = _c === void 0 ? 'NGN' : _c, channels = args.channels, _d = args.label, label = _d === void 0 ? '' : _d, _e = args.plan, plan = _e === void 0 ? '' : _e, _f = args.quantity, quantity = _f === void 0 ? '' : _f, _g = args.subaccount, subaccount = _g === void 0 ? '' : _g, _h = args.transaction_charge, transaction_charge = _h === void 0 ? 0 : _h, _j = args.bearer, bearer = _j === void 0 ? 'account' : _j, split = args.split, split_code = args.split_code; - if (scriptLoaded) { - var paystackArgs = { - callback: onSuccess ? onSuccess : function () { return null; }, - onClose: onClose ? onClose : function () { return null; }, - key: publicKey, - ref: reference, - email: email, - firstname: firstname, - lastname: lastname, - phone: phone, - amount: amount, - currency: currency, - plan: plan, - quantity: quantity, - channels: channels, - subaccount: subaccount, - transaction_charge: transaction_charge, - bearer: bearer, - label: label, - metadata: metadata, - split: split, - split_code: split_code, - 'data-custom-button': args['data-custom-button'] || '', - }; - callPaystackPop(paystackArgs); - } + var _a = usePaystackScript(), + scriptLoaded = _a[0], + scriptError = _a[1]; + function initializePayment(_a) { + var config = _a.config, + onSuccess = _a.onSuccess, + onClose = _a.onClose; + if (scriptError) { + throw new Error('Unable to load paystack inline script'); + } + var args = __assign(__assign({}, hookConfig), config); + var publicKey = args.publicKey, + firstname = args.firstname, + lastname = args.lastname, + phone = args.phone, + email = args.email, + amount = args.amount, + reference = args.reference, + _b = args.metadata, + metadata = _b === void 0 ? {} : _b, + _c = args.currency, + currency = _c === void 0 ? 'NGN' : _c, + channels = args.channels, + _d = args.label, + label = _d === void 0 ? '' : _d, + _e = args.plan, + plan = _e === void 0 ? '' : _e, + _f = args.quantity, + quantity = _f === void 0 ? '' : _f, + _g = args.subaccount, + subaccount = _g === void 0 ? '' : _g, + _h = args.transaction_charge, + transaction_charge = _h === void 0 ? 0 : _h, + _j = args.bearer, + bearer = _j === void 0 ? 'account' : _j, + split = args.split, + split_code = args.split_code; + if (scriptLoaded) { + var paystackArgs = { + callback: onSuccess + ? onSuccess + : function () { + return null; + }, + onClose: onClose + ? onClose + : function () { + return null; + }, + key: publicKey, + ref: reference, + email: email, + firstname: firstname, + lastname: lastname, + phone: phone, + amount: amount, + currency: currency, + plan: plan, + quantity: quantity, + channels: channels, + subaccount: subaccount, + transaction_charge: transaction_charge, + bearer: bearer, + label: label, + metadata: metadata, + split: split, + split_code: split_code, + 'data-custom-button': args['data-custom-button'] || '', + }; + callPaystackPop(paystackArgs); } - useEffect(function () { - if (scriptError) { - throw new Error('Unable to load paystack inline script'); - } - }, [scriptError]); - return initializePayment; + } + useEffect( + function () { + if (scriptError) { + throw new Error('Unable to load paystack inline script'); + } + }, + [scriptError], + ); + return initializePayment; } var PaystackButton = function (_a) { - var text = _a.text, className = _a.className, children = _a.children, onSuccess = _a.onSuccess, onClose = _a.onClose, config = __rest(_a, ["text", "className", "children", "onSuccess", "onClose"]); - var initializePayment = usePaystackPayment(config); - return (React.createElement("button", { className: className, onClick: function () { return initializePayment({ config: config, onSuccess: onSuccess, onClose: onClose }); } }, text || children)); + var text = _a.text, + className = _a.className, + children = _a.children, + onSuccess = _a.onSuccess, + onClose = _a.onClose, + config = __rest(_a, ['text', 'className', 'children', 'onSuccess', 'onClose']); + var initializePayment = usePaystackPayment(config); + return React.createElement( + 'button', + { + className: className, + onClick: function () { + return initializePayment({config: config, onSuccess: onSuccess, onClose: onClose}); + }, + }, + text || children, + ); }; var PaystackContext = createContext({ - config: {}, - initializePayment: function () { return null; }, - onSuccess: function () { return null; }, - onClose: function () { return null; }, + config: {}, + initializePayment: function () { + return null; + }, + onSuccess: function () { + return null; + }, + onClose: function () { + return null; + }, }); var PaystackProvider = function (_a) { - var children = _a.children, onSuccess = _a.onSuccess, onClose = _a.onClose, config = __rest(_a, ["children", "onSuccess", "onClose"]); - var initializePayment = usePaystackPayment(config); - return (React.createElement(PaystackContext.Provider, { value: { config: config, initializePayment: initializePayment, onSuccess: onSuccess, onClose: onClose } }, children)); + var children = _a.children, + onSuccess = _a.onSuccess, + onClose = _a.onClose, + config = __rest(_a, ['children', 'onSuccess', 'onClose']); + var initializePayment = usePaystackPayment(config); + return React.createElement( + PaystackContext.Provider, + { + value: { + config: config, + initializePayment: initializePayment, + onSuccess: onSuccess, + onClose: onClose, + }, + }, + children, + ); }; var PaystackConsumerChild = function (_a) { - var children = _a.children, ref = _a.ref; - var _b = useContext(PaystackContext), config = _b.config, initializePayment = _b.initializePayment, onSuccess = _b.onSuccess, onClose = _b.onClose; - var completeInitializePayment = function () { return initializePayment({ config: config, onSuccess: onSuccess, onClose: onClose }); }; - return children({ initializePayment: completeInitializePayment, ref: ref }); + var children = _a.children, + ref = _a.ref; + var _b = useContext(PaystackContext), + config = _b.config, + initializePayment = _b.initializePayment, + onSuccess = _b.onSuccess, + onClose = _b.onClose; + var completeInitializePayment = function () { + return initializePayment({config: config, onSuccess: onSuccess, onClose: onClose}); + }; + return children({initializePayment: completeInitializePayment, ref: ref}); }; // eslint-disable-next-line react/display-name var PaystackConsumer = forwardRef(function (_a, ref) { - var children = _a.children, paraSuccess = _a.onSuccess, paraClose = _a.onClose, others = __rest(_a, ["children", "onSuccess", "onClose"]); - var onSuccess = paraSuccess ? paraSuccess : function () { return null; }; - var onClose = paraClose ? paraClose : function () { return null; }; - return (React.createElement(PaystackProvider, __assign({}, others, { onSuccess: onSuccess, onClose: onClose }), - React.createElement(PaystackConsumerChild, { ref: ref }, children))); + var children = _a.children, + paraSuccess = _a.onSuccess, + paraClose = _a.onClose, + others = __rest(_a, ['children', 'onSuccess', 'onClose']); + var onSuccess = paraSuccess + ? paraSuccess + : function () { + return null; + }; + var onClose = paraClose + ? paraClose + : function () { + return null; + }; + return React.createElement( + PaystackProvider, + __assign({}, others, {onSuccess: onSuccess, onClose: onClose}), + React.createElement(PaystackConsumerChild, {ref: ref}, children), + ); }); -export { PaystackButton, PaystackConsumer, usePaystackPayment }; +export {PaystackButton, PaystackConsumer, usePaystackPayment}; //# sourceMappingURL=index.es.js.map diff --git a/example/src/dist/index.js b/example/src/dist/index.js index ee51386..3a47f46 100644 --- a/example/src/dist/index.js +++ b/example/src/dist/index.js @@ -2,182 +2,282 @@ var React = require('react'); -/****************************************************************************** -Copyright (c) Microsoft Corporation. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */ -/* global Reflect, Promise, SuppressedError, Symbol */ - - -var __assign = function() { - __assign = Object.assign || function __assign(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; - -function __rest(s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -} - -typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { - var e = new Error(message); - return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; +/****************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ +/* global Reflect, Promise, SuppressedError, Symbol */ + +var __assign = function () { + __assign = + Object.assign || + function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); }; +function __rest(s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === 'function') + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +} + +typeof SuppressedError === 'function' + ? SuppressedError + : function (error, suppressed, message) { + var e = new Error(message); + return (e.name = 'SuppressedError'), (e.error = error), (e.suppressed = suppressed), e; + }; + var cachedScripts = []; function usePaystackScript() { - var src = 'https://js.paystack.co/v1/inline.js'; - var _a = React.useState({ - loaded: false, - error: false, - }), state = _a[0], setState = _a[1]; - React.useEffect(function () { - if (cachedScripts.includes(src)) { - setState({ - loaded: true, - error: false, - }); - } - else { - cachedScripts.push(src); - var script_1 = document.createElement('script'); - script_1.src = src; - script_1.async = true; - var onScriptLoad_1 = function () { - setState({ - loaded: true, - error: false, - }); - }; - var onScriptError_1 = function () { - var index = cachedScripts.indexOf(src); - if (index >= 0) - cachedScripts.splice(index, 1); - script_1.remove(); - setState({ - loaded: true, - error: true, - }); - }; - script_1.addEventListener('load', onScriptLoad_1); - script_1.addEventListener('complete', onScriptLoad_1); - script_1.addEventListener('error', onScriptError_1); - document.body.appendChild(script_1); - return function () { - script_1.removeEventListener('load', onScriptLoad_1); - script_1.removeEventListener('error', onScriptError_1); - }; - } - }, [src]); - return [state.loaded, state.error]; + var src = 'https://js.paystack.co/v1/inline.js'; + var _a = React.useState({ + loaded: false, + error: false, + }), + state = _a[0], + setState = _a[1]; + React.useEffect( + function () { + if (cachedScripts.includes(src)) { + setState({ + loaded: true, + error: false, + }); + } else { + cachedScripts.push(src); + var script_1 = document.createElement('script'); + script_1.src = src; + script_1.async = true; + var onScriptLoad_1 = function () { + setState({ + loaded: true, + error: false, + }); + }; + var onScriptError_1 = function () { + var index = cachedScripts.indexOf(src); + if (index >= 0) cachedScripts.splice(index, 1); + script_1.remove(); + setState({ + loaded: true, + error: true, + }); + }; + script_1.addEventListener('load', onScriptLoad_1); + script_1.addEventListener('complete', onScriptLoad_1); + script_1.addEventListener('error', onScriptError_1); + document.body.appendChild(script_1); + return function () { + script_1.removeEventListener('load', onScriptLoad_1); + script_1.removeEventListener('error', onScriptError_1); + }; + } + }, + [src], + ); + return [state.loaded, state.error]; } /* eslint-disable */ var callPaystackPop = function (paystackArgs) { - // @ts-ignore - var handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs); - handler && handler.openIframe(); + // @ts-ignore + var handler = window.PaystackPop && window.PaystackPop.setup(paystackArgs); + handler && handler.openIframe(); }; function usePaystackPayment(hookConfig) { - var _a = usePaystackScript(), scriptLoaded = _a[0], scriptError = _a[1]; - function initializePayment(_a) { - var config = _a.config, onSuccess = _a.onSuccess, onClose = _a.onClose; - if (scriptError) { - throw new Error('Unable to load paystack inline script'); - } - var args = __assign(__assign({}, hookConfig), config); - var publicKey = args.publicKey, firstname = args.firstname, lastname = args.lastname, phone = args.phone, email = args.email, amount = args.amount, reference = args.reference, _b = args.metadata, metadata = _b === void 0 ? {} : _b, _c = args.currency, currency = _c === void 0 ? 'NGN' : _c, channels = args.channels, _d = args.label, label = _d === void 0 ? '' : _d, _e = args.plan, plan = _e === void 0 ? '' : _e, _f = args.quantity, quantity = _f === void 0 ? '' : _f, _g = args.subaccount, subaccount = _g === void 0 ? '' : _g, _h = args.transaction_charge, transaction_charge = _h === void 0 ? 0 : _h, _j = args.bearer, bearer = _j === void 0 ? 'account' : _j, split = args.split, split_code = args.split_code; - if (scriptLoaded) { - var paystackArgs = { - callback: onSuccess ? onSuccess : function () { return null; }, - onClose: onClose ? onClose : function () { return null; }, - key: publicKey, - ref: reference, - email: email, - firstname: firstname, - lastname: lastname, - phone: phone, - amount: amount, - currency: currency, - plan: plan, - quantity: quantity, - channels: channels, - subaccount: subaccount, - transaction_charge: transaction_charge, - bearer: bearer, - label: label, - metadata: metadata, - split: split, - split_code: split_code, - 'data-custom-button': args['data-custom-button'] || '', - }; - callPaystackPop(paystackArgs); - } + var _a = usePaystackScript(), + scriptLoaded = _a[0], + scriptError = _a[1]; + function initializePayment(_a) { + var config = _a.config, + onSuccess = _a.onSuccess, + onClose = _a.onClose; + if (scriptError) { + throw new Error('Unable to load paystack inline script'); + } + var args = __assign(__assign({}, hookConfig), config); + var publicKey = args.publicKey, + firstname = args.firstname, + lastname = args.lastname, + phone = args.phone, + email = args.email, + amount = args.amount, + reference = args.reference, + _b = args.metadata, + metadata = _b === void 0 ? {} : _b, + _c = args.currency, + currency = _c === void 0 ? 'NGN' : _c, + channels = args.channels, + _d = args.label, + label = _d === void 0 ? '' : _d, + _e = args.plan, + plan = _e === void 0 ? '' : _e, + _f = args.quantity, + quantity = _f === void 0 ? '' : _f, + _g = args.subaccount, + subaccount = _g === void 0 ? '' : _g, + _h = args.transaction_charge, + transaction_charge = _h === void 0 ? 0 : _h, + _j = args.bearer, + bearer = _j === void 0 ? 'account' : _j, + split = args.split, + split_code = args.split_code; + if (scriptLoaded) { + var paystackArgs = { + callback: onSuccess + ? onSuccess + : function () { + return null; + }, + onClose: onClose + ? onClose + : function () { + return null; + }, + key: publicKey, + ref: reference, + email: email, + firstname: firstname, + lastname: lastname, + phone: phone, + amount: amount, + currency: currency, + plan: plan, + quantity: quantity, + channels: channels, + subaccount: subaccount, + transaction_charge: transaction_charge, + bearer: bearer, + label: label, + metadata: metadata, + split: split, + split_code: split_code, + 'data-custom-button': args['data-custom-button'] || '', + }; + callPaystackPop(paystackArgs); } - React.useEffect(function () { - if (scriptError) { - throw new Error('Unable to load paystack inline script'); - } - }, [scriptError]); - return initializePayment; + } + React.useEffect( + function () { + if (scriptError) { + throw new Error('Unable to load paystack inline script'); + } + }, + [scriptError], + ); + return initializePayment; } var PaystackButton = function (_a) { - var text = _a.text, className = _a.className, children = _a.children, onSuccess = _a.onSuccess, onClose = _a.onClose, config = __rest(_a, ["text", "className", "children", "onSuccess", "onClose"]); - var initializePayment = usePaystackPayment(config); - return (React.createElement("button", { className: className, onClick: function () { return initializePayment({ config: config, onSuccess: onSuccess, onClose: onClose }); } }, text || children)); + var text = _a.text, + className = _a.className, + children = _a.children, + onSuccess = _a.onSuccess, + onClose = _a.onClose, + config = __rest(_a, ['text', 'className', 'children', 'onSuccess', 'onClose']); + var initializePayment = usePaystackPayment(config); + return React.createElement( + 'button', + { + className: className, + onClick: function () { + return initializePayment({config: config, onSuccess: onSuccess, onClose: onClose}); + }, + }, + text || children, + ); }; var PaystackContext = React.createContext({ - config: {}, - initializePayment: function () { return null; }, - onSuccess: function () { return null; }, - onClose: function () { return null; }, + config: {}, + initializePayment: function () { + return null; + }, + onSuccess: function () { + return null; + }, + onClose: function () { + return null; + }, }); var PaystackProvider = function (_a) { - var children = _a.children, onSuccess = _a.onSuccess, onClose = _a.onClose, config = __rest(_a, ["children", "onSuccess", "onClose"]); - var initializePayment = usePaystackPayment(config); - return (React.createElement(PaystackContext.Provider, { value: { config: config, initializePayment: initializePayment, onSuccess: onSuccess, onClose: onClose } }, children)); + var children = _a.children, + onSuccess = _a.onSuccess, + onClose = _a.onClose, + config = __rest(_a, ['children', 'onSuccess', 'onClose']); + var initializePayment = usePaystackPayment(config); + return React.createElement( + PaystackContext.Provider, + { + value: { + config: config, + initializePayment: initializePayment, + onSuccess: onSuccess, + onClose: onClose, + }, + }, + children, + ); }; var PaystackConsumerChild = function (_a) { - var children = _a.children, ref = _a.ref; - var _b = React.useContext(PaystackContext), config = _b.config, initializePayment = _b.initializePayment, onSuccess = _b.onSuccess, onClose = _b.onClose; - var completeInitializePayment = function () { return initializePayment({ config: config, onSuccess: onSuccess, onClose: onClose }); }; - return children({ initializePayment: completeInitializePayment, ref: ref }); + var children = _a.children, + ref = _a.ref; + var _b = React.useContext(PaystackContext), + config = _b.config, + initializePayment = _b.initializePayment, + onSuccess = _b.onSuccess, + onClose = _b.onClose; + var completeInitializePayment = function () { + return initializePayment({config: config, onSuccess: onSuccess, onClose: onClose}); + }; + return children({initializePayment: completeInitializePayment, ref: ref}); }; // eslint-disable-next-line react/display-name var PaystackConsumer = React.forwardRef(function (_a, ref) { - var children = _a.children, paraSuccess = _a.onSuccess, paraClose = _a.onClose, others = __rest(_a, ["children", "onSuccess", "onClose"]); - var onSuccess = paraSuccess ? paraSuccess : function () { return null; }; - var onClose = paraClose ? paraClose : function () { return null; }; - return (React.createElement(PaystackProvider, __assign({}, others, { onSuccess: onSuccess, onClose: onClose }), - React.createElement(PaystackConsumerChild, { ref: ref }, children))); + var children = _a.children, + paraSuccess = _a.onSuccess, + paraClose = _a.onClose, + others = __rest(_a, ['children', 'onSuccess', 'onClose']); + var onSuccess = paraSuccess + ? paraSuccess + : function () { + return null; + }; + var onClose = paraClose + ? paraClose + : function () { + return null; + }; + return React.createElement( + PaystackProvider, + __assign({}, others, {onSuccess: onSuccess, onClose: onClose}), + React.createElement(PaystackConsumerChild, {ref: ref}, children), + ); }); exports.PaystackButton = PaystackButton; diff --git a/libs/test/use-paystack.test.tsx b/libs/test/use-paystack.test.tsx index 506c271..72fd733 100644 --- a/libs/test/use-paystack.test.tsx +++ b/libs/test/use-paystack.test.tsx @@ -86,6 +86,17 @@ describe('usePaystackPayment()', () => { }, ], }, + connect_account: 'C_ACT_911WDFTY6GW', + connect_split: [ + { + account_id: 'C_ACT_911WDFTY6GW', + share: 70, + }, + { + account_id: 'C_ACT_DHRI3498VB', + share: 8, + }, + ], }), ); rerender(); @@ -96,7 +107,7 @@ describe('usePaystackPayment()', () => { expect(callPaystackPop).toHaveBeenCalledTimes(1); }); - it('should usePaystackPayment accept parameter parameters', () => { + it('should usePaystackPayment accept parameters', () => { const currency: Currency = 'GHS'; const channels: PaymentChannels[] = ['mobile_money', 'ussd']; const moreConfig = { @@ -136,6 +147,17 @@ describe('usePaystackPayment()', () => { }, ], }, + connect_account: 'C_ACT_911WDFTY6GW', + connect_split: [ + { + account_id: 'C_ACT_911WDFTY6GW', + share: 70, + }, + { + account_id: 'C_ACT_DHRI3498VB', + share: 8, + }, + ], }; const {result, rerender} = renderHook(() => diff --git a/libs/types.ts b/libs/types.ts index 22179f1..5501cb5 100644 --- a/libs/types.ts +++ b/libs/types.ts @@ -28,6 +28,11 @@ interface PaystackMetadata { [key: string]: any; } +interface PaystackConnectSplit { + account_id: string; + share: number; +} + export type callback = (response?: any) => void; export interface PaystackProps { @@ -50,6 +55,8 @@ export interface PaystackProps { 'data-custom-button'?: string; split_code?: string; split?: Record; + connect_split?: PaystackConnectSplit[]; + connect_account?: string; } export type InitializePayment = (options: { diff --git a/libs/use-paystack.ts b/libs/use-paystack.ts index c0961ae..2bc1432 100644 --- a/libs/use-paystack.ts +++ b/libs/use-paystack.ts @@ -32,6 +32,8 @@ export default function usePaystackPayment(hookConfig: HookConfig): InitializePa bearer = 'account', split, split_code, + connect_account, + connect_split, } = args; if (scriptLoaded) { @@ -56,6 +58,8 @@ export default function usePaystackPayment(hookConfig: HookConfig): InitializePa metadata, split, split_code, + connect_split, + connect_account, 'data-custom-button': args['data-custom-button'] || '', }; callPaystackPop(paystackArgs);