paystack icon indicating copy to clipboard operation
paystack copied to clipboard

How to pass callback for successful payment

Open alexander01202 opened this issue 3 years ago • 2 comments

Hello. I am trying to pass a callback or handle some sort of function when there is a successful or failed payment. Here is my code:

paystack.transaction.initialize({ email: ${req.query.email}, amount: req.query.amount * 100, interval: ${req.query.interval}`, currency: 'NGN', plan: response.data.plan_code, callback: function(response) {

                        var reference = response.reference;
                        console.log('Payment complete! Reference: ' + reference);
                       
                      },
                })
                .then(response => {
                    if (response.status) {
                        res.send({ success:true, url: response.data.authorization_url })   
                    }else{
                        res.send({ success:false, url: null })
                    }
                }).catch(err => {
                    console.log(err)
                    res.send({ success:false,url:null })
                })`

The callback isn't working unfortunately. I have no idea why. I need to navigate to another screen after a cancelled or successful payment.

alexander01202 avatar Jun 23 '22 13:06 alexander01202

Hi! try out this package. It's not yet a major release but it supports typescript and other JavaScript runtime like bun and Deno https://www.npmjs.com/package/@gray-adeyi/paystack-sdk

gray-adeyi avatar Sep 17 '24 09:09 gray-adeyi

@gray-adeyi/paystack-sdk 0.2.4 release is now available with even better type support 🔥 https://www.npmjs.com/package/@gray-adeyi/paystack-sdk

gray-adeyi avatar Dec 14 '24 11:12 gray-adeyi