你如何在 ADYEN Card Component 中存储 state.Data 和 state.isValid ? 不要在生产中这样做!!!!

问题描述

所以我已经阅读了文档并遵循了到目前为止的所有内容。但是,在 handleOnChange 函数中,我无法发布数据,因为它给出了错误:

ERROR

这是我目前尝试发布数据的方式,我愿意接受任何建议。

function handleOnChange(state,component) {
  state.isValid 
  state.data 
  component 
  if (state.isValid === true) {
    this.http.post(environment.paymentFunctionurl + '/',{ amount: this.amount,content: state.data}).subscribe((res) => {
      console.log(res);
    })
  }
}

我尝试将它们存储为变量,但结果为未定义。我在这里错过了什么?

解决方法

您的错误是访问 http,它不是 this 的一部分。您需要确保将 http 添加到 this 或可能将 http 放在 window 上,以便无论您的范围如何都可以访问它。

旁注:您的示例正在从客户端传递 amount

不要在生产中这样做!!!!

您可能只是在测试时这样做,但这在测试中甚至是不好的做法。客户端可能是恶意的并更改了金额,而您应该使用自己的后端/数据库来决定收费多少。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...