php - Restore magento quote after payment was refused -


i'm creating magento payment extension following:

when user clicks on checkout in merchant site, gets redirected web site (like paypal) inputs payment data. if payment method fails, user gets redirected merchant site.

however, appears quote no more active.

what possibilities make possible end user reuse quote ?

a few possibilities :

  • duplicating quote if user gets back
  • retrieve quote , set active shows again

here of code use in payment model:

to initialize payment method pending_payment

/**  * instantiate state pending_payment  * @param  * @param  */ public function initialize($paymentaction, $stateobject) {     $state = mage_sales_model_order::state_pending_payment;     $stateobject->setstate($state);     $stateobject->setstatus(mage_sales_model_order::state_pending_payment);     $stateobject->setisnotified(false); } 

to redirect payment method (the url redirect remote host)

/**  * checkout redirect url getter onepage checkout  *  * @see mage_checkout_onepagecontroller::savepaymentaction()  * @see mage_sales_model_quote_payment::getorderplaceredirecturl()  * @return string  */  public function getorderplaceredirecturl() {     return mage::geturl('pay/payment/redirect'); } 

in case payment fails, user come @ url /pay/payment/fail (i know how create controller this, problem reactivate quote).

i found out how (many modules : paypal, authorizenet, stripe)

you have first cancel order (using registercancellation method), load quote, setisactive 1 , remove reservedorderid field.

public function cancelaction() {     $session = mage::getsingleton('checkout/session');     if ($session->getlastrealorderid())     {         $order = mage::getmodel('sales/order')->loadbyincrementid($session->getlastrealorderid());         if ($order->getid())         {             //cancel order             if ($order->getstate() != mage_sales_model_order::state_canceled)             {                 $order->registercancellation("canceled payment provider")->save();             }             $quote = mage::getmodel('sales/quote')                 ->load($order->getquoteid());             //return quote             if ($quote->getid())             {                 $quote->setisactive(1)                     ->setreservedorderid(null)                     ->save();                 $session->replacequote($quote);             }              //unset data             $session->unslastrealorderid();         }     }      return $this->getresponse()->setredirect( mage::geturl('checkout/onepage')); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -