diff --git a/app/code/community/Bitpay/Bitcoins/Model/PaymentMethod.php b/app/code/community/Bitpay/Bitcoins/Model/PaymentMethod.php index 7527da9..de82fdd 100644 --- a/app/code/community/Bitpay/Bitcoins/Model/PaymentMethod.php +++ b/app/code/community/Bitpay/Bitcoins/Model/PaymentMethod.php @@ -245,6 +245,7 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst public function MarkOrderPaid($order) { $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save(); + //Mage::log($order->getData(), null, 'bitpay.log'); if ($order->getTotalDue() > 0) { @@ -264,7 +265,7 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst */ public function MarkOrderComplete($order) { - if ($order->getTotalDue() >= 0) + if ($order->getTotalDue() >= 0 && $order->canInvoice()) { if ($order->hasInvoices()) { @@ -283,10 +284,6 @@ class Bitpay_Bitcoins_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst } } } - else - { - Mage::log('MarkOrderComplete called but order '. $order->getId() .' has an outstanding balance that has not been paid.', Zend_Log::WARN, 'bitpay.log'); - } // If the $_bpCreateShipment option is set to true above, this code will // programmatically create a shipment for you. By design, this will mark diff --git a/app/code/community/Bitpay/Bitcoins/controllers/IndexController.php b/app/code/community/Bitpay/Bitcoins/controllers/IndexController.php index a6e28d9..d7922ea 100644 --- a/app/code/community/Bitpay/Bitcoins/controllers/IndexController.php +++ b/app/code/community/Bitpay/Bitcoins/controllers/IndexController.php @@ -53,6 +53,8 @@ class Bitpay_Bitcoins_IndexController extends Mage_Core_Controller_Front_Action throw new Exception('Bitpay callback error:' . $invoice); } + Mage::log($invoice, null, 'bitpay.log'); + // get the order if (isset($invoice['posData']['quoteId'])) { @@ -89,30 +91,17 @@ class Bitpay_Bitcoins_IndexController extends Mage_Core_Controller_Front_Action // Map to Magento state Processing case 'paid': // Mark paid if there is an outstanding total - if ($order->getTotalDue() > 0) - { - $method = Mage::getModel('Bitcoins/paymentMethod'); - $method->MarkOrderPaid($order); - } - else - { - Mage::log('Received a PAID notification from BitPay but there is nothing due on this invoice. Ignoring this IPN.', Zend_Log::INFO, 'bitpay.log'); - } + $method = Mage::getModel('Bitcoins/paymentMethod'); + $method->MarkOrderPaid($order); break; // Map to Magento status Complete case 'confirmed': case 'complete': // Mark confirmed/complete if the order has been paid - if ($order->getTotalDue() <= 0) - { - $method = Mage::getModel('Bitcoins/paymentMethod'); - $method->MarkOrderComplete($order); - } - else - { - Mage::log('Received a ' . $invoice['status'] . ' notification from BitPay but this order is not paid yet. Possible internal error with Magento. Check order status to confirm.', Zend_Log::ERR, 'bitpay.log'); - } + $method = Mage::getModel('Bitcoins/paymentMethod'); + $method->MarkOrderComplete($order); + //Mage::log('Received a ' . $invoice['status'] . ' notification from BitPay but this order is not paid yet. Possible internal error with Magento. Check order status to confirm.', Zend_Log::ERR, 'bitpay.log'); break; // Map to Magento State Closed diff --git a/lib/bitpay/bp_config_default.php b/lib/bitpay/bp_config_default.php index 33df7fa..ab781d7 100644 --- a/lib/bitpay/bp_config_default.php +++ b/lib/bitpay/bp_config_default.php @@ -26,7 +26,7 @@ global $bpconfig; -$bpconfig['host'] = "bitpay.com"; +$bpconfig['host'] = "test.bitpay.com"; $bpconfig['port'] = 443; $bpconfig['hostAndPort'] = $bpconfig['host'];