diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index b24a7e6..32fc066 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [14.x, 16.x, 18.x] + node-version: [14.x, 16.x, 18.x, 20.x] steps: - uses: actions/checkout@v2 diff --git a/dist/index.es.js.map b/dist/index.es.js.map index 2920845..f5e531b 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 {InitializePayment, PaystackProps} from './types';\nimport usePaystackScript from './paystack-script';\nimport {callPaystackPop} from './paystack-actions';\n\nexport default function usePaystackPayment(hookConfig: Partial): 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,CAAC;AAMrB,SAAU,iBAAiB,GAAA;IACvC,IAAM,GAAG,GAAG,qCAAqC,CAAC;IAE5C,IAAA,EAAA,GAAoB,QA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B,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 } = 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,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,CAAC,EAHK,KAAK,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,QAAQ,QAGpB,CAAC;AAEH,IAAA,SAAS,CAAC,YAAA;AACR,QAAA,IAAI,aAAa,CAAC,Q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AiB,uBAAA,EAAE,SAAS,eAAA,EAAE,OAAO,aAA+B,CAAC;AAEpF,IAAA,IAAM,yBAAyB,GAAG,YAAA,EAAY,OAAA,iBAAiB,CAAC,EAAC,MAAM,EAAA,MAAA,EAAE,SAAS,EAAA,SAAA,EAAE,OAAO,EAAA,OAAA,EAAC,CAAC,CAAA,EAAA,CAAC;IAC9F,OAAO,QAAQ,CAAC,EAAC,iBAAiB,EAAE,yBAAyB,EAAE,GAAG,EAAA,GAAA,EAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF;AACA,IAAM,gBAAgB,GAAG,UAAU,CACjC,UACE,EAAwF,EACxF,GAAQ,EAAA;AADP,IAAA,IAAA,QAAQ,GAAA,EAAA,CAAA,QAAA,EAAa,WAAW,GAAA,EAAA,CAAA,SAAA,EAAW,SAAS,GAAA,EAAA,CAAA,OAAA,EAAK,MAAM,GAAhE,MAAA,CAAA,EAAA,EAAA,CAAA,UAAA,EAAA,WAAA,EAAA,SAAA,CAAiE,CAAD,CAAA;AAGhE,IAAA,IAAM,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,YAAW,EAAA,OAAA,IAAI,CAAA,EAAA,CAAC;AAC9D,IAAA,IAAM,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,YAAW,EAAA,OAAA,IAAI,CAAA,EAAA,CAAC;AACxD,IAAA,QACE,KAAA,CAAA,aAAA,CAAC,gBAAgB,EAAA,QAAA,CAAA,EAAA,EAAK,MAAM,EAAA,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 diff --git a/dist/index.js.map b/dist/index.js.map index 608e889..f83250b 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 {InitializePayment, PaystackProps} from './types';\nimport usePaystackScript from './paystack-script';\nimport {callPaystackPop} from './paystack-actions';\n\nexport default function usePaystackPayment(hookConfig: Partial): 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,QAAQ,QAGpB,CAAC;AAEH,IAAAC,eAAS,CAAC,YAAA;AACR,QAAA,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC/B,YAAA,QAAQ,CAAC;AACP,gBAAA,MAAM,EAAE,IAAI;AACZ,gBAAA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A,EAAY,OAAA,iBAAiB,CAAC,EAAC,MAAM,EAAA,MAAA,EAAE,SAAS,EAAA,SAAA,EAAE,OAAO,EAAA,OAAA,EAAC,CAAC,CAAA,EAAA,CAAC;IAC9F,OAAO,QAAQ,CAAC,EAAC,iBAAiB,EAAE,yBAAyB,EAAE,GAAG,EAAA,GAAA,EAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF;AACA,IAAM,gBAAgB,GAAGC,gBAAU,CACjC,UACE,EAAwF,EACxF,GAAQ,EAAA;AADP,IAAA,IAAA,QAAQ,GAAA,EAAA,CAAA,QAAA,EAAa,WAAW,GAAA,EAAA,CAAA,SAAA,EAAW,SAAS,GAAA,EAAA,CAAA,OAAA,EAAK,MAAM,GAAhE,MAAA,CAAA,EAAA,EAAA,CAAA,UAAA,EAAA,WAAA,EAAA,SAAA,CAAiE,CAAD,CAAA;AAGhE,IAAA,IAAM,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,YAAW,EAAA,OAAA,IAAI,CAAA,EAAA,CAAC;AAC9D,IAAA,IAAM,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,YAAW,EAAA,OAAA,IAAI,CAAA,EAAA,CAAC;AACxD,IAAA,QACE,KAAA,CAAA,aAAA,CAAC,gBAAgB,EAAA,QAAA,CAAA,EAAA,EAAK,MAAM,EAAA,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.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,QAAQ,QAGpB,CAAC;AAEH,IAAAC,eAAS,CAAC,YAAA;AACR,QAAA,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC/B,YAAA,QAAQ,CAAC;AACP,gBAAA,MAAM,EAAE,IAAI;AACZ,gBAAA,KAAK,EAAE,KAAK;AACb,aAAA,CAAC,CAAC;SACJ;aAAM;AACL,YAAA,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAExB,IAAM,QAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;A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,yBAAyB,EAAE,GAAG,EAAA,GAAA,EAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF;AACA,IAAM,gBAAgB,GAAGC,gBAAU,CACjC,UACE,EAAwF,EACxF,GAAQ,EAAA;AADP,IAAA,IAAA,QAAQ,GAAA,EAAA,CAAA,QAAA,EAAa,WAAW,GAAA,EAAA,CAAA,SAAA,EAAW,SAAS,GAAA,EAAA,CAAA,OAAA,EAAK,MAAM,GAAhE,MAAA,CAAA,EAAA,EAAA,CAAA,UAAA,EAAA,WAAA,EAAA,SAAA,CAAiE,CAAD,CAAA;AAGhE,IAAA,IAAM,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,YAAW,EAAA,OAAA,IAAI,CAAA,EAAA,CAAC;AAC9D,IAAA,IAAM,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,YAAW,EAAA,OAAA,IAAI,CAAA,EAAA,CAAC;AACxD,IAAA,QACE,KAAA,CAAA,aAAA,CAAC,gBAAgB,EAAA,QAAA,CAAA,EAAA,EAAK,MAAM,EAAA,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 diff --git a/dist/types.d.ts b/dist/types.d.ts index 700debf..04aa83f 100644 --- a/dist/types.d.ts +++ b/dist/types.d.ts @@ -1,4 +1,4 @@ -type Currency = 'NGN' | 'GHS' | 'USD' | 'ZAR' | 'KES' | 'XOF'; +export type Currency = 'NGN' | 'GHS' | 'USD' | 'ZAR' | 'KES' | 'XOF'; type PaymentChannels = 'bank' | 'card' | 'qr' | 'ussd' | 'mobile_money' | 'eft' | 'bank_transfer' | 'payattitude'; type Bearer = 'account' | 'subaccount'; type phone = number | string; @@ -38,6 +38,7 @@ export interface PaystackProps { export type InitializePayment = (options: { onSuccess?: callback; onClose?: callback; - config?: PaystackProps; + config?: Omit; }) => void; +export type HookConfig = Omit, 'publicKey'> & Pick; export {}; diff --git a/dist/use-paystack.d.ts b/dist/use-paystack.d.ts index 51688f4..19ba7b0 100644 --- a/dist/use-paystack.d.ts +++ b/dist/use-paystack.d.ts @@ -1,2 +1,2 @@ -import { InitializePayment, PaystackProps } from './types'; -export default function usePaystackPayment(hookConfig: Partial): InitializePayment; +import { HookConfig, InitializePayment } from './types'; +export default function usePaystackPayment(hookConfig: HookConfig): InitializePayment; diff --git a/package.json b/package.json index 72d04e2..7fbc275 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@babel/core": "^7.21.4", "@babel/preset-env": "^7.21.4", "@babel/preset-typescript": "^7.21.4", - "@rollup/plugin-commonjs": "^24.0.1", + "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-typescript": "^11.0.0", "@testing-library/react": "^14.0.0", @@ -50,28 +50,28 @@ "@types/jest": "^29.5.0", "@types/react": "^18.0.32", "@types/react-dom": "^18.0.11", - "@typescript-eslint/eslint-plugin": "^5.57.0", - "@typescript-eslint/parser": "^5.57.0", + "@typescript-eslint/eslint-plugin": "^6.17.0", + "@typescript-eslint/parser": "^6.17.0", "babel-eslint": "^10.1.0", "babel-jest": "^29.5.0", "eslint": "^8.37.0", - "eslint-config-prettier": "^8.8.0", + "eslint-config-prettier": "^9.1.0", "eslint-config-standard": "^17.0.0", "eslint-plugin-jest": "^27.2.1", - "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-prettier": "^5.1.2", "eslint-plugin-react": "^7.32.2", "jest": "^29.5.0", "jest-environment-jsdom": "^29.5.0", - "prettier": "^2.8.7", + "prettier": "^3.1.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-test-renderer": "^18.2.0", - "rollup": "^3.20.2", + "rollup": "^4.9.2", "rollup-plugin-babel": "^4.4.0", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-peer-deps-external": "^2.2.4", - "rollup-plugin-typescript2": "^0.34.1", + "rollup-plugin-typescript2": "^0.36.0", "ts-jest": "^29.1.0", "typescript": "^5.0.3" }