Merge pull request #28 from ionux/master

Add call to send email & bool option for shipment
This commit is contained in:
Ryan X. Charles 2014-03-18 08:55:53 -07:00
commit 41a6220571
1 changed files with 38 additions and 16 deletions

View File

@ -90,6 +90,11 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
*/ */
protected $_canSaveCc = false; protected $_canSaveCc = false;
/**
* BitPay - create shipment automatically after completing order?
*/
protected $_bpCreateShipment = false;
//protected $_formBlockType = 'bitcoins/form'; //protected $_formBlockType = 'bitcoins/form';
//protected $_infoBlockType = 'bitcoins/info'; //protected $_infoBlockType = 'bitcoins/info';
@ -174,30 +179,47 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
} }
} }
//$shipment = $order->prepareShipment(); // If the $_bpCreateShipment option is set to true above, this code will
//if($shipment) { // programmatically create a shipment for you. By design, this will mark
// $shipment->register(); // the entire order as 'complete'.
// $order->setIsInProcess(true); if(isset($_bpCreateShipment) && $_bpCreateShipment == true) {
try {
// $transaction_save = Mage::getModel('core/resource_transaction') $shipment = $order->prepareShipment();
// ->addObject($shipment) if($shipment) {
// ->addObject($shipment->getOrder()) $shipment->register();
// ->save(); $order->setIsInProcess(true);
//} $transaction_save = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
}
} catch (Exception $e) {
Mage::log('Error creating shipment', null, 'bitpay.log');
Mage::logException($e);
}
}
try { try {
//$order->setState('Complete', 'complete', 'Completed by BitPay payments.', true); if(isset($_bpCreateShipment) && $_bpCreateShipment == true) {
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, 'processing', 'BitPay has confirmed the payment.', true); $order->setState('Complete', 'complete', 'Completed by BitPay payments.', true);
} else {
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, 'processing', 'BitPay has confirmed the payment.', false);
$order->sendNewOrderEmail();
}
$order->save(); $order->save();
} catch (Exception $e) { } catch (Exception $e) {
Mage::logException($e); Mage::logException($e);
} }
} }
function MarkOrderCancelled($order) { function MarkOrderCancelled($order) {
try {
$order->setState(Mage_Sales_Model_Order::STATE_CANCELLED, true)->save(); $order->setState(Mage_Sales_Model_Order::STATE_CANCELLED, true)->save();
} catch (Exception $e) {
Mage::log('Could not cancel order', null, 'bitpay.log');
Mage::logException($e);
}
} }
// given Mage_Core_Model_Abstract, return api-friendly address // given Mage_Core_Model_Abstract, return api-friendly address