Not able to call custom function/service inside razorPaySuccessHandler in Angular

31 views Asked by At

I am trying to call an API after payment success. So I was calling Function inside razorPaySuccessHandler function but it is throwing error as below:

constructor(
  private userService: UserService
) { }

  paymentProcess() {
    let creditDialogRef = this.dialog.open(CreditFormComponent);
    creditDialogRef.afterClosed().subscribe(result => {
      this.userService.createOrder(this.id).subscribe(res => {

        // this.RAZORPAY_OPTIONS.amount = result.data.amount;
        this.RAZORPAY_OPTIONS.amount = '100';
        this.RAZORPAY_OPTIONS.order_id = '';

        // binding this object to both success and dismiss handler
        this.RAZORPAY_OPTIONS["handler"] = this.razorPaySuccessHandler.bind(this);

        let razorpay = new Razorpay(this.RAZORPAY_OPTIONS);
        razorpay.open();
      });
    });
  }

public razorPaySuccessHandler(response) {
        console.log("razorpay",response)
        if (response.razorpay_payment_id) {
          console.log(response, "Order Placed");
          this.razorpayResponse = `Razorpay Response`;
          this.userService.verifyOrder(this.orderId).subscribe(res=>{
              console.log(res)
          })
        }
        else {
          console.log("Payment failed")
        }
      }

I am getting error:

Uncaught TypeError: Cannot read property 'verifyOrder' of undefined
    at Ui.push../src/app/views/marketing/home-page/home-page.component.ts.HomePageComponent.razorPaySuccessHandler (home-page.component.ts:214)
    at checkout.js:1
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)

How do I call my own function or service inside it?

0

There are 0 answers