Last active
May 20, 2020 17:51
-
-
Save alabobriggs/a5a3196fbe702a0e868f5e91af2cef65 to your computer and use it in GitHub Desktop.
Simple JS implementation for paystack
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
makeInvestment: async () => { | |
/* | |
add this script inside your page head tag <script async src="https://js.paystack.co/v1/inline.js" /> | |
this will make the PasystackPop available | |
*/ | |
const handler = PaystackPop.setup({ | |
key: process.env.PAYSTACK_LIVE_API, | |
email: '[email protected]', | |
amount: `100000`, | |
currency: user.currency, | |
ref: `${Date.now()}_xxxxxxxx`, | |
metadata: { | |
custom_fields: [ | |
{ | |
display_name: 'Customer Name', | |
variable_name: 'customer_name', | |
value: `Alabo Briggs` | |
} | |
] | |
}, | |
callback: async (result) => { | |
/* | |
Do what you want with result object here, you can handle redirect or make post | |
request to server here if successful | |
*/ | |
}, | |
onClose: () => { | |
// if payment was succefull handle error here | |
} | |
}); | |
return handler.openIframe(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment