Stripe 在测试模式下不会拒绝任何卡片

Stripe is not declining any cards in test mode

我将 Stripe 与 Laravel 5.1 一起使用,并且一切正常,除了当我输入应该被拒绝的测试卡号时,我没有收到任何错误;也就是说,resonse.errors 永远不存在,即使它应该存在。

我收到了一个令牌,好像一切顺利(示例:tok_16Y3wFAMxhd2ngVpHnky8VWX)

无论我使用什么测试卡,stripeResponseHandler() 函数都不会 returning 响应中的错误。这是有问题的代码:

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 文档中拒绝的测试卡号,但是 none 其中 return 有错误的响应。

请帮帮我。谢谢你的时间。

当您使用 Stripe.js, Stripe will only verify that the card details look correct and they don't contact the bank at that point. This means that they ensure the card number passes the Luhn Check 时,到期日期是未来的有效日期,并且 CVC 是 3 位数字(或 4 位美国运通卡)号码。

这样,令牌tok_XXX创建成功,您可以将其发送到您的服务器。当您添加尝试对其收费时,该卡将在服务器端被拒绝。当您创建客户时,它也会被拒绝,因为 Stripe 将 运行 在卡上进行 0 美元或 1 美元的授权,以确保它有效并被银行接受。