Skip to content

Instantly share code, notes, and snippets.

@voidnerd
Last active July 10, 2019 15:24
Show Gist options
  • Select an option

  • Save voidnerd/c76dad8f4e90a9181d4b1346e8aec42d to your computer and use it in GitHub Desktop.

Select an option

Save voidnerd/c76dad8f4e90a9181d4b1346e8aec42d to your computer and use it in GitHub Desktop.
const axios = require('axios');
const secretKey = "<PAYSTACK_SECRET_KEY>"
const initializePaystack = async (form) => {
const options = {
url : 'https://api.paystack.co/transaction/initialize',
headers : {
'authorization': `Bearer ${secretKey}`,
'content-type': 'application/json',
'cache-control': 'no-cache'
},
method: "POST",
data: form
}
return new Promise( async (resolve, reject) => {
try {
const { data } = await axios.request(options)
resolve(data)
} catch (err) {
reject(err);
}
})
}
const verifyPaystack = async (ref) => {
const options = {
url : 'https://api.paystack.co/transaction/verify/'+encodeURIComponent(ref),
headers : {
'authorization': `Bearer ${secretKey}`,
'content-type': 'application/json',
'cache-control': 'no-cache'
},
method: "GET"
}
return new Promise(async (resolve, reject) => {
try {
const { data } = await axios.request(options)
resolve(data);
} catch (err) {
reject(err);
}
})
}
module.exports = {initializePaystack, verifyPaystack};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment