Added duplicate paid/confirmed/complete checks

Also added logging in case of duplicate IPNs to inform the merchant in the event they needed to capture that information.
This commit is contained in:
Rich Morgan 2014-06-24 23:32:07 -04:00
parent 8ebae606ca
commit 1667dfde1a
1 changed files with 25 additions and 11 deletions

View File

@ -23,9 +23,9 @@
class Bitpay_Bitcoins_IndexController extends Mage_Core_Controller_Front_Action {
public function checkForPaymentAction() {
$params = $this->getRequest()->getParams();
$params = $this->getRequest()->getParams();
$quoteId = $params['quote'];
$paid = Mage::getModel('Bitcoins/ipn')->GetQuotePaid($quoteId);
$paid = Mage::getModel('Bitcoins/ipn')->GetQuotePaid($quoteId);
print json_encode(array('paid' => $paid));
exit();
}
@ -33,7 +33,7 @@ class Bitpay_Bitcoins_IndexController extends Mage_Core_Controller_Front_Action
// bitpay's IPN lands here
public function indexAction() {
require Mage::getBaseDir('lib').'/bitpay/bp_lib.php';
$apiKey = Mage::getStoreConfig('payment/Bitcoins/api_key');
$apiKey = Mage::getStoreConfig('payment/Bitcoins/api_key');
$invoice = bpVerifyNotification($apiKey);
if (is_string($invoice))
@ -52,22 +52,36 @@ class Bitpay_Bitcoins_IndexController extends Mage_Core_Controller_Front_Action
Mage::getModel('Bitcoins/ipn')->Record($invoice);
// update the order if it exists already
if ($order->getId())
if ($order->getId()) {
switch($invoice['status']) {
case 'paid':
$method = Mage::getModel('Bitcoins/paymentMethod');
$method->MarkOrderPaid($order);
// 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.', null, 'bitpay.log');
}
break;
case 'confirmed':
case 'complete':
$method = Mage::getModel('Bitcoins/paymentMethod');
$method->MarkOrderComplete($order);
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.', null, 'bitpay.log');
}
break;
case 'invalid':
$method = Mage::getModel('Bitcoins/paymentMethod');
$method->MarkOrderCancelled($order);
break;
}
}
}
}