4

I would like to be able to allow users to select a certain option on checkout, and then they will be redirected to the bank page where they use their credit info to pay, then redirected back to magento and set order as approved on success or fail if not

I have been messing around with magento's code for a couple of days, I was able to 'hack' through the onepage controller to do the redirect and then come back, but I am not able to change the status of the order to 'approved' from that controller

what I basically did in the controller in the 'saveorder action' is: - check the payment method selected by the user - if it is the one I need, send user to bank page with the amount to be paid - then return back from that page to a php page that checks the status returned, if successful redirects to onepage/success/ , if not, to onepage/failure

it all works nicely BUT how can I change the order state ?

I tried what's in this link, but this only works for an older version of Magento it seems http://blog.chapagain.com.np/magento-how-to-change-order-status-programmatically/

thanks

roy naufal
  • 379
  • 1
  • 8
  • 19
  • By the way - you may find the BlueSnap integration for Magento useful for your needs, you can see the details in this link: https://support.bluesnap.com/docs/magento-2 – Dan Jul 31 '17 at 12:10

3 Answers3

2

Keep in mind that the success page doesn't necessarily change the payment state to approved. This is because different payment methods may approve a payment at different times. For example, Paypal will not approve the payment until it has a chance to process it.

Does your CC company provide callbacks that you can use to update the status? If so, I suggest using the Paypal module as a template for how to handle this (wait for the callback, update the order status). If not, perhaps use a cronjob and their API to check the payment status.

Overall, do not depend on customers visiting a certain page after they have paid, as there are plenty of situations where this will not be the case.

Hope that helps!

Thanks, Joe

Joe Mastey
  • 26,809
  • 13
  • 80
  • 104
  • ah great, thanks for the tip...didn't really consider that yea, it sends back callbacks that I'm currently using I'm very new to mage/zend/magento so I tried messing around with paypal module but had no idea how it worked and couldn't get it to do what I wanted...eventhough I have decent php experience any tips or links that I might be able to use? – roy naufal Apr 23 '11 at 09:02
  • Magento is a bit of a beast if you are new to it. The tutorials on the actual Magento site cover a lot of topics, but it's difficult to point to a single overview of how the entire Paypal order lifecycle occurs. If you have specific code questions, search around the questions that have been answered on this site or post new questions and there are plenty of folks happy to help. – Joe Mastey Apr 23 '11 at 16:56
2

I solved this problem after payment success from paypal. You can change order staus process to downloadable product,

Go to app\code\core\Mage\paypal\controllers\StandardController.php and replace the code after payment send mail success and order status with my code.

public function successAction() 
{ 
    $session = Mage::getSingleton('checkout/session'); 
    $session->setQuoteId($session->getPaypalStandardQuoteId(true)); 
    Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save(); 

    $session->setPaypalStandardQuoteId($session->getQuoteId()); 
    $order = Mage::getModel('sales/order'); 
    $order->load(Mage::getSingleton('checkout/session')->getLastOrderId()); 
    $state = Mage_Sales_Model_Order::STATE_PROCESSING; 
    $order->setState($state); 
    $order->setStatus('processing'); 
    $order->sendNewOrderEmail(); 
    $order->save(); 
    $this->_redirect('checkout/onepage/success', array('_secure'=>true)); 
} 
Thomas Vander Stichele
  • 36,043
  • 14
  • 56
  • 60
BIKASH
  • 21
  • 1
  • 1
    Hi Thomas, this dosen't look like best practice, this code $order->load(Mage::getSingleton('checkout/session')->getLastOrderId()); what if multiple customers have checkout before you return from bank site, this will give a false LastOrderId – Edwin O. Jul 29 '14 at 16:08
1

To change the order state (magento 1.5)

$order->setStatus(Mage_Sales_Model_Order::STATE_COMPLETE);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE);
$order->save();
pderaaij
  • 1,337
  • 12
  • 32
  • ah, I was using this: $order->setStatus('complete'); $order->save(); It was working, but inside the order details in admin, the 'comments history' section still displayed 'processing' , eventhough the order status itself is changed to complete I tried your code, definitely progress,I used to get an error that I cannot change state manually, but now I'm getting this: Please check shipping address information, enter first name, last name, street...etc(all address info) I'm checking out as guest I am loading the order like this: $order = Mage::getModel('sales/order')->load($lastOrderId); – roy naufal Apr 23 '11 at 09:19