简体   繁体   English

为什么我的Hpp支付功能需要点击两次才能打开?

[英]Why does my Hpp payment function take two clicks to open?

I have a payment page which first does an axios call to get the required HPP model data.我有一个支付页面,它首先调用 axios 来获取所需的 HPP 模型数据。 I then call the Hpp function to open the hosted page but it takes 2 clicks to complete the action.然后我调用 Hpp 函数打开托管页面,但需要单击 2 次才能完成操作。 I have tried putting the code direct from the hpp function but the same thing happens.我曾尝试将代码直接来自 hpp 函数,但同样的事情发生了。 Any help is appreciated.任何帮助表示赞赏。

paymentFunction(){  
  const data = {
      //my passed data
  };

  const response = axios ({
    url: "Myserverapitogetmodeldata",
    data: data,
    method: "POST"
  })  

  //open the hosted page
  this.hppFunction(response.data.id);

}

  hppFunction(i) {
$.getJSON("serverapimodeldata" + i, function (
  jsonFromRequestEndpoint
) {
  debugger;
  window.RealexHpp.setHppUrl("realexpaymentsapi");
  window.RealexHpp.lightbox.init(
    "payButtonId",
    "responseUrl",
    jsonFromRequestEndpoint
  );
});

} }

 <MDBBtn id="payButtonId" onClick={() =>this.paymentFunction()}>Pay Now</MDBBtn>

if i call the initial function with onClick={this.paymentFunction()}, this works but it is doing the post to the Db with the onchange and posting each time a character is entered如果我用 onClick={this.paymentFunction()} 调用初始函数,这是可行的,但是每次输入一个字符时,它都会使用 onchange 向 Db 进行发布和发布

It seems like这好像是

window.RealexHpp.lightbox.init(
  "payButtonId",
  "responseUrl",
  jsonFromRequestEndpoint
);

should be called before the button is clicked, as it sets up the button.应该在单击按钮之前调用,因为它设置了按钮。 At the moment your 1st click is setting up the button, and your 2nd click is executing the payment.目前,您的第一次点击正在设置按钮,而您的第二次点击正在执行付款。

See this example where the RealexHpp.lightbox.init method is called on page load.请参阅此示例,其中在页面加载时调用RealexHpp.lightbox.init方法。

EDIT: Your axios call also isn't waiting for a response, it just continues.编辑:您的 axios 调用也不在等待响应,它只是继续。 You can try:你可以试试:

axios({
  url: "Myserverapitogetmodeldata",
  data: data,
  method: "POST"
})
.then(response => {
  //open the hosted page
  this.hppFunction(response.data.id);
});  

And see if it fixes your issue.看看它是否能解决你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM