stripe.js 在 Stripe 对象创建失败时未报告错误。

huangapple go评论68阅读模式
英文:

stripe.js not reporting error when Stripe object creation fails

问题

I have a very intermittent failure where my JavaScript fails to produce a Stripe PaymentElement, which results in the client not getting a payment form. I can't reliably reproduce this, but I get exactly the same effect if I supply an invalid key when calling Stripe(publishableKey). I'm running test mode, not live.

The problem is that I can't persuade the call to Stripe to report an error if I deliberately give it the wrong key. The code below just carries on logging "stripe: key Ok" in the server logs, even when the key is wrong and the subsequent attempt to create a paymentElement fails. Can anyone give me any pointers on how to detect an error here? I've had this for a couple of weeks and I'm completely out of ideas. In this app, the client carries out an Ajax request to get the key from the server, and the code below is the callback function when the key is returned:

stripeFuncs.setPKey = function(pkey) {
serverLog(1, "stripe: received key (" + pkey + ")"); // record a message on the server
try {
stripe = Stripe(pkey);
} catch(e) {
// nothing is thrown: this never happens
modalAlert("Error", "Cannot initialise Stripe ('" + e.message + "').");
return;
}
serverLog(1, "stripe: key Ok");
};

英文:

I have a very intermittent failure where my JavaScript fails to produce a Stripe PaymentElement, which results in the client not getting a payment form. I can't reliably reproduce this, but I get exactly the same effect if I supply an invalid key when calling Stripe(publishableKey). I'm running test mode, not live.

The problem is that I can't persuade the call to Stripe to report an error if I deliberately give it the wrong key. The code below just carries on logging "stripe: key Ok" in the server logs, even when the key is wrong and the subsequent attempt to create a paymentElement fails. Can anyone give me any pointers on how to detect an error here? I've had this for a couple of weeks and I'm completely out of ideas. In this app, the client carries out an Ajax request to get the key from the server, and the code below is the callback function when the key is returned:

   stripeFuncs.setPKey = function(pkey) {
      serverLog(1, "stripe: received key (" + pkey + ")");  // record a message on the server
      try {
         stripe = Stripe(pkey);
      } catch(e) {
         // nothing is thrown: this never happens
         modalAlert("Error", "Cannot initialise Stripe ('" + e.message + "').");
         return;
      }
      serverLog(1, "stripe: key Ok");
   };

答案1

得分: 1

The loaderror event can catch the wrong key or any error upon loading. ie.

paymentElement.on('loaderror', function (ev){
  console.log(ev.elementType);
  console.log(ev.error);
})
英文:

The loaderror event can catch the wrong key or any error upon loading. ie.

paymentElement.on('loaderror',function (ev){
  console.log(ev.elementType);
  console.log(ev.error);
})

huangapple
  • 本文由 发表于 2023年6月12日 03:44:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452259.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定