We use a payment gateway that goes redirects offsite and then returns to the success or failed controllers.
Once there is a failed payment (and it goes to the payment failed controller) the user is redirected to the shopping cart and the error message is shown.
We want the user to instead be redirected to the payment part of the checkout process. We also want all checkout information such as shipping and billing address and customer email to stay.
So far I am saving the shipping details in a session variable on the Fail controller:
$order = $this->checkoutSession->getLastRealOrder();
if ($order) {
$shipping = $order->getShippingAddress();
if ($shipping) {
$shippingData = $shipping->getData();
$shipAr = array('firstName' => $shippingData['firstname'],
'lastName' => $shippingData['lastname'],
'region' => $shippingData['region'],
'postcode' => $shippingData['postcode'],
'street' => $shippingData['street'],
'city' => $shippingData['city'],
'company' => $shippingData['company'],
'telephone' => $shippingData['telephone'],
'country_id' => $shippingData['country_id'],
'fax' => $shippingData['fax'],
'email' => $shippingData['email']);
$this->checkoutSession->setFailedPaymentShippingInfo($shipAr);
}
}
Then I redirect to the checkout shipping section with:
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('checkout', ['_fragment'=>'payment']);
return $resultRedirect;
On the checkout page I am overriding LayoutProcessor::afterProcess()
and updating the $jsLayout
with the values from the session variable.
It is not working too well. How can I do this?
Best Answer
I do not have the complete answer.
I use Ingenico Magento 2 module, and they integrate a specific page for the payment retry with the orderId as paramater.
Code exemple :
Another usefull code is from Mage Authorizenet module module located here :
The Magento core function is replaceQuote :
You can check also the
\Magento\Checkout\Model\Session::restoreQuote
function