Skip to content

Instantly share code, notes, and snippets.

@alabobriggs
Last active May 20, 2020 17:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alabobriggs/a5a3196fbe702a0e868f5e91af2cef65 to your computer and use it in GitHub Desktop.
Save alabobriggs/a5a3196fbe702a0e868f5e91af2cef65 to your computer and use it in GitHub Desktop.
Simple JS implementation for paystack
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: 'user@example.com',
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