-
-
Save meetKazuki/598dc7727e3b741caee8cec485d58e51 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