0

I'm trying to post the token generated after payment in the call back function but the issue is like I'm unable to post that in callback function as it is not recognizing the HttpClient.

The code is as follows.

  async makePayment() {
      var token;
      var obj;
      var yoco = new window.YocoSDK({
    publicKey: 'xxxxxxxxxxxxxxxxxxxx',
    locale: 'auto',
    });
       await yoco.showPopup({
            amountInCents: 300,
            currency: 'ZAR',
            name: 'Your Store or Product',
            description: 'Awesome description',
            callback: await function (result) {
              if (result.error) {
                const errorMessage = result.error.message;
                alert("error occured: " + errorMessage);
              } else {
                alert("card successfully tokenised: " + result.id);
                token=result.id;
                obj = {
                    "token" : token,
                    "amountInCents" : 300,
                    "currency" : "ZAR"
                }
                this.resumeGeneratorService.PaymentCONFIRMMTF().subscribe(x=>{
                    var confirmationres = x;
                })
              }
            }
        });
  }
  async payment(){
      console.log(async);
    await this.makePayment();
    console.log("result");
    
    this.resumeGeneratorService.PaymentCONFIRMMTF().subscribe(x=>{
        var confirmationres = x;
    })
  }
  invokePayment() {
    if(!window.document.getElementById('stripe-script')) {
      const script = window.document.createElement("script");
      script.id = "stripe-script";
      script.type = "text/javascript";
      script.src = "https://js.yoco.com/sdk/v1/yoco-sdk-web.js";
      script.onload = () => {
        this.paymentHandler = (<any>window).YocoSDK
      }
      window.document.body.appendChild(script);
    }
}

If I'm calling the POST method in the function I'm getting the following error:

zone-evergreen.js:171 Uncaught TypeError: Cannot read property 'request' of undefined
at Object.yoco.showPopup.callback (build-cv.page.ts:359)
at Object.onSuccess (Checkout.tsx:32)
at index.tsx:59
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Zone.runTask (zone-evergreen.js:167)
at invokeTask (zone-evergreen.js:480)
at ZoneTask.invoke (zone-evergreen.js:469)
at timer (zone-evergreen.js:2552)

MakePayment() is having the token which need to be sent back to API. Can any one please help me on this?

R. Richards
  • 24,603
  • 10
  • 64
  • 64
  • Change `callback: await function (result) {` to `callback: await (result)=> {` – eko May 23 '21 at 13:24
  • @eko not working – Gibran Aakib May 23 '21 at 13:33
  • Are you using the `function` keyword anywhere else? And where are you calling the `payment` method? – eko May 23 '21 at 13:38
  • @eko `async payment(){ console.log(async); await this.makePayment(); console.log("result"); this.resumeGeneratorService.PaymentCONFIRMMTF().subscribe(x=>{ var confirmationres = x; }) }` Here I'm calling payment Method no not using function any where else – Gibran Aakib May 23 '21 at 13:42
  • I didn't ask for the `payment` method; I asked you where you were calling it from. You can also try to create another `this` variable under your `makePayment` method like `async makePayment() { var self = this; var token;` then use that in your function `self.resumeGeneratorService.PaymentCONFIRMMTF()..`. The bottom line is that your `this` is not referring to your global scope. Please read the duplicate question and you will figure it out. – eko May 23 '21 at 13:46
  • @eko Okay I'll look into that.self is also not working – Gibran Aakib May 23 '21 at 13:52
  • 1
    @eko Solve Thanks Buddy. Var self = this worked earlier placed in wrong method I was struggling since morning 8:00 AM Thank You so much yaar – Gibran Aakib May 23 '21 at 13:57

0 Answers0