Forum
Testing shop+stripe: nothing happens after payment submit
I'm testing Shop with Stripe in test mode (on localhost) and when you submit the card details in the Stripe modal box the green tick appears then the page (confirm.php) reloads with just the header visible and rest of the page blank. The order is not registered and there is no redirect to either success or failure pages.
confirm.php (the cart):
<?php
include($_SERVER['DOCUMENT_ROOT'].'/admin/runtime.php');
perch_layout('header', array(
'title' => "Confirm your order",
));
if (perch_member_logged_in() && perch_post('stripeToken')) {
// 'success' and 'failure' URLs
$return_url = '/pay/success';
$cancel_url = '/pay/cancelled';
perch_shop_checkout('stripe', [
'return_url' => $return_url,
'cancel_url' => $cancel_url,
'token' => perch_post('stripeToken')
]);
}
?>
<div class="clear">
<div class="wrap wrap--large">
<h1>Confirm and pay</h1>
</div>
</div>
<div class="clear">
<div class="wrap wrap--small">
<?php perch_content('Intro text'); ?>
<?php
// Show the cart
perch_shop_cart([
'template'=>'cart/cart.html'
]);
// Show the order addresses
perch_shop_order_addresses();
// Show the payment form if logged in and something in cart
if (perch_member_logged_in() && perch_shop_cart_item_count([], true) > 0) {
perch_shop_payment_form('stripe');
}
?>
</div>
</div>
<div class="clear">
<div class="wrap wrap--small">
<?php perch_content('Shop footer'); ?>
</div>
</div>
<?php perch_layout('footer');?>
config/shop.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Gateway settings
|--------------------------------------------------------------------------
*/
'gateways' => [
'default' => [
'enabled' => false,
'test_mode' => false,
'live' => [
'api_key' => 'abc123',
],
'test' => [
'api_key' => 'abc123',
],
],
'stripe' => [
'enabled' => true,
'test_mode' => true,
'live' => [
'secret_key' => 'mylivekeyishere',
'publishable_key' => 'mylivekeyishere',
],
'test' => [
'secret_key' => 'mytestkeyishere',
'publishable_key' => 'mytestkeyishere',
],
],
],
];
stripe_payment_form.html:
<a href="logout" style="float: right;">Cancel order</a>
<form action="" method="post">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="<perch:shop id="publishable_key" escape="true" />"
data-amount="<perch:shop id="amount" escape="true" />"
data-currency="<perch:shop id="currency" escape="true" />"
data-name="My Shop"
data-description="Items (<perch:shop id="amount_formatted" escape="true" />)"
data-email="<perch:member id="email" escape="true" />">
</script>
</form>
If you are getting a blank or cut off page then you have a PHP error, what is the actual error?
Also, remember we need to see your Diagnostics Report in order to help.
No error appears, it just seems to reload the page with the header (which is a perch layout file) and nothing else. I've got debug on the page but lower down in the code so it doesn't get loaded.
You will need to look in your error log as usual for the error.
Hi Rachel. I got the following:
Can you try the current version of Shop?
I updated Shop and same issue but this time just get one warning:
Make sure you're not outputting anything to the page before you try to redirect to payment.
I don't know why but I can't access any of my site on localhost this morning due to this error:
Throwing this into the mix incase it somehow helps:
It looks like you're storing your website files in a Google Drive synced folder - it might be worth trying all this stuff in a folder that isn't being synced - it could be causing the issues you're seeing with files missing and what-not.
Not a guaranteed solution, but worth a go.
Thanks Duncan yes I had considered that.
I fixed the fatal error warning by reinstalling Shop anyway. I'm now going to try the checkout process again and report back.
Ok after entering the test card details this time and submitting I get a redirect to my failed URL. How can I get more information about why the transaction failed? The order did not appear in Perch admin or Stripe so I'm wondering how I can investigate?
Update: just found the Stripe Logs area which I hadn't seen before. I'm getting:
Does this mean I can't test on localhost?
No, you'll just need to update your local server.