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']);


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?

1 Answer 1


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 :

    $quoteId = $order->getQuoteId();
    /** @var \Magento\Quote\Model\Quote $quote */
    $quote = $this->quoteRepository->get($quoteId);
    $resultPage = $this->pageFactory->create();

Another usefull code is from Mage Authorizenet module module located here :


The Magento core function is replaceQuote :


 * @param Quote $quote
 * @return $this
public function replaceQuote($quote)
    $this->_quote = $quote;
    return $this;

You can check also the \Magento\Checkout\Model\Session::restoreQuote function

  • Yeah that restores the last active quote. But it only has the email address in my case. It does not have the shipping information etc. Basically we want all of that stuff pre-populated as it was before the failed attempt so the user can just select a different payment method and continue. I will look at the modules you showed.
    – tread
    Apr 6, 2017 at 15:27
  • Did you check that the information is correct on database ? The sipping information is set up ? You can check that window.checkoutConfig.paymentMethods is not empty Apr 6, 2017 at 15:29
  • Yes it is in the db
    – tread
    Apr 7, 2017 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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