How do you maintain checkout data and state after a failed payment in Magento 2? Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Magento2 - Modify Checkout pageGetting strange result querying carts when using multiple search filter groupsThe requested Payment Method is not available When creating an orderMagento 2 - Change the order of the Shipping fields on the Checkout pageMagento 2: Update Billing Address info fieldsHow to return a JSON object with a custom REST API in Magento 2?Address Information And Customer address are not showing in magento 2Magento 2 wrong paypal express checkout token specifiedMagento 2: Payment Method Not Capturing Shipping Address From Payment PageAddress format checkout page issue in Magento 2.2.3

Array/tabular for long multiplication

Why does tar appear to skip file contents when output file is /dev/null?

Writing Thesis: Copying from published papers

If A makes B more likely then B makes A more likely"

How should I respond to a player wanting to catch a sword between their hands?

Need a suitable toxic chemical for a murder plot in my novel

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

Notation for two qubit composite product state

When is phishing education going too far?

What would be Julian Assange's expected punishment, on the current English criminal law?

Problem when applying foreach loop

How can I protect witches in combat who wear limited clothing?

Can I throw a sword that doesn't have the Thrown property at someone?

How did the aliens keep their waters separated?

When communicating altitude with a '9' in it, should it be pronounced "nine hundred" or "niner hundred"?

Single author papers against my advisor's will?

Can the prologue be the backstory of your main character?

Limit for e and 1/e

Do working physicists consider Newtonian mechanics to be "falsified"?

Stars Make Stars

I'm having difficulty getting my players to do stuff in a sandbox campaign

Fishing simulator

Autumning in love

Stop battery usage [Ubuntu 18]



How do you maintain checkout data and state after a failed payment in Magento 2?



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Magento2 - Modify Checkout pageGetting strange result querying carts when using multiple search filter groupsThe requested Payment Method is not available When creating an orderMagento 2 - Change the order of the Shipping fields on the Checkout pageMagento 2: Update Billing Address info fieldsHow to return a JSON object with a custom REST API in Magento 2?Address Information And Customer address are not showing in magento 2Magento 2 wrong paypal express checkout token specifiedMagento 2: Payment Method Not Capturing Shipping Address From Payment PageAddress format checkout page issue in Magento 2.2.3



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















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?










share|improve this question














bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.





















    1















    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?










    share|improve this question














    bumped to the homepage by Community 9 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      1












      1








      1








      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?










      share|improve this question














      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?







      magento2 checkout payment






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 6 '17 at 15:01









      Stevie GStevie G

      345726




      345726





      bumped to the homepage by Community 9 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 9 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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 :



           $this->checkoutSession->setPaymentRetryFlow(true);
          $this->checkoutSession->setOrderOnRetry($order->getIncrementId());
          $quoteId = $order->getQuoteId();
          /** @var MagentoQuoteModelQuote $quote */
          $quote = $this->quoteRepository->get($quoteId);
          $this->checkoutSession->replaceQuote($quote);
          $resultPage = $this->pageFactory->create();


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



          vendor/magento/module-authorizenet/Controller/Directpost/Payment.php:140


          The Magento core function is replaceQuote :



          vendor/magento/module-checkout/Model/Session.php:458

          /**
          * @param Quote $quote
          * @return $this
          */
          public function replaceQuote($quote)

          $this->_quote = $quote;
          $this->setQuoteId($quote->getId());
          return $this;



          You can check also the MagentoCheckoutModelSession::restoreQuote function






          share|improve this answer

























          • 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.

            – Stevie G
            Apr 6 '17 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

            – Franck Garnier
            Apr 6 '17 at 15:29












          • Yes it is in the db

            – Stevie G
            Apr 7 '17 at 7:43











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f168010%2fhow-do-you-maintain-checkout-data-and-state-after-a-failed-payment-in-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          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 :



           $this->checkoutSession->setPaymentRetryFlow(true);
          $this->checkoutSession->setOrderOnRetry($order->getIncrementId());
          $quoteId = $order->getQuoteId();
          /** @var MagentoQuoteModelQuote $quote */
          $quote = $this->quoteRepository->get($quoteId);
          $this->checkoutSession->replaceQuote($quote);
          $resultPage = $this->pageFactory->create();


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



          vendor/magento/module-authorizenet/Controller/Directpost/Payment.php:140


          The Magento core function is replaceQuote :



          vendor/magento/module-checkout/Model/Session.php:458

          /**
          * @param Quote $quote
          * @return $this
          */
          public function replaceQuote($quote)

          $this->_quote = $quote;
          $this->setQuoteId($quote->getId());
          return $this;



          You can check also the MagentoCheckoutModelSession::restoreQuote function






          share|improve this answer

























          • 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.

            – Stevie G
            Apr 6 '17 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

            – Franck Garnier
            Apr 6 '17 at 15:29












          • Yes it is in the db

            – Stevie G
            Apr 7 '17 at 7:43















          0














          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 :



           $this->checkoutSession->setPaymentRetryFlow(true);
          $this->checkoutSession->setOrderOnRetry($order->getIncrementId());
          $quoteId = $order->getQuoteId();
          /** @var MagentoQuoteModelQuote $quote */
          $quote = $this->quoteRepository->get($quoteId);
          $this->checkoutSession->replaceQuote($quote);
          $resultPage = $this->pageFactory->create();


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



          vendor/magento/module-authorizenet/Controller/Directpost/Payment.php:140


          The Magento core function is replaceQuote :



          vendor/magento/module-checkout/Model/Session.php:458

          /**
          * @param Quote $quote
          * @return $this
          */
          public function replaceQuote($quote)

          $this->_quote = $quote;
          $this->setQuoteId($quote->getId());
          return $this;



          You can check also the MagentoCheckoutModelSession::restoreQuote function






          share|improve this answer

























          • 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.

            – Stevie G
            Apr 6 '17 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

            – Franck Garnier
            Apr 6 '17 at 15:29












          • Yes it is in the db

            – Stevie G
            Apr 7 '17 at 7:43













          0












          0








          0







          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 :



           $this->checkoutSession->setPaymentRetryFlow(true);
          $this->checkoutSession->setOrderOnRetry($order->getIncrementId());
          $quoteId = $order->getQuoteId();
          /** @var MagentoQuoteModelQuote $quote */
          $quote = $this->quoteRepository->get($quoteId);
          $this->checkoutSession->replaceQuote($quote);
          $resultPage = $this->pageFactory->create();


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



          vendor/magento/module-authorizenet/Controller/Directpost/Payment.php:140


          The Magento core function is replaceQuote :



          vendor/magento/module-checkout/Model/Session.php:458

          /**
          * @param Quote $quote
          * @return $this
          */
          public function replaceQuote($quote)

          $this->_quote = $quote;
          $this->setQuoteId($quote->getId());
          return $this;



          You can check also the MagentoCheckoutModelSession::restoreQuote function






          share|improve this 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 :



           $this->checkoutSession->setPaymentRetryFlow(true);
          $this->checkoutSession->setOrderOnRetry($order->getIncrementId());
          $quoteId = $order->getQuoteId();
          /** @var MagentoQuoteModelQuote $quote */
          $quote = $this->quoteRepository->get($quoteId);
          $this->checkoutSession->replaceQuote($quote);
          $resultPage = $this->pageFactory->create();


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



          vendor/magento/module-authorizenet/Controller/Directpost/Payment.php:140


          The Magento core function is replaceQuote :



          vendor/magento/module-checkout/Model/Session.php:458

          /**
          * @param Quote $quote
          * @return $this
          */
          public function replaceQuote($quote)

          $this->_quote = $quote;
          $this->setQuoteId($quote->getId());
          return $this;



          You can check also the MagentoCheckoutModelSession::restoreQuote function







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 6 '17 at 15:24

























          answered Apr 6 '17 at 15:18









          Franck GarnierFranck Garnier

          2,096926




          2,096926












          • 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.

            – Stevie G
            Apr 6 '17 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

            – Franck Garnier
            Apr 6 '17 at 15:29












          • Yes it is in the db

            – Stevie G
            Apr 7 '17 at 7:43

















          • 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.

            – Stevie G
            Apr 6 '17 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

            – Franck Garnier
            Apr 6 '17 at 15:29












          • Yes it is in the db

            – Stevie G
            Apr 7 '17 at 7:43
















          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.

          – Stevie G
          Apr 6 '17 at 15:27





          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.

          – Stevie G
          Apr 6 '17 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

          – Franck Garnier
          Apr 6 '17 at 15:29






          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

          – Franck Garnier
          Apr 6 '17 at 15:29














          Yes it is in the db

          – Stevie G
          Apr 7 '17 at 7:43





          Yes it is in the db

          – Stevie G
          Apr 7 '17 at 7:43

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f168010%2fhow-do-you-maintain-checkout-data-and-state-after-a-failed-payment-in-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Jet Time Laivasto | Lähteet | Aiheesta muualla | NavigointivalikkoJet Time - The CompanyThe CompanyManagementJet Time aloittaa lauantaina Suomi-rekisterissä olevalla Boeing 737 -koneellaJettime Finland Fleet Details and HistoryJettime Fleet Details and HistoryRegional Jet OÜ takes over ATR production for SASJet Time Returns To Its Core BusinessYhtiön kotisivutlaajentamalla

          Olympian arkeologinen museo Sisällysluettelo Historia ja rakennus | Kokoelmat | Lähteet | Aiheesta muualla | Navigointivalikko37°38′36″N, 21°37′46″EInfobox OKArchaeological Museum of Olympia: HistoryArchaeological Museum of Olympia: DescriptionΜουσείο Ιστορίας των Ολυμπιακών Αγώνων της Αρχαιότητας: ΙστορικόArchaeological Museum of Olympia

          Äpy Sisällysluettelo Äpyt kautta historian | Esimerkkejä Äpy-huumorista | Katso myös | Kirjallisuutta | Aiheesta muualla | Navigointivalikkowww.äpy.fi