【问题标题】:Stripe is not declining any cards in test modeStripe 在测试模式下不会拒绝任何卡片
【发布时间】:2015-11-01 19:22:30
【问题描述】:

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

我收到了一个令牌,好像一切正​​常(例如: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 文档中拒绝的测试卡号,但它们都没有返回错误响应。

请帮帮我。感谢您的宝贵时间。

【问题讨论】:

  • 那么什么是条带回传?如果响应不包含错误,我们将如何做任何事情?

标签: jquery laravel stripe-payments


【解决方案1】:

当您使用Stripe.js 时,Stripe 只会验证卡的详细信息是否正确,此时他们不会联系银行。这意味着他们确保卡号通过Luhn Check,到期日期是未来的有效日期,并且 CVC 是 3 位数(或 Amex 的 4 位数)号码。

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

【讨论】:

  • 这是我的一个误解。当然,卡片并没有被拒绝,因为 Stripe.js 只是确保数字、到期和日期看起来合法。处理下降的是实际的 Post to stripe。感谢您的回复。
猜你喜欢
  • 2018-01-04
  • 2017-10-12
  • 2017-01-24
  • 2017-09-03
  • 2018-08-30
  • 2021-12-27
  • 2014-08-23
  • 2014-12-31
  • 2021-02-27
相关资源
最近更新 更多