Created
April 22, 2021 13:18
-
-
Save pena56/4476e66f469037a3e50e6995cf936528 to your computer and use it in GitHub Desktop.
This file contains 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
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