Shop redirect after cancelling
I've built simple checkout process which works perfectly unless a user cancels from PayPal. After this, the checkout flow is broken as any attempt to go back through the checkout results in a redirect back to the defined cancel page.
Checkout page
<?php
if (perch_member_logged_in() && perch_shop_addresses_set() && perch_shop_cart_has_property('terms_agreed')) {
// your 'success' return URL
$return_url = 'https://www.linziboyd.com/bob-school/payment-result';
$cancel_url = 'https://www.linziboyd.com/bob-school/events';
perch_shop_checkout('paypal-express', [
'return_url' => $return_url,
'cancel_url' => $cancel_url
]);
}
perch_layout('global/header', [
'body-class' => 'home',
]);
if (perch_member_logged_in() && perch_shop_addresses_set()) {
PerchSystem::set_var('customerEmail', perch_member_get('email'));
// Confirm back the order
?>
<div class="container-fluid first-chapter">
<div class="container">
<h2>Confirmation</h2>
</div>
</div>
<div class="container padding-top default">
<div class="row">
<div class="col-sm-12">
<p>Please confim that you agree with the terms and conditions and click <strong>Pay Now</strong> to be taken to our payment gateway.</p>
</div>
</div>
<div class="row">
<div class="col-sm-7">
<?php
perch_shop_cart([
'template'=>'cart/cart_static.html'
]);
?>
</div>
<div class="col-sm-5">
<?php perch_shop_order_addresses(); ?>
</div>
</div>
<?php
perch_shop_form('checkout/confirm.html');
?>
</div>
<?php
} else {
perch_shop_registration_form(['template' => 'checkout/customer_create_passwordless.html']);
}
perch_layout('global/footer');
I wonder if I am missing doing something when the order is cancelled?
The step before this page is just a shopping cart and this still displays and functions as expected.
What are you doing on the cancellation page?
Nothing at the moment. It just redirects back to the list of products.
Is it a logic issue on your pages - are your early process pages not expecting values that are already set?
The checkout process only really uses two pages. There is no registration, details are collected via a password registration form. Nothing requires delivery (It's a booking on an event) so only a single address is required for billing.
Products are displayed on the events page (which is also the cancel URL page)
The cart page is as follows...
Everything else is handled via the checkout page above. So, yes, I think everything is already set so `perch_shop_checkout()' is getting called but it does not take you to PayPal it goes straight to the cancel page.
Perhaps my questions should be, how can I redisplay the final confirmation (e.g. reset the terms agreed to false maybe?) and will this actually solve the problem?
So everything works on the first pass, but fails on the second?
That's right. If you pay, you get to the payment result, the cart is emptied and everything is fine. I have only been able to recreate this problem when cancelling from PayPal.
For testing purposes - if you clear the cart on the cancelation page, does that help?
I created a simple page that clears the cart and redirects back to the events page...
What happens now is that the I can go back through the checkout process, addresses have to be re-entered and I have to re-check the terms and conditions box but I still get redirected.
This also happened in a different browser that I had not used with this site before.
I don't follow. Did you empty the cart on your cancellation page? What's this redirect?
Are you now saying that checkout doesn't work at all, ever?
Thanks for the continued help.
It would appear that the checkout is not working at all now. I tried a different browser and a different email address and a new email address but instead of getting taken to PayPal, it just redirects me through the cancel page (which just empties the cart and redirects) back to my product listing (the events page).
Looking at the network traffic, at the point the system should take you to PayPal, the checkout page shows a status 302.
Is there anything else I can provide?
I've also just noticed that there are 8,703 rows in the
perch_shop_cart
table. Actually this is rising all the time and most of the entries are the same. Most data is null or zero, no cart properties, no addresses.8,709 rows after writing the above.
In order to store the cart we need to add it to the database. If we didn't store the cart the data wouldn't persist from page to page.
Understand that. I just thought it was a little odd that there were so many entries in the cart table for a small site. It's up to 8,835 now. Is this the magnitude of entries that you would expect on small site?
perch_shop_cart_data
has 23 rows,perch_shop_cart_items
has 18 rows.I'm stuck with this redirect? Can you suggest anything else I can do to diagnose the problem?
It's nothing to do with the size of the site - it's the number of carts being created.
My apologies, Perhaps I dragged us off topic looking at that.
I'm still stuck with this redirect? Can you suggest anything else I can do to diagnose the problem?
Are you always testing with the same account?
No I've tried different accounts, a different device and account as well as different browsers.
Have you checked to see the failure reason?
Where would I check this?
Do you mean with PayPal? PalPal is never reached (as far as I can tell from sniffing the network traffic). There is just the strange redirect to whatever page is set as the cancel_url.
I can't see anything in the Perch back end that indicates an order was attempted and failed.
Add this before your call to
perch_shop_checkout()
and make sure debug is on.