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?