Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Class object "this" is null in paytm successCallback function #41

Open
manojbharti opened this issue May 11, 2020 · 6 comments
Open

Class object "this" is null in paytm successCallback function #41

manojbharti opened this issue May 11, 2020 · 6 comments

Comments

@manojbharti
Copy link

manojbharti commented May 11, 2020

@ArunYogi I have integrated this plugin in my ionic-5 App and it is working fine but after successful payment I need to save transaction detail into database by calling my backend API. Posting successCallback function below...

successCallback(response) {
console.log("........", response)
if (response.STATUS == "TXN_SUCCESS") {
var txn_id = response.TXNID;
var paymentmode = response.PAYMENTMODE;
console.log("txn_id => ", txn_id);
this.paytmTransaction();
} else {
alert("Transaction Failed for reason " + response.RESPMSG);
}
}

I am calling this.paytmTransaction(); function after succesfull payment but I am getting error in console ==> TypeError: Cannot read property 'paytmTransaction' of null
class object "this" is null in successCallback function, please let me know what i am missing here.

@remorr25
Copy link

remorr25 commented Jul 6, 2020

@manojbharti please check below code

declare var paytm: any;

@Component({
  selector: "app-home",
  templateUrl: "home.page.html",
  styleUrls: ["home.page.scss"]
})
export class HomePage {
  base_url =
    "http://DOMAIN.COM/paytm/paytmChecksum/generateChecksum.php";
   constructor(private http: HttpClient) {
  }

  txnRequest() {
    let txn = {
      MID: "PAYTM_MID", // PayTM Credentials
      //ORDER_ID: "ORDER0000000001", //Should be unique for every order.
      CUST_ID: "CUST0001",
      INDUSTRY_TYPE_ID: "Retail", // PayTM Credentials
      CHANNEL_ID: "WAP", // PayTM Credentials
      TXN_AMOUNT: "10", // Transaction Amount should be a String
      WEBSITE: "APPSTAGING" // PayTM Credentials
    };
     
     this.http.post(this.base_url, txn).subscribe((response: any) => {
       console.log("API -" + JSON.stringify(response));
       paytm.startPayment(response, this.successCallback, this.failureCallback);
     });
   
  }

   successCallback(response) {
      console.log("gateway response", JSON.stringify(response));
     if (response.STATUS == "TXN_SUCCESS") {
        
      var txn_id = response.TXNID;
      var paymentmode = response.PAYMENTMODE;
      console.log("txn_id => ", txn_id);
      alert("txn_id => " + txn_id);
    } else {
      alert("Transaction Failed for reason " + response.RESPMSG);
    }
  }

  failureCallback(error) {

    alert("Transaction Failed for reason " + error.RESPMSG);
  }
   

}

@manojbharti
Copy link
Author

@remorr25 Thank you...

@Dipak26
Copy link

Dipak26 commented Dec 25, 2020

@remorr25 I want to call my API from inside successCallback and errorCallback but I am not able to get my ionic 5 angular 10 component reference with in this plugin function how I get that reference. I am a beginner in angular 2 and above.

@manojbharti
Copy link
Author

@Dipak26 paste your code here.

@Dipak26
Copy link

Dipak26 commented Dec 28, 2020

@Dipak26 paste your code here.

Thanks, @manojbharti for the quick reply but I tried and solve the problem. I pass the component reference and use that.

@manojbharti
Copy link
Author

@Dipak26 Great...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants