1
如何在Magento中以編程方式退款?更確切地說,處於未決狀態和狀態的訂單如何更改爲適當的退款狀態和/或狀態。Magento - 如何以編程方式發行退款?
如何在Magento中以編程方式退款?更確切地說,處於未決狀態和狀態的訂單如何更改爲適當的退款狀態和/或狀態。Magento - 如何以編程方式發行退款?
你真的不能通過IPN設施做到這一點,因爲網關正在通知Magento已經發生的行動。如果您想實際在線退款,只需要擴展或調用CreditmemoController的saveAction即可。
這是實際進行退款但是依賴於控制器內受保護方法的控制器操作。要使用這個,你可以直接發佈到它 - 例如發佈到https://yoursite.com/admin/sales/order/creditmemo/save/
,或者在一個捏你可以複製到一個單一的腳本的方法。
<?php
//taken from /app/code/core/Adminhtml/controllers/Sales/Order/CreditmemoController.php
/**
* Save creditmemo
* We can save only new creditmemo. Existing creditmemos are not editable
*/
public function saveAction()
{
$data = $this->getRequest()->getPost('creditmemo');
if (!empty($data['comment_text'])) {
Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']);
}
try {
$creditmemo = $this->_initCreditmemo();
if ($creditmemo) {
if (($creditmemo->getGrandTotal() <=0) && (!$creditmemo->getAllowZeroGrandTotal())) {
Mage::throwException(
$this->__('Credit memo\'s total must be positive.')
);
}
$comment = '';
if (!empty($data['comment_text'])) {
$creditmemo->addComment(
$data['comment_text'],
isset($data['comment_customer_notify']),
isset($data['is_visible_on_front'])
);
if (isset($data['comment_customer_notify'])) {
$comment = $data['comment_text'];
}
}
if (isset($data['do_refund'])) {
$creditmemo->setRefundRequested(true);
}
if (isset($data['do_offline'])) {
$creditmemo->setOfflineRequested((bool)(int)$data['do_offline']);
}
$creditmemo->register();
if (!empty($data['send_email'])) {
$creditmemo->setEmailSent(true);
}
$creditmemo->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
$this->_saveCreditmemo($creditmemo);
$creditmemo->sendEmail(!empty($data['send_email']), $comment);
$this->_getSession()->addSuccess($this->__('The credit memo has been created.'));
Mage::getSingleton('adminhtml/session')->getCommentText(true);
$this->_redirect('*/sales_order/view', array('order_id' => $creditmemo->getOrderId()));
return;
} else {
$this->_forward('noRoute');
return;
}
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
} catch (Exception $e) {
Mage::logException($e);
$this->_getSession()->addError($this->__('Cannot save the credit memo.'));
}
$this->_redirect('*/*/new', array('_current' => true));
}
HTH,乾杯。
正在尋求離線簽發貸項通知單,或者您的目標是通過支付網關觸發在線退款嗎? – benmarks
我正試圖從Magento側的網關處理退款ipn(將狀態更改爲適當的,發出備忘錄,無論適當的過程是什麼)。謝謝。 –