Skip to content

Instantly share code, notes, and snippets.

@pena56
Created April 22, 2021 13:18
Show Gist options
  • Save pena56/4476e66f469037a3e50e6995cf936528 to your computer and use it in GitHub Desktop.
Save pena56/4476e66f469037a3e50e6995cf936528 to your computer and use it in GitHub Desktop.
import axios from 'axios';
export const initializePayment = (email, name, amount) => {
let promise = new Promise(function (resolve, reject) {
axios({
method: 'post',
url: 'https://api.paystack.co/transaction/initialize',
headers: {
Authorization: `Bearer ${process.env.NEXT_PUBLIC_PAYSTACK_API_SECRET}`,
'Content-Type': 'application/json',
},
data: {
email: email,
amount: amount,
currency: 'NGN',
callback_url: 'http://127.0.0.1:3000/success',
metadata: {
custom_fields: [
{
display_name: 'Name',
variable_name: 'name',
value: name,
},
],
},
},
})
.then((res) => {
resolve(res.data.data.authorization_url);
})
.catch((err) => {
reject(err);
});
});
return promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment