public function testSetPaymentDoesNotAcceptNull() { $this->mage->expects($this->once())->method("throwException")->with('Ongeldig order_id of transaction_id...')->will($this->throwException(new Exception("NO_NULL", 400))); $this->setExpectedException("Exception", "NO_NULL", 400); $model = new Mollie_Mpm_Model_Api(); $model->setPayment(NULL, NULL); }
/** * This action is getting called by Mollie to report the payment status */ public function webhookAction() { // Determine if this is a connection test if ($this->getRequest()->getParam('testByMollie')) { return; } // Get transaction_id from post parameter $transactionId = $this->getRequest()->getParam('id'); // Get order by transaction_id $orderId = Mage::helper('mpm/data')->getOrderIdByTransactionId($transactionId); // Load order by id ($orderId) /** @var $order Mage_Sales_Model_Order */ $order = Mage::getModel('sales/order')->load($orderId); try { if (!empty($transactionId) && $order->getData('status') === Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) { if (!$this->_api->checkPayment($transactionId)) { Mage::throwException($this->_api->getErrorMessage()); } $customer = $this->_api->getConsumerInfo(); // Maakt een Order transactie aan /** @var $payment Mage_Sales_Model_Order_Payment */ $payment = Mage::getModel('sales/order_payment')->setMethod('Mollie')->setTransactionId($transactionId)->setIsTransactionClosed(TRUE); $order->setPayment($payment); if ($this->_api->getPaidStatus()) { // Als de vorige betaling was mislukt, zijn de producten 'Canceled'... Undo that foreach ($order->getAllItems() as $item) { /** @var $item Mage_Sales_Model_Order_Item */ $item->setQtyCanceled(0); $item->save(); } $this->_model->updatePayment($transactionId, $this->_api->getBankStatus(), $customer); /* * Send an email to the customer. */ if (!Mage::Helper('mpm/data')->getConfig('mollie', 'skip_order_mails')) { $order->sendNewOrderEmail()->setEmailSent(TRUE); } if ($transaction = $payment->getTransaction($transactionId)) { $transaction->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE); $transaction->setIsClosed(TRUE); $transaction->save(); } else { Mage::log(__METHOD__ . ' said: Could not find a transaction with id ' . $transactionId . ' for order ' . $orderId); return; } if (Mage::Helper('mpm/data')->getConfig('mollie', 'skip_invoice') || !$order->canInvoice()) { /* * Update the total amount paid */ try { $amount = $this->_api->getAmount(); // Amount in EUROs $curr_base = Mage::app()->getStore()->getBaseCurrencyCode(); $curr_store = Mage::app()->getStore()->getCurrentCurrencyCode(); $amount_base = Mage::helper('directory')->currencyConvert($amount, 'EUR', $curr_base); $amount_store = Mage::helper('directory')->currencyConvert($amount, 'EUR', $curr_store); $order->setBaseTotalPaid($amount_base); $order->setTotalPaid($amount_store); } catch (Exception $e) { Mage::log(__METHOD__ . '() said: Could not convert currencies. Details: ' . $e->getMessage()); } } else { $this->_savePaidInvoice($order, $transaction->getId()); } $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING, $this->__(Mollie_Mpm_Model_Api::PAYMENT_FLAG_PROCESSED), TRUE); $order->save(); } else { $this->_model->updatePayment($transactionId, $this->_api->getBankStatus()); // Stomme Magento moet eerst op 'cancel' en dan pas setState, andersom dan zet hij de voorraad niet terug. $order->cancel(); $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, Mage_Sales_Model_Order::STATE_CANCELED, $this->__(Mollie_Mpm_Model_Api::PAYMENT_FLAG_CANCELD), FALSE)->save(); } } } catch (Exception $e) { Mage::log($e); $this->_showException($e->getMessage()); } }