Jump to content

Payment Gateway - Cart not Emptied upon Closed Window


Guillaume

Recommended Posts

Hi,

This is a continuation of this topic:

So I have developped a payment module, which has a gateway.class.php file with a call() function in it.

This time, my call() function is called, I know it as I log transaction notes, and they are exactly reported as instructed in such function. However, on the payment gateway:

  1. If I let the payment page go through and come back to the store URL, the order is indeed registered and the cart is emptied
  2. If I close the window after the payment is accepted, although the order is registered, the cart is not emptied

What puzzles me is that the transaction logs are filled in as instructed in the call() function, and right below this instruction which I know is processed, I have put a:

            $GLOBALS['cart']->clear();

But in case 2, the cart is never emptied. And to be very honest, even commenting the above instruction e,ptying the cart, in case 1 the cart is emptied nevertheless.

Any hint on how I could make sure the cart is emptied?

Best regards,

Guillaume

 

gateway.class.php

Link to comment
Share on other sites

The Cart->clear() function also includes a SQL query to delete all records in CubeCart_saved_cart for the logged in customer.

When a logged-in customer does return to CubeCart, one of the things CubeCart does is to check and see if there is a record for this customer in CubeCart_saved_cart, and if there is, reloads the Cart with those contents.

When the gateway class sends CubeCart to ?_a=complete, there is a Cart->clear() command there, as well.

It is very likely the case that when the customer does not return to CubeCart directly, CubeCart does not know what the customer_id is supposed to be.

If you really want to delete all records for this customer from CubeCart_saved_cart (assuming this is where the conundrum is happening) without requiring the customer to actually return to CubeCart, relying solely on the IPN callback, you can execute your own SQL query to do what Cart-clear() cannot do.

$GLOBALS['db']->delete('CubeCart_saved_cart', array('customer_id' => $order_summary['customer_id']));
$GLOBALS['cart']->clear();

Please experiment carefully. I have not done this myself.

Link to comment
Share on other sites

Hi,

Thanks a lot for this detailed answer. The way I understand it is, that whenever a customer comes back to Cubecart, Cubecart will try to retrieve from the database their basket. This would explain that merely deleting the cart from the session (with the below) does not work, because Cubecart would subsequently retrieve the cart from the DB and put it back in session:

$GLOBALS['session']->clear();
$GLOBALS['session']->delete('basket');

Now I've tried the below, which you suggested, but for some reason it does not work:

$GLOBALS['db']->delete('CubeCart_saved_cart', array('customer_id' => $order_summary['customer_id']));
$GLOBALS['cart']->clear();

I've checked and the instruction seems corect, as in the logs the customer_id is correctly filled in, both for the cart and the order_summary.

What also puzzles me is that I have the below instruction (where redirection is towards the index.php?_a=complete page) in my code:

httpredir($redirection, '', true, 200, true);

Where you mentioned a cart clearance is conducted. That works perfectly when I don't close the window. But for some reason it deosn't when the window is closed.

I guess my next step is to read the database and make sure the instruction in database is correctly executed.

Guillaume

 

 

 

 

 

 

Link to comment
Share on other sites

Hi,

Thanks a lot for your feedback - really appreciate your help. I was trying so far with Firefox, and don't think I have any such add-on. I tried with Chrome (where I have no add-on for sure), same result. I am not really sure what to do next: how are IPN usually managed in the case the user closes the window? I'm afraid I can't really test to that extent on other gateways, as I would need a test key to get the payment through.

What really puzzles me is that the IPN seems to be taken into consideratio, as the function call() is used indeed (I can see that as it logs the transaction). But solely when it comes to emptying the cart that fails. Could there be anything wrong with the cart emptying command we've defined?

Cheers,

Guillaume

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

Would really appreciate any insight anyone may have here. Is there any way to clearly rule out, from Cubecart's perspective, whether the cookies are deleted? E.g. can I look for a cookies log in Cubecart?

What I am not getting in the first response is "CubeCart does not know what the customer_id is supposed to be". I believe it does, because the customer is still logged, and his cart is still present (besides the order being recorded in his account).

I am rather under the impression that when the ?_a=complete is called, for some reason the cart is not emptied, possibly because it is called incorrectly. However, I am not sure how to verify that...

Any hint very appreciated. Best regards,

Guillaume

Link to comment
Share on other sites

  • 3 weeks later...

Sure:

  • A first (Beta) version of the "Pay by Instalments" version was uploaded and published to Cubecart on 3rd June 2021 - under the name Systempay - downloaded 86 times so far
  • A second version of the above was just published yesterday. For IP reasons, I had to rename it "Paiement CB France par Améo - Paiement en plusieurs fois"
  • A similar version for straight payment (not by instalments) was also published yesterday. It is named "Paiement CB France par Améo"

In the next version I'd like to male a couple of improvements and solve a couple of bugs, included the one mentioned here. Note that I have been in touch with Lyra (which owes all the payment gateways accessible through this module) to have the module officially referenced on their website. The certification process on their side is ongoing.

Link to comment
Share on other sites

  • 3 months later...

Hi,

Apologises for coming back on this topic. I still did not manage to correctly implement the IPN on this payement gateway. The obvious consequence is that, if after clicking pay, the customer closes the window, then the cart is not emptied.

There might be something I do wrong in processing the payment system provider's response, but I wonder whether in Cubecart, there is a dedicated URL to be called for offline payment notifications? Or is it the same as online payment notifications, i.e. $STOREURL."index.php?_a=complete" in case of success?

Best regards,

Guillaume

Link to comment
Share on other sites

  • 1 month later...

I actually have the IPN working fine (and my call function is called indeed). So the problem seems to be only limited to the instruction actually emptying the cart offline. I have made several attemps:

Quote
$GLOBALS['db']->delete('CubeCart_saved_cart', array('customer_id' => $order_summary['customer_id']));
$GLOBALS['cart']->clear();

(which you suggested)

I then checked the logs and finding that I was logged under 'customer_id '= 1, tried the following:

Quote

$GLOBALS['db']->delete('CubeCart_saved_cart', array('customer_id' => 1));

$GLOBALS['cart']->clear();

Also unsuccessful. Then I tried playing with the session, but I believe, as you indicated above, that the session is populated again when coming back to the website, which would explain the below attemp being unsuccessful:

Quote

$GLOBALS['session']->delete('', 'basket');

Any hint would be much appreciated!

Guillaume

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...