Fix for order not marked complete issue

This commit is contained in:
Rich Morgan 2014-03-13 16:14:25 -04:00
parent ac03c7fa44
commit 8dacf9939c
1 changed files with 53 additions and 24 deletions

View File

@ -53,7 +53,7 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
/**
* Can capture funds online?
*/
protected $_canCapture = false;
protected $_canCapture = true;
/**
* Can capture partial amounts online?
@ -144,31 +144,60 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
if (!count($order->getInvoiceCollection())) {
$invoice = $order->prepareInvoice()
->setTransactionId(1)
->addComment('Invoiced automatically by Bitpay/Bitcoins/controllers/IndexController.php')
->register()
->pay();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE);
try {
$order->sendNewOrderEmail();
$invoice = $order->prepareInvoice()
->setTransactionId(1)
->addComment('Invoiced automatically by Bitpay/Bitcoins/controllers/IndexController.php')
->register()
->pay();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
} catch (Exception $e) {
Mage::logException($e);
}
} else {
Mage::log('Count of InvoiceCollection was zero! Order not invoiced.', null, 'bitpay.log');
}
}
function MarkOrderComplete($order) {
if ($order->hasInvoices()) {
foreach ($order->getInvoiceCollection() as $_eachInvoice) {
try {
$_eachInvoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$_eachInvoice->capture()->save();
} catch (Exception $e) {
Mage::logException($e);
}
}
}
$shipment = $order->prepareShipment();
if($shipment) {
$shipment->register();
$order->setIsInProcess(true);
$transaction_save = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
}
try {
$order->setState('Complete', 'complete', 'Completed by BitPay payments.', false);
$order->save();
} catch (Exception $e) {
Mage::logException($e);
}
}
function MarkOrderCancelled($order) {
$order->setState(Mage_Sales_Model_Order::STATE_CANCELLED, true)->save();
}
}
// given Mage_Core_Model_Abstract, return api-friendly address
function ExtractAddress($address) {
@ -178,7 +207,7 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
if ($address->getCompany())
$options['buyerName'] = $options['buyerName'].' c/o '.$address->getCompany();
$options['buyerAddress1'] = $address->getStreet1();
$options['buyerAddress1'] = $address->getStreet1();
$options['buyerAddress2'] = $address->getStreet2();
$options['buyerAddress3'] = $address->getStreet3();
$options['buyerAddress4'] = $address->getStreet4();
@ -193,7 +222,7 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
foreach(array('buyerName', 'buyerAddress1', 'buyerAddress2', 'buyerAddress3', 'buyerAddress4', 'buyerCity', 'buyerState', 'buyerZip', 'buyerCountry', 'buyerEmail', 'buyerPhone') as $f)
$options[$f] = substr($options[$f], 0, 100);
return $options;
return $options;
}
function CreateInvoiceAndRedirect($payment, $amount) {
@ -214,7 +243,7 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
'apiKey' => $apiKey,
);
$options += $this->ExtractAddress($order->getShippingAddress());
$options += $this->ExtractAddress($order->getShippingAddress());
$invoice = bpCreateInvoice($orderId, $amount, array('orderId' => $orderId), $options);
$payment->setIsTransactionPending(true); // status will be PAYMENT_REVIEW instead of PROCESSING