-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify capture code - fixes #10, add mass capture functionality
- Loading branch information
Showing
4 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/code/community/Quickpay/Payment/controllers/Adminhtml/QuickpayController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
class Quickpay_Payment_Adminhtml_QuickpayController extends Mage_Adminhtml_Controller_Action | ||
{ | ||
/** | ||
* Mass capture action | ||
* | ||
* @throws Mage_Core_Exception | ||
*/ | ||
public function massCaptureAction() | ||
{ | ||
$orderIds = $this->getRequest()->getPost('order_ids', array()); | ||
|
||
foreach ($orderIds as $orderId) { | ||
/** @var Mage_Sales_Model_Order $order */ | ||
$order = Mage::getModel("sales/order")->load($orderId); | ||
|
||
if (!$order->getPayment()->getMethodInstance() instanceof Quickpay_Payment_Model_Method_Abstract) { | ||
$this->_getSession()->addError($this->__('%s Order was not placed using QuickPay', $order->getIncrementId())); | ||
continue; | ||
} | ||
|
||
try { | ||
|
||
if (!$order->canInvoice()) { | ||
$this->_getSession()->addError($this->__('Could not create invoice for %s', $order->getIncrementId())); | ||
} | ||
|
||
/* @var $invoice Mage_Sales_Model_Order_Invoice */ | ||
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(); | ||
|
||
if (!$invoice->getTotalQty()) { | ||
$this->_getSession()->addError($this->__('Cannot create an invoice without products for %s.', $order->getIncrementId())); | ||
} | ||
|
||
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE); | ||
$invoice->register(); | ||
|
||
$transactionSave = Mage::getModel('core/resource_transaction') | ||
->addObject($invoice) | ||
->addObject($invoice->getOrder()); | ||
|
||
$transactionSave->save(); | ||
} catch (Exception $e) { | ||
$this->_getSession()->addError($this->__('Invoice and capture failed for %s: %s', $order->getIncrementId(), $e->getMessage())); | ||
} | ||
} | ||
|
||
$this->_redirect('*/sales_order/'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters