Skip to content

Instantly share code, notes, and snippets.

@dozykeys
Created October 5, 2020 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dozykeys/d870d332afa5301af03bf571b7282169 to your computer and use it in GitHub Desktop.
Save dozykeys/d870d332afa5301af03bf571b7282169 to your computer and use it in GitHub Desktop.
app.get('/payment/verify', async(req,res) => {
const ref = req.query.reference;
let output;
await axios.get(`https://api.paystack.co/transaction/verify/${ref}`, {
headers: {
authorization: "Bearer TEST SECRET KEY",
//replace TEST SECRET KEY with your actual test secret
//key from paystack
"content-type": "application/json",
"cache-control": "no-cache",
},
).then((success)=>{
output=success;
}).catch((error)=>{
output=error;
});
//now we check for internet connectivity issues
if(!output.response && output.status!==200) throw new UserInputError("No internet Connection");
//next,we confirm that there was no error in verification.
if(output.response && !output.response.data.status) throw new UserInputError( "Error verifying payment , 'unknown Transaction Reference Id'");
}
//we return the output of the transaction
res.status(200).send("Payment was successfully verified");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment