英文:
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);
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论