我正在使用Stripe和Laravel 5.1,除了当我输入一个应该被拒绝的测试卡号码时我没有任何错误;也就是说,即使它应该存在,也不会存在共振 .
我收到一个令牌,好像一切都很顺利(例如:tok_16Y3wFAMxhd2ngVpHnky8VWX)
无论我使用什么测试卡,stripeResponseHandler()函数都不会在响应中返回错误 . 这是有问题的代码:
var PublishableKey = 'pk_test_Ed0bCarBWsgCXGBtjEnFeBVJ'; // Replace with your API publishable key
Stripe.setPublishableKey(PublishableKey);
/* Create token */
var expiry = $form.find('[name=cardExpiry]').payment('cardExpiryVal');
var ccData = {
number: $form.find('[name=cardNumber]').val().replace(/\s/g, ''),
cvc: $form.find('[name=cardCVC]').val(),
exp_month: expiry.month,
exp_year: expiry.year
};
Stripe.card.createToken(ccData, function stripeResponseHandler(status, response) {
console.log(status);
if (response.error) {
/* Visual feedback */
$form.find('[type=submit]').html('Please Try Again');
/* Show Stripe errors on the form */
$form.find('.payment-errors').text(response.error.message);
$form.find('.payment-errors').closest('.row').show();
} else {
/* Visual feedback */
$form.find('[type=submit]').html('Processing <i class="fa fa-spinner fa-pulse"></i>');
/* Hide Stripe errors on the form */
$form.find('.payment-errors').closest('.row').hide();
$form.find('.payment-errors').text("");
// response contains id and card, which contains additional card details
console.log(response.id);
console.log(response.card);
var token = response.id;
var email = $form.find('[name=email]').val();
var formToken = $form.find('[name=_token]').val();
console.log(email);
// AJAX - you would send 'token' to your server here.
console.log(token);
$.post('/testing', {
_token: formToken,
token: token,
email: email
}, function (data) {
console.log(data);
})
// Assign handlers immediately after making the request,
.done(function (data, textStatus, jqXHR) {
//console.log(data);
$form.find('[type=submit]').html('Subscription Successful <i class="fa fa-check"></i>').prop('disabled', true);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$form.find('[type=submit]').html('There was a problem').removeClass('success').addClass('error');
/* Show Stripe errors on the form */
$form.find('.payment-errors').text('Try refreshing the page and trying again.');
$form.find('.payment-errors').closest('.row').show();
});
}
});
if(response.error)永远不会触发,即使该卡应该被拒绝 . 我无法理解我在这里做错了导致这个问题 .
我已经尝试了所有应该从Stripe文档中删除的测试卡号,但是没有一个返回有错误的响应 .
请帮帮我 . 感谢您的时间 .
1 回答
当您使用Stripe.js时,Stripe将仅验证卡详细信息是否正确,并且此时他们不会联系银行 . 这意味着它们确保卡号通过Luhn Check,到期日期是将来的有效日期,并且CVC是3位数(或Amex的4位数) .
就是这种情况,令牌
tok_XXX
已成功创建,您可以将其发送到您的服务器 . 当您添加尝试为其充电时,该卡将在服务器端被拒绝 . 当您创建客户时,它也会被拒绝,因为Stripe将在卡上运行$ 0或$ 1授权以确保其有效并被银行接受 .