expired invoice - wrong redirect

This commit is contained in:
Damian Bzdon 2018-03-13 11:32:10 +01:00
parent 23db274908
commit 76b82f8c7f
2 changed files with 47 additions and 0 deletions

View File

@ -55,6 +55,9 @@ class Bitpay_Core_Model_Method_Bitcoin extends Mage_Payment_Model_Method_Abstrac
throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.');
}
//add order id to the redirect url to match order in the checkout/onepage/success if bitpay invoice expired
$invoice->setRedirectUrl(\Mage::getUrl(\Mage::getStoreConfig('payment/bitpay/redirect_url') . '/order_id/'.$payment->getOrder()->getId()));
$invoice = $this->prepareInvoice($invoice, $payment, $amount);
try {

View File

@ -75,4 +75,48 @@ class Bitpay_Core_Model_Observer {
\Mage::helper('bitpay') -> cleanExpired();
}
/**
* Event Hook: checkout_onepage_controller_success_action
* @param $observer Varien_Event_Observer
*/
public function redirectToCartIfExpired(Varien_Event_Observer $observer)
{
if ($observer->getEvent()->getName() == 'checkout_onepage_controller_success_action')
{
$lastOrderId = null;
foreach(\Mage::app()->getRequest()->getParams() as $key=>$value)
{
if($key == 'order_id')
$lastOrderId = $value;
}
if($lastOrderId != null)
{
//get order
$order = \Mage::getModel('sales/order')->load($lastOrderId);
if (false === isset($order) || true === empty($order)) {
\Mage::helper('bitpay')->debugData('[ERROR] In Bitpay_Core_Model_Observer::redirectToCartIfExpired(), Invalid Order ID received.');
return;
}
//check if order is pending
if($order->getStatus() != 'pending')
return;
//check if invoice for order exist in bitpay_invoices table
$bitpayInvoice = \Mage::getModel('bitpay/invoice')->load($order->getIncrementId(), 'increment_id');
$bitpayInvoiceData = $bitpayInvoice->getData();
//if is empty or not is array abort
if(!is_array($bitpayInvoiceData) || is_array($bitpayInvoiceData) && empty($bitpayInvoiceData))
return;
//check if bitpay invoice id expired
$invoiceExpirationTime = $bitpayInvoiceData['expiration_time'];
if($invoiceExpirationTime < strtotime('now'))
{
$failure_url = \Mage::getUrl(\Mage::getStoreConfig('payment/bitpay/failure_url'));
\Mage::app()->getResponse()->setRedirect($failure_url)->sendResponse();
}
}
}
}
}