javascript - 使用函数时无法从 Angular 发布到 API
问题描述
我正在尝试在回调函数中发布付款后生成的令牌,但问题是我无法在回调函数中发布该令牌,因为它无法识别HttpClient
.
代码如下。
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);
}
}
如果我在函数中调用 POST 方法,则会收到以下错误:
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()
正在拥有需要发送回 API 的令牌。有人可以帮我吗?
解决方案
推荐阅读
- macos - MacOS - 屏幕解锁时切换 wifi
- c# - XML-Warnings 不会在带有 ReSharper 18.2 的 Studio 17 中显示
- php - 比较键上的两个数组,如果键不匹配,则创建多个数组集值
- dart - Flutter:具有多个小部件的自定义抽屉
- java - 从Android(JAVA)的Json(序列化形式)中检索数据
- sensors - 有哪些很好的资源可以了解 IMU 的传感器漂移校正?
- ruby-on-rails - Ruby Active Record 加入并包含为计数生成不同的 sql
- android - 使用 Espresso 进行 E2E 测试:在完成 @Test/正确构建更大的测试用例后保持应用程序打开
- django - Django:基于模型实例属性的权限
- ibm-watson - Watson 发现结果在聊天机器人中以 pdf 形式出现