public function refund(Varien_Object $payment, $amount) { $order = $payment->getOrder(); $payment = $order->getPayment()->getMethodInstance(); switch ($payment->getCode()) { // MSP - Fast Checkout case self::MSP_FASTCHECKOUT_CODE: $settingsPathPrefix = 'mspcheckout/settings'; break; // General (Main settings in the 'Payment Methods' tab // General (Main settings in the 'Payment Methods' tab case self::MSP_GENERAL_CODE: $settingsPathPrefix = 'payment/msp'; break; // MSP - Gateways (Pay After Delivery) // MSP - Gateways (Pay After Delivery) case self::MSP_GENERAL_PAD_CODE: $settingsPathPrefix = 'msp/' . self::MSP_GENERAL_PAD_CODE; break; case self::MSP_GENERAL_KLARNA_CODE: $settingsPathPrefix = 'msp/' . self::MSP_GENERAL_KLARNA_CODE; break; // MSP - Gateways // MSP - Gateways default: $settingsPathPrefix = 'msp/settings'; break; } $config = Mage::getStoreConfig($settingsPathPrefix, $order->getStoreId()); // use refund by Credit Memo is enabled $pathCreditMemoIsEnabled = $payment->getCode() == self::MSP_GENERAL_PAD_CODE || $payment->getCode() == self::MSP_GENERAL_KLARNA_CODE ? 'msp/settings' : $settingsPathPrefix; if (!Mage::getStoreConfigFlag($pathCreditMemoIsEnabled . '/use_refund_credit_memo', $order->getStoreId())) { Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('msp')->__('Refund has not been send to MultiSafepay. You need to refund manually at MultiSafepay. Please check if the creditmemo option is configured within the MultiSafepay payment methods configuration!')); return $this; } // check payment method is from MultiSafepayment if (!in_array($payment->getCode(), $this->availablePaymentMethodCodes)) { Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('msp')->__('Refund has not been send to MultiSafepay. Looks like a non MultiSafepay payment method was selected')); return $this; } // build request $mapi = new MultiSafepay(); $mapi->test = $config['test_api'] == 'test'; $mapi->merchant['account_id'] = $config['account_id']; $mapi->merchant['site_id'] = $config['site_id']; $mapi->merchant['site_code'] = $config['secure_code']; $mapi->merchant['api_key'] = $config['api_key']; $mapi->transaction['id'] = $order->getIncrementId(); $mapi->transaction['amount'] = $amount * 100; //$order->getGrandTotal() * 100; $mapi->transaction['currency'] = Mage::app()->getStore()->getCurrentCurrencyCode(); $mapi->signature = sha1($config['site_id'] . $config['secure_code'] . $mapi->transaction['id']); $response = $mapi->refundTransaction(); if ($mapi->error) { Mage::getSingleton('adminhtml/session')->addError($mapi->error_code . ' - ' . $mapi->error); //return false; } else { Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('msp')->__('Refund request has been sent successfully to MultiSafepay, your transaction has been refunded.')); } return $this; }