Search code examples
vue.jsrazorpay

How to integrate razorpay in Vue.js


I am using Vue js Cdn and not using node. so I want to know how can I integrate Razorpay in Vue as inside Vue template script tags are not allowed. Can anyone help me with that


Solution

  • You would have to implement the manual checkout as given on the Razorpay docs. Read this for reference. You can include the script tag in index.html.

    <button id="rzp-button1">Pay</button>
    <script src="https://checkout.razorpay.com/v1/checkout.js"></script>
    <script>
    var options = {
        "key": "YOUR_KEY_ID",
        "amount": "2000", // 2000 paise = INR 20
        "name": "Merchant Name",
        "description": "Purchase Description",
        "image": "/your_logo.png",
        "handler": function (response){
            alert(response.razorpay_payment_id);
        },
        "prefill": {
            "name": "Gaurav Kumar",
            "email": "[email protected]"
        },
        "notes": {
            "address": "Hello World"
        },
        "theme": {
            "color": "#F37254"
        }
    };
    var rzp1 = new Razorpay(options);
    
    document.getElementById('rzp-button1').onclick = function(e){
        rzp1.open();
        e.preventDefault();
    }
    </script>