Domanda

I'm making a new payment method for Magento 1.9. for now I can make an order and have the invoice correctly. I wane to add the possibility to make credit memos using my payment method, but i can't find the way. This is how i pay the order:

    $order->setState(Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW, true, 'Payment Success.');
    $order->save();

    $transaction = Mage::getModel('core/resource_transaction');
    $transaction->addObject($order);
    $transaction->addCommitCallback(array($order, 'place'));
    $transaction->addCommitCallback(array($order, 'save'));
    $transaction->save();

    $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
    $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
    $invoice->register();
    $invoice->getOrder()->setIsInProcess(true);
    $transactionSave = Mage::getModel('core/resource_transaction')
        ->addObject($invoice)
        ->addObject($invoice->getOrder());
    $transactionSave->save();

    Mage::getSingleton('checkout/session')->unsQuoteId();
    Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=> false));
    return;

I have this in my model:

  protected $_canRefund = true;
  public function refund(Varien_Object $payment, $amount) {   
    return parent::refund($payment, $amount);
  }

But this do not allow the creation of a credit memo. I read here that natively, the Magento API doesn't support online refunds. You have to create a local version of it which implements some methods which are normally only called when raising credit memos in the admin. But after i implement the sample i was in the same place. Please, someone have an sample to make an online refund API?

È stato utile?

Soluzione

Well, after search in all the internet and inspect the visual element in charge to show the button, search in the backend templates for that view i notice that the botton have a condition asking for canCreditmemo() function in Order model class. Then i search the order class in sales in magento code and start debugin the conditions, long story short, the problem is with the estate of the Order

$order->setState(Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW, true, 'Payment Success.');

Change it to

$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, false, 'Payment Success.');

and problem solved

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top