在以下代码中,我遇到Stripe未处理付款的问题。我正确地从表单中获取所有值,但是在stripeResponseHandler函数中没有任何记录。我使用他们网站上提供的测试信用卡,并且在此错误之前我成功使用了几次。
我将https://js.stripe.com/v2/stripe-debug.js加载到我的javascript中,并且登录了Chrome控制台"看起来Stripe.js被加载了多次。请每页只加载一次。"但是我只在这个JS文件中设置了可发性键并加载
Stripe.setPublishableKey('pk_test_TK18ZwUnK2CT1Wmof8WsQl8S');
var payMeal = function(){
console.log("inside the paymeals function");
var x = document.getElementsByClassName("form-payment");
console.log("Number is " + x[0].value)
console.log("CVC is " + x[1].value)
console.log("Exp_Month is " + x[2].value)
console.log("Exp_Year is " + x[3].value)
console.log("The Stripe Object is",Stripe)
Stripe.card.createToken({
number: x[0].value,
cvc: x[1].value,
exp_month: x[2].value,
exp_year: x[3].value
}, stripeResponseHandler)
window.location.href = "../../meals"
};
var stripeResponseHandler = function(status, response){
console.log("IM IN THE RESPONSE HANDLER!!!!+++++***")
if(response.error){
console.log("THERE IS AN ERROR!!***")
console.log(response);
}
else{
console.log("submitting ajax to server with token");
token = response.id;
ajaxToServer(token);
}
}