Currently I am using the code below to refund a full order and create the creditmemo..

        $order = Mage::getModel('sales/order')->loadByIncrementId('100091904');
        $invoices = array();
        foreach ($order->getInvoiceCollection() as $invoice) {
            if ($invoice->canRefund()) {
                $invoices[] = $invoice;

        $service = Mage::getModel('sales/service_order', $order);
        foreach ($invoices as $invoice) {
            $creditmemo = $service->prepareInvoiceCreditmemo($invoice);

But the problem is that the customer paid online with SagePay, this current method ONLY refunds this offline and as you can see this could be a very big problem, anyone got any ways to get around this? Would be much appreciated. Using Magento Enterprise ver.

I've not found anything on this before this purely REFUNDING online, not creating the Credit Memo that is the problem it only refunds offline.

closed as off-topic by Marius, David Manners, Keyul Shah, davidalger, Foo Bar Jun 13 '14 at 16:15

  • This question does not appear to be about the Magento e-Commerce platform within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Why is it a problem? Refunding online means that Magento can talk back to the payment processor and submit a refund. Refund offline merely makes the record in Magento that it has been refunded (with no update to the payment processor). Some payment processors don't support this, or require a certain period before it can be done, hence why Refund Offline is available. – Axel Dec 11 '13 at 6:22
  • That is a good point but it's a problem because I'd like the refund to be done through the Payment Option, and it works when doing it manually just not through the API or the bespoke code found. Not really got any idea where to go with this. – Aimson Dec 11 '13 at 14:26
  • 4
    This question appears to be off-topic because it is about a third party module – Marius Jun 13 '14 at 8:21
  • It's not off-topic at all, this was the PHP code in Magento e-Commerce platform. Nothing to do with the SagePay third party module. – Aimson Jun 16 '14 at 9:01

Browse other questions tagged or ask your own question.