Last active
July 10, 2019 15:24
-
-
Save voidnerd/c76dad8f4e90a9181d4b1346e8aec42d 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
| 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