Ejemplo n.º 1
0
 public function refund(Varien_Object $payment, $amount)
 {
     // fetch order and transaction info
     $order = $payment->getOrder();
     $row = $this->_mysqlr->fetchRow('SELECT * FROM `' . $this->_table . '` WHERE `order_id` = ' . intval($order->entity_id), array(), Zend_Db::FETCH_ASSOC);
     $transaction_id = $row['transaction_id'];
     // fetch payment info
     $mollie = $this->_api->_getMollieAPI();
     $mollie_payment = $mollie->payments->get($transaction_id);
     // attempt a refund
     try {
         $mollie->payments->refund($mollie_payment, $amount);
     } catch (Exception $e) {
         Mage::throwException('Impossible to create a refund for this transaction. Details: ' . $e->getMessage() . '<br />');
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * 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());
     }
 }