Skip to content

Instantly share code, notes, and snippets.

@vamsipavanmahesh
Created March 1, 2016 06:44
Show Gist options
  • Save vamsipavanmahesh/9b7e5670b1b1e89f310d to your computer and use it in GitHub Desktop.
Save vamsipavanmahesh/9b7e5670b1b1e89f310d to your computer and use it in GitHub Desktop.
$(document).ready(function(){
var options = {
"key": "<%= "#{Figaro.env.MERCHANT_KEY_ID}" %>",
"amount": "<%= "#{@product.price}" %>",
"name": "<%= "#{@product.seller.name}" %>",
"description": "<%= "#{@product.description}" %>",
"image": "/images/product.jpg",
"handler": function (response){
var mapForm = document.createElement("form");
mapForm.target = "_self";
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "/purchase";
var mapInput = document.createElement("input");
mapInput.type = "text";
mapInput.name = "payment_id";
mapInput.value = response.razorpay_payment_id;
mapForm.appendChild(mapInput);
var mapInput2 = document.createElement("input");
mapInput2.type = "text";
mapInput2.name = "user_id";
mapInput2.value = "<%= "#{current_user.id}" %>";
var mapInput3 = document.createElement("input");
mapInput3.type = "text";
mapInput3.name = "product_id";
mapInput3.value = "<%= "#{@product.id}" %>";
mapForm.appendChild(mapInput);
mapForm.appendChild(mapInput2);
mapForm.appendChild(mapInput3);
mapForm.submit();
},
"prefill": {
"name": "<%= "#{current_user.name}" %>",
"email": "<%= "#{current_user.email}" %>"
},
"notes": {
"address": "Hello World"
},
"theme": {
"color": "#198F69"
}
};
$("#rzp-button1").click(function(e){
var rzp1 = new Razorpay(options);
rzp1.open();
e.preventDefault();
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment