Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

OnSuccess & OnClose Function not working #101

Open
multiman95 opened this issue May 11, 2024 · 7 comments
Open

OnSuccess & OnClose Function not working #101

multiman95 opened this issue May 11, 2024 · 7 comments

Comments

@multiman95
Copy link

const config = {
  reference: (new Date()).getTime().toString(),
  email: "[email protected]",
  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

@iamefe
Copy link

iamefe commented May 26, 2024

Same here.

@kodervine
Copy link

I am having the same issue. Have you been able to work around this @multiman95 @iamefe

@iamefe
Copy link

iamefe commented Jun 19, 2024

@kodervine Yes. Here's what worked for me:

  initializePayment({ onSuccess, onClose });

I wrapped both onSuccess and onClose in curly brackets before they were recognized. I think the documentation needs to be updated.

@kodervine
Copy link

@kodervine Yes. Here's what worked for me:

  initializePayment({ onSuccess, onClose });

I wrapped both onSuccess and onClose in curly brackets before they were recognized. I think the documentation needs to be updated.

That worked. Thank you so very much. Yes, definitely a documentation issue

@iamefe
Copy link

iamefe commented Jun 19, 2024

@kodervine Yes. Here's what worked for me:

  initializePayment({ onSuccess, onClose });

I wrapped both onSuccess and onClose in curly brackets before they were recognized. I think the documentation needs to be updated.

That worked. Thank you so very much. Yes, definitely a documentation issue

You are welcome. I just made a pull request for the edit.
#106

@kodervine
Copy link

@kodervine Yes. Here's what worked for me:

  initializePayment({ onSuccess, onClose });

I wrapped both onSuccess and onClose in curly brackets before they were recognized. I think the documentation needs to be updated.

That worked. Thank you so very much. Yes, definitely a documentation issue

You are welcome. I just made a pull request for the edit. #106

Yeah hopefully. I know the older integration I'd had with paystack without the curly braces still work. But let's see what they resolve it

@daviddivinefavour
Copy link

Well.. Thanks guys, was facing the same difficulty for over 40mins now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants