Created
October 5, 2020 13:08
-
-
Save dozykeys/d870d332afa5301af03bf571b7282169 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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