2

I've got an issue when cards are declined and only a white screen is shown to the user without any feedback. The url has not changed at all either.

This is happening on the live Stripe account so I set up a dev site and used the test account and saw the same when using the 4000000000000002 card number, devMode is enabled but no errors were returned.

Here are the relevant bits of my JS code which handle the creating of the card token and showing any errors encountered:

function stripeResponseHandler(status, response) {
    // Grab the form:
    var $form = $('#payment-information');
    if (response.error) { // Problem!
        if ($('#stripeToken').length) {
            $('#stripeToken').remove();
        }
        // Show the errors on the form
        $('#payment-information').find('.payment-errors').show().find("p").text(response.error.message);
        return false;
    } else { // Token was created!
        // Get the token ID:
        var token = response.id;
        // Insert the token into the form so it gets submitted to the server:
        if ($('#stripeToken').length) {
            $('#stripeToken').val(token);
        } else {
            $('#payment-information').append($('<input type="hidden" id="stripeToken" />').val(token));
        }
        $('#payment-information').find('.payment-errors').hide();
        $("#payment-information").submit();
        return true;
    }
}

Stripe.card.createToken({
    name: $('input[name="firstName"]').val()+" "+$('input[name="lastName"]').val(),
    number: $('#payment-card-number').val(),
    cvc: $('#payment-cvt-code').val(),
    exp_month: $('select[name="month"]').val(),
    exp_year: $('select[name="year"]').val(),
    address_zip: $('#shippingAddress-zipCode').val() 
}, stripeResponseHandler);

Payments are going through fine on the live site and errors such as invalid card numbers are being shown correctly. However, 4000000000000002 is a valid card number and therefore the token is being created successfully without any errors. This is what is happening on the live site when payments are being declined for customers.

When this is then submitted through the commerce/cartPayment/pay form, no errors are shown, just a white page. Has anyone else encountered this and found a way around it? Thanks.

5
  • Stripe is telling me the card number was declined (in test mode) when trying to reproduce: jmp.sh/ZNij6tc Commented Jun 19, 2017 at 12:34
  • Thanks for your attempt at reproducing this Luke. I'm not using the modal popup. I'm not sure why an error wouldn't be returned within my code on checking the same card number. Surely the response.error condition should return as true at this point and show our message. Here is an example of what I am seeing when an error is returned, and then what happens when a payment declines without an error. recordit.co/BNLxooClUL Commented Jun 19, 2017 at 13:09
  • Luke, I managed to find this thread on stripe: github.com/stripe/stripe-python/issues/103 The gist of it seems to be that Stripe.card.createToken() doesn't raise cardError exceptions. Could the commerce plugin return an error to the template if this happens? I noticed in the console window though that the dev output shows a flash notice is set, but the page is just a white screen. Could we have it returned to the template in an errors array possibly? I'm guessing that at this point commerce is returning false and as a result, doesn't render the template. recordit.co/0IlguRSBSK Commented Jun 19, 2017 at 15:06
  • I implemented Stripe.js, you are correct the token was returned without errors in javascript, but Craft Commerce still returned to the same page and added the flash message error. jmp.sh/0NsjfdG Commented Jun 22, 2017 at 3:45
  • Thank you for your feedback Luke. I'm still seeing a blank white page on this end. I've managed to get around it though with a simple plugin which I will post as the answer. Commented Jun 23, 2017 at 10:45

1 Answer 1

1

Couldn't get past the white page issue so I made a simple plugin which does the following:

craft()->on('commerce_transactions.onSaveTransaction', function($event) {
    $transaction = $event->params["transaction"];
    if ($transaction->status == "failed") {
        $message = $transaction->response["error"]["message"];
        craft()->userSession->setNotice($message);
        craft()->request->redirect('/order');
    }
});

Thank you for your help Luke Holder. Strange that I couldn't get rid of the white page but at least we found a solution in the end to stop the issue on the live site whilst customers are making payments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.