3

I had a custom payment module that was working properly on 2.2.x as well as 2.3.x. However, when I tried to install it onto a clean 2.4.2 instance, I found that the function getLastSuccessQuoteId() called on the checkout session always gave me a null result.

The payment gateway I implemented is more or less like the PayPal Hosted Solution, where the customers would be redirected to a 3rd party platform for the settlement, and redirected back to the shop afterward via a return URL.

On 2.2.x and 2.3.x, I was able to get the previous success quote ID by calling getLastSuccessQuoteId() in this return URL, but now it gave me nothing.

I am not sure which part of the new Magento was contributing to the difference here. I have tried the following directions:

  • add the CSP whitelist
  • switch on the CSP report-only mode in the config.xml
  • disable the CSP module
  • implement those new CsrfAwareActionInterface, HttpPostActionInterface, HttpGetActionInterface for the return action controller

In the end, I have even tried to rewrite the module completely based on the PayPal Hosted solution, but I am still getting the same result.

I really have no clue what I could have missed out on.

5
  • have you found the solution yet ? I am facing the same issue on Magento 2.4.2
    – Dhimant
    Jul 22, 2021 at 1:37
  • @Dhimant you may want to check if that is caused by the SameSite cookie policy
    – d.yuk
    Jul 22, 2021 at 2:19
  • The module I am using has a little different architecture, before redirecting customer to payment gateway it loads a block, and based on the values stored in order it redirects customers to the the payment gateway, also SAMESITE cookie was set to LAX, now it's blank, I tried to apply none, but for some reason it is still blank, also I am able to fetch the values sometimes and process payments but sometimes , it is blank.
    – Dhimant
    Jul 22, 2021 at 4:59
  • @d.yuk did you manage to find a solution? I am facing the same problem with getLastSuccessQuoteId() return null and I can't load the order to complete the redirect in my controller Aug 9, 2021 at 8:53
  • @MiroslavPetroff My problem was caused by the SameSite cookie policy issue. So you might want to check if you are having the same problem there
    – d.yuk
    Aug 9, 2021 at 10:42

1 Answer 1

1

I had a simmilar problem some time ago.

I havent found the perfect solution yet but for now I have implemented a solution which solve the issue partialy.

When the payment method returns to custom Magento Controller, I load the order and add it to the checkout session and redirect him to the succes page. The good thing is that the customer redirects to the succes page, the bad thing is that, if the customer was logged in he logges out.

$this->_checkoutSession
->setLastOrderId($order->getId())
->setLastRealOrderId($order->getIncrementId())
->setLastOrderStatus($order->getStatus());
$this->_checkoutSession->setLastQuoteId($order->getQuoteId());
$this->_checkoutSession->setLastSuccessQuoteId($order->getQuoteId());

There is a big discustion regarding this issue and it has many different solution of each kind of problem.

Here is the discution https://github.com/magento/magento2/issues/26377, depending on what kind of problem you got, it mentions some solutions.

This looks promising but only for apache, for nginx there must be something simmilar.

<If "%{HTTP_USER_AGENT} =~ /(iPhone; CPU iPhone OS 1[0-2]|iPad; CPU OS 1[0-2]|iPod touch; CPU iPhone OS 1[0-2]|Macintosh; Intel Mac OS X.*Version\x2F1[0-2].*Safari|Macintosh;.*Mac OS X 10_14.* AppleWebKit.*Version\x2F1[0-3].*Safari|(Chrom[^ \x2F]+\x2F(([4-5][0-9])|([6][0-7]))[\.\d]*[ ]))/i">
  Header always edit Set-Cookie "^(.*)(;[ ]?SameSite=None|;[ ]?samesite=None)(.*)?$" "$1$3"
</If>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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