Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

OnSuccess & OnClose Function not working #101

Open
@multiman95

Description

const config = {
 reference: (new Date()).getTime().toString(),
 email: "demo@gmail.com",
 amount: Math.ceil(final_fees_to_pay) * 100, 
 currency: "GHS",
 channels: ["card", "bank", "mobile_money", "bank_transfer", "qr", "eft"],
 metadata: {
 "item_id": 'item-1003944'
 },
 publicKey: 'pk_test_4b43c',
};
// onSuccess, Verify Transaction in server and then redirect to Success Page
const onSuccess = (reference) => {
 // Implementation for whatever you want to do with reference and after success call.
 console.log('Transaction Success ', reference);
 alert(reference)
 router.replace('/success')
};
// Cancel transaction when user closes payment modal
const onClose = () => {
 // implementation for whatever you want to do when the Paystack dialog closed.
 // alert('closed')
}
const PaystackHook = () => {
 const initializePayment = usePaystackPayment(config);
 return(
 <Button fullWidth color='primary' radius='full' size='lg' onClick={() => {initializePayment(onSuccess, onClose)}}> 
 <Image src='/images/default/paystack.jpg' width={30} height={30} className='rounded-full' alt='PayStack'/> Pay 
 </Button>
 )
}
return (
 <React.Fragment>
 
 <div className='mt-5'>
 <PaystackHook/>
 </div>
 
 </React.Fragment>
)
}

After payment success onSuccess does not work or throw any error and same as onClose

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /