title: How to mark an order failed programmatically - Magento
body: <p>I would just like to know what is that one property which when set would mark the order as failed so that <code>failureAction()</code> of <code>app/code/core/Mage/Checkout/controller/OnepageController.php</code> gets called.</p>
  
  <p>I have an Observer.php where in I'm creating invoice for successful payments and for failed payments saving order with <code>pending_payment</code> status and wanting to redirect them to the cart page with an error message at the top.</p>
  
  <p>All this happens fine. Just that for unsuccessful / failed payments, along with saving the order with pending_payment status n redirecting them to cart page with error message, I would also like to retain/save the cart from getting empty.</p>
  
  <p>But to no luck</p>
  
  <p>Observer.php</p>
  
  <pre><code> public function implementOrderStatus($event)
   {
      $order = $event-&gt;getEvent()-&gt;getOrder(); 
      if ($this-&gt;_getPaymentMethod($order) == 'mypaymentmodule') 
      {
                  $quote = Mage::getModel('sales/quote')-&gt;load($order-&gt;getQuoteId());
          if($order-&gt;getPayment()-&gt;getCcTransId() == NULL)
          {
              $order-&gt;cancel();
              $order-&gt;setStatus('canceled');
              $order-&gt;save();
              $quote-&gt;setIsActive(1)-&gt;save();
              /*$state = 'pending_payment';
              $status = 'pending_payment';
              $comment = 'Payment transaction failed due to incorrect AVS/CVD details.';
              $isNotified = false;
              $order-&gt;setState($state,$status,$comment,$isNotified)-&gt;save();
              $order-&gt;setCanSendNewEmailFlag(false);*/
  
              Mage::getSingleton('checkout/session')-&gt;addError('Sorry, either of your card information (billing address or card validation digits) dint match. Please try again');                 
  
              Mage::app()-&gt;getFrontController()-&gt;getResponse()-&gt;setRedirect('checkout/cart/')-&gt;sendResponse();
          }
         else
         {
             if ($order-&gt;canInvoice())
  
              $this-&gt;_processOrderStatus($order);
         }
      }
      return $this;
  }
  </code></pre>
  
  <p>But <code>$quote-&gt;setIsActive(true)-&gt;save()</code> does not seem to be doing the trick. Any help as to how can I save my cart from getting empty after saving the order with 'canceled' status.</p>