Skip to content

Instantly share code, notes, and snippets.

@piyushgarg-dev
Last active May 9, 2021 07:15
Show Gist options
  • Save piyushgarg-dev/0120722c459474891c515bd635e4522d to your computer and use it in GitHub Desktop.
Save piyushgarg-dev/0120722c459474891c515bd635e4522d to your computer and use it in GitHub Desktop.
buyButton.addEventListener('click', async (event) => {
const response = await fetch('/order', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ amount: 500 }) // Rs.500
});
const responseJson = await response.json();
const { order } = responseJson;
const razorPayOptions = {
key: '<YOUR_KEY_ID_HERE>',
amount: 500,
currency: 'INR',
name: `Buy Shirt`,
description: `Paying for testing`,
order_id: order.id,
handler: function (response) { // handler function when payment is successfull
const razorpayPaymentId = response['razorpay_payment_id'];
const razorpayOrderId = response['razorpay_order_id'];
const razorpaySignature = response['razorpay_signature'];
console.log('Payment successfull');
},
};
const razorpayInstance = new Razorpay(razorPayOptions);
razorpayInstance.open();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment