angular - 在 Angular 组件内接收 POST 数据

标签 angular payment-gateway

我正在 Angular 版本 7 中集成支付网关。

支付网关需要输入如下数据

requestParameter : MerchantId||CollaboratorID||Encrypted_string

我尝试使用 ngForm 提交表单,如下所示,但我的请求没有发布到支付网关 url 并收到错误 404 未找到“http://localhost:4200/direcPayment/”和支付网关的 session 过期消息作为响应。就像如果请求中有任何错误,您会收到 session 过期消息。
<form  (ngSubmit)="onSubmit()" method="POST" mt-3>

在代码后面,我根据需要传递参数并进行 http.post 调用,如下所示。单击 OnSubmit 后,我​​使用加密字符串调用了 formSubmit
formSubmit( encryptedString) {
const formData = new FormData();
formData.append( 'requestParameter', encryptedString);

this.http.post('direcPayment/', formData, httpFormDataOptions)
    .subscribe((resposne) => {
      console.log(resposne);
    });

}

在“httpFormDataOptions”中,我在标题下方添加了
const httpFormDataOptions = {
  headers: new HttpHeaders(),
};
httpFormDataOptions.headers.append('Access-Control-Allow-Origin', '*');
httpFormDataOptions.headers.append('Access-Control-Allow-Methods', 'DELETE, POST, GET, OPTIONS');
httpFormDataOptions.headers.append('Access-Control-Allow-Headers', 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');

/direcPayment 指的是我的 Proxy.config.json 文件如下
{
  "/direcPayment": {
  "target": "PaymentGatewayURL",
  "secure": true,
  "pathRewrite": {"^/direcPayment" : ""},
  "changeOrigin": true
  },
}

所以目前我使用 ngNoForm 并使用 action 属性提交表单。

所以我想问两个问题
  • 使用 httpClient POST 方法将表单提交到支付网关链接
  • 支付网关说,如果支付成功/失败,那么他们将重定向到成功/失败 URL 作为加密格式的 POST 数据,那么如何以 Angular 接收数据到特定 URL?如果有人在两种情况下都使用 httpClient 调用或 ngNoForm
  • 调用了我的 angular URL,是否有任何方法可以接收数据

    谢谢。

    最佳答案

    您的代码:

    this.http.post('direcPayment/', formData, httpFormDataOptions)
        .subscribe((resposne) => {
          console.log(resposne);
        });
    }
    

    所以post数据会提交到http://localhost:4200/direcPayment/ , 你应该把你的支付网关的 URL 放在这里

    关于angular - 在 Angular 组件内接收 POST 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53926233/

    相关文章:

    javascript - angular 中 .next() 函数的解释

    java - 无法在 Android 中集成 ICICI 支付网关

    wordpress - 没有 PayPal 帐户无法启用结帐

    javascript - Angular 7+ : Images in assets folder does not appear

    angular - Angular 11 中的 "No overload matches this call"

    angular - TypeError : this. sqlites.executeSql 不是函数

    javascript - 用于文件上传的 Angular2 服务器端监听器

    php - Sagepay 5006 错误代码修复

    php - 如何使用 PHP 在 facebook 应用程序 Canvas 中实现 paypal?

    php - 在 WooCommerce 付款后立即更改订单状态