ashwamegh / razorpay-react-demo

Razorpay React.js bindings
https://ashwamegh.github.io/razorpay-react-demo/
MIT License
18 stars 8 forks source link

window.Razorpay is not a constructor #3

Closed abdulkadhir closed 5 years ago

abdulkadhir commented 5 years ago

I got an error window.Razorpay is not a constructor

`

placeOrder(){

let options = {
  "key": "RAZORPAY_KEY",
  "amount": this.state.amount, 
  "name": "Merchant Name",
  "description": "Purchase Description",
  "image": "/logo.png",
  "handler": function (response){
    alert(response.razorpay_payment_id);
  },
  "prefill": {
    "name": "xyz",
    "email": "123@xyz.com"
  },
  "notes": {
    "address": "Hello World"
  },
  "theme": {
    "color": "#F37254"
  }
};

const rzp = new window.Razorpay(options);
rzp.open();

}

`
rocknegi commented 5 years ago

I got an error window.Razorpay is not a constructor

`

placeOrder(){

let options = {
  "key": "RAZORPAY_KEY",
  "amount": this.state.amount, 
  "name": "Merchant Name",
  "description": "Purchase Description",
  "image": "/logo.png",
  "handler": function (response){
    alert(response.razorpay_payment_id);
  },
  "prefill": {
    "name": "xyz",
    "email": "123@xyz.com"
  },
  "notes": {
    "address": "Hello World"
  },
  "theme": {
    "color": "#F37254"
  }
};

const rzp = new window.Razorpay(options);
rzp.open();

}

onClick={(e) => this.placeOrder()} color="primary" size="lg">Place order `

just add this to your index.html

ghost commented 3 years ago

I got the same error. Just use

const rzp = new window.Razorpay({key});
rzp.createPayment(options); // key not required
ravipronteff commented 2 years ago

add in the HTML

Sameer1408 commented 2 years ago

Thank u So much @rocknegi

manishkumar-8218 commented 2 years ago

Thank u So much for providing solution@rocknegi

Akshay7623 commented 1 year ago

Thank you @rocknegi

AnittaMathew1 commented 1 year ago

I am getting same error for unit test TypeError: window.Razorpay is not a constructor But the razorpay page is working fine.. error only in unit test using jest