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

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

<p>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.</p>

CC BY-SA 3.0
2017-06-23T10:48:54.540Z
2017-06-23T10:48:54.540Z
Matt Shearing
<p>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.</p>

<p>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.</p>

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

<pre><code>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($('&lt;input type="hidden" id="stripeToken" /&gt;').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);
</code></pre>

<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2017-06-19T12:34:29.693Z
Stripe is telling me the card number was declined (in test mode) when trying to reproduce: http://jmp.sh/ZNij6tc
Luke Holder
CC BY-SA 3.0
2017-06-19T13:09:50.270Z
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. http://recordit.co/BNLxooClUL
Matt Shearing
CC BY-SA 3.0
2017-06-19T15:06:18.670Z
Luke, I managed to find this thread on stripe: https://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. http://recordit.co/0IlguRSBSK
Matt Shearing
CC BY-SA 3.0
2017-06-22T03:45:23.277Z
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. http://jmp.sh/0NsjfdG
Luke Holder
CC BY-SA 3.0
2017-06-23T10:45:28.500Z
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.
Matt Shearing
<plugin-craftcommerce><stripe><payment><white-screen>
Commerce Stripe Card Declined shows white screen with no error
# Commerce Stripe Card Declined shows white screen with no error

(Asked by: username_0 on 2017-06-19)

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($('').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.

**Tags:** plugin-craftcommerce, stripe, payment, white-screen
> **Comments:**
> **username_1**: Stripe is telling me the card number was declined (in test mode) when trying to reproduce: http://jmp.sh/ZNij6tc  
> **username_0**: 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. http://recordit.co/BNLxooClUL  
> **username_0**: Luke, I managed to find this thread on stripe: https://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. http://recordit.co/0IlguRSBSK  
> **username_1**: 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. http://jmp.sh/0NsjfdG  
> **username_0**: 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.  

---

## 1 answers

### Answer by username_0 on 2017-06-23. Score: 1 | Accepted answer

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.


---

