/** * @param Mage_Sales_Model_Order_Payment $payment * @param float $amount * @return Bitpay_Core_Model_PaymentMethod */ public function authorize(Varien_Object $payment, $amount) { if (false === isset($payment) || false === isset($amount) || true === empty($payment) || true === empty($amount)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); } $this->debugData('[INFO] Bitpay_Core_Model_Method_Bitcoin::authorize(): authorizing new order.'); // Create BitPay Invoice $invoice = $this->initializeInvoice(); if (false === isset($invoice) || true === empty($invoice)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); } $invoice = $this->prepareInvoice($invoice, $payment, $amount); try { $bitpayInvoice = \Mage::helper('bitpay')->getBitpayClient()->createInvoice($invoice); } catch (\Exception $e) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): ' . $e->getMessage()); \Mage::throwException('In Bitpay_Core_Model_Method_Bitcoin::authorize(): Could not authorize transaction.'); } self::$_redirectUrl = $bitpayInvoice->getUrl(); $this->debugData(array('[INFO] BitPay Invoice created', sprintf('Invoice URL: "%s"', $bitpayInvoice->getUrl()))); // Save BitPay Invoice in database for reference $mirrorInvoice = \Mage::getModel('bitpay/invoice')->prepareWithBitpayInvoice($bitpayInvoice)->prepateWithOrder($payment->getOrder())->save(); $this->debugData('[INFO] Leaving Bitpay_Core_Model_Method_Bitcoin::authorize(): invoice id ' . $bitpayInvoice->getId()); return $this; }
/** * @param Mage_Sales_Model_Order_Payment $payment * @param float $amount * @return Bitpay_Core_Model_PaymentMethod */ public function authorize(Varien_Object $payment, $amount, $iframe = false) { if (false === isset($payment) || false === isset($amount) || true === empty($payment) || true === empty($amount)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); } $amount = $payment->getOrder()->getQuote()->getGrandTotal(); $this->debugData('[INFO] Bitpay_Core_Model_Method_Bitcoin::authorize(): authorizing new order.'); // Create BitPay Invoice $invoice = $this->initializeInvoice(); if (false === isset($invoice) || true === empty($invoice)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); } $invoice = $this->prepareInvoice($invoice, $payment, $amount); try { $bitpayInvoice = \Mage::helper('bitpay')->getBitpayClient()->createInvoice($invoice); } catch (\Exception $e) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): ' . $e->getMessage()); \Mage::throwException('In Bitpay_Core_Model_Method_Bitcoin::authorize(): Could not authorize transaction.'); } self::$_redirectUrl = Mage::getStoreConfig('payment/bitpay/fullscreen') ? $bitpayInvoice->getUrl() : $bitpayInvoice->getUrl() . '&view=iframe'; $this->debugData(array('[INFO] BitPay Invoice created', sprintf('Invoice URL: "%s"', $bitpayInvoice->getUrl()))); $quote = \Mage::getSingleton('checkout/session')->getQuote(); $order = \Mage::getModel('sales/order')->load($quote->getId(), 'quote_id'); // Save BitPay Invoice in database for reference $mirrorInvoice = \Mage::getModel('bitpay/invoice')->prepareWithBitpayInvoice($bitpayInvoice)->prepareWithOrder(array('increment_id' => $order->getIncrementId(), 'quote_id' => $quote->getId()))->save(); $this->debugData('[INFO] Leaving Bitpay_Core_Model_Method_Bitcoin::authorize(): invoice id ' . $bitpayInvoice->getId()); return $this; }
/** * @param Mage_Sales_Model_Order_Payment $payment * @param float $amount * @return Bitpay_Core_Model_PaymentMethod */ public function authorize(Varien_Object $payment, $amount, $iframe = false) { // Check if coming from iframe or submit button if (!Mage::getStoreConfig('payment/bitpay/fullscreen') && $iframe === false || Mage::getStoreConfig('payment/bitpay/fullscreen') && $iframe === true) { $quoteId = $payment->getOrder()->getQuoteId(); $ipn = Mage::getModel('bitpay/ipn'); if (!$ipn->GetQuotePaid($quoteId)) { // This is the error that is displayed to the customer during checkout. Mage::throwException("Order not paid for. Please pay first and then Place your Order."); Mage::log('Order not paid for. Please pay first and then Place Your Order.', Zend_Log::CRIT, Mage::helper('bitpay')->getLogFile()); } return $this; } if (false === isset($payment) || false === isset($amount) || true === empty($payment) || true === empty($amount)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): missing payment or amount parameters.'); } $this->debugData('[INFO] Bitpay_Core_Model_Method_Bitcoin::authorize(): authorizing new order.'); // Create BitPay Invoice $invoice = $this->initializeInvoice(); if (false === isset($invoice) || true === empty($invoice)) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); throw new \Exception('In Bitpay_Core_Model_Method_Bitcoin::authorize(): could not initialize invoice.'); } $invoice = $this->prepareInvoice($invoice, $payment, $amount); try { $bitpayInvoice = \Mage::helper('bitpay')->getBitpayClient()->createInvoice($invoice); } catch (\Exception $e) { $this->debugData('[ERROR] In Bitpay_Core_Model_Method_Bitcoin::authorize(): ' . $e->getMessage()); \Mage::throwException('In Bitpay_Core_Model_Method_Bitcoin::authorize(): Could not authorize transaction.'); } self::$_redirectUrl = Mage::getStoreConfig('payment/bitpay/fullscreen') ? $bitpayInvoice->getUrl() : $bitpayInvoice->getUrl() . '&view=iframe'; $this->debugData(array('[INFO] BitPay Invoice created', sprintf('Invoice URL: "%s"', $bitpayInvoice->getUrl()))); $quote = Mage::getSingleton('checkout/session')->getQuote(); $order = \Mage::getModel('sales/order')->load($quote->getId(), 'quote_id'); // Save BitPay Invoice in database for reference $mirrorInvoice = \Mage::getModel('bitpay/invoice')->prepareWithBitpayInvoice($bitpayInvoice)->prepareWithOrder(array('increment_id' => $order->getIncrementId(), 'quote_id' => $quote->getId()))->save(); $this->debugData('[INFO] Leaving Bitpay_Core_Model_Method_Bitcoin::authorize(): invoice id ' . $bitpayInvoice->getId()); return $this; }