diff --git a/app/code/community/Mollie/Mpm/Model/Client/Orders.php b/app/code/community/Mollie/Mpm/Model/Client/Orders.php index ba1759b5..1acf8178 100644 --- a/app/code/community/Mollie/Mpm/Model/Client/Orders.php +++ b/app/code/community/Mollie/Mpm/Model/Client/Orders.php @@ -106,6 +106,10 @@ public function startTransaction(Mage_Sales_Model_Order $order) $orderData['payment']['dueDate'] = $this->mollieHelper->getBanktransferDueDate($storeId); } + if (isset($additionalData['limited_methods'])) { + $orderData['method'] = $additionalData['limited_methods']; + } + $orderData = $this->mollieHelper->validateOrderData($orderData); $this->mollieHelper->addTolog('request', $orderData); @@ -248,15 +252,6 @@ public function processTransaction(Mage_Sales_Model_Order $order, $type = 'webho ->addObject($invoice) ->addObject($invoice->getOrder()) ->save(); - - - /** - * $transaction = Mage::getModel('core/resource_transaction') - * ->addObject($invoice) - * ->addObject($invoice->getOrder()); - * - * $transaction->save(); - * **/ } $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING)->save(); @@ -309,9 +304,12 @@ public function processTransaction(Mage_Sales_Model_Order $order, $type = 'webho if ($mollieOrder->method == 'banktransfer' && !$order->getEmailSent()) { $order->sendNewOrderEmail()->setEmailSent(true)->save(); $message = $this->mollieHelper->__('New order email sent'); - $defaultStatusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId); + if (!$statusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId)) { + $statusPending = $order->getStatus(); + } + $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT); - $order->addStatusToHistory($defaultStatusPending, $message, true); + $order->addStatusToHistory($statusPending, $message, true); $order->save(); } @@ -472,12 +470,11 @@ public function createShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_S * Check if Transactions needs to be captures (eg. Klarna methods) */ $payment = $order->getPayment(); - if (!$payment->getIsTransactionClosed()) { + /** @var Mage_Sales_Model_Order_Invoice $invoice */ + $invoice = $order->getInvoiceCollection()->getLastItem(); + if ($invoice && $invoice->getState() == 1) { $payment->registerCaptureNotification($order->getBaseGrandTotal(), true); $order->save(); - - /** @var Mage_Sales_Model_Order_Invoice $invoice */ - $invoice = $payment->getCreatedInvoice(); $sendInvoice = $this->mollieHelper->sendInvoice($order->getStoreId()); if ($invoice && !$invoice->getEmailSent() && $sendInvoice) { $invoice->setEmailSent(true)->sendEmail()->save(); @@ -497,7 +494,6 @@ public function createShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_S * @param Mage_Sales_Model_Order $order * * @return $this - * @throws Mage_Core_Exception */ public function updateShipmentTrack(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order_Shipment_Track $track, Mage_Sales_Model_Order $order) { @@ -538,7 +534,6 @@ public function updateShipmentTrack(Mage_Sales_Model_Order_Shipment $shipment, M } } catch (\Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); - Mage::throwException($this->mollieHelper->__('Mollie API: %s', $e->getMessage())); } return $this; @@ -557,9 +552,26 @@ public function createOrderRefund(Mage_Sales_Model_Order_Creditmemo $creditmemo, $storeId = $order->getStoreId(); $orderId = $order->getId(); + /** + * Skip the creation of an online refund if an offline refund is used + * and add a message to the core/sessions about this workflow. + * Registry set at the Mollie_Mpm_Model_Mollie::refund and is set once an online refund is used. + */ + if (!Mage::registry('online_refund')) { + Mage::getSingleton('core/session')->addNotice( + $this->mollieHelper->__( + 'An offline refund has been created, please make sure to also create this + refund on mollie.com/dashboard or use the online refund option.' + ) + ); + return $this; + } + $methodCode = $this->mollieHelper->getMethodCode($order); if (!$order->hasShipments() && ($methodCode == 'klarnapaylater' || $methodCode == 'klarnasliceit')) { - $msg = $this->mollieHelper->__('Order can only be refunded after Klara has been captured (after shipment)'); + $msg = $this->mollieHelper->__( + 'Order can only be refunded after Klara has been captured (after shipment)' + ); Mage::throwException($msg); } @@ -582,7 +594,9 @@ public function createOrderRefund(Mage_Sales_Model_Order_Creditmemo $creditmemo, * Throw exception if these are set, as this is not supportef by the orders api. */ if ($creditmemo->getAdjustmentPositive() > 0 || $creditmemo->getAdjustmentNegative() > 0) { - $msg = $this->mollieHelper->__('Creating an online refund with adjustment fee\'s is not supported by Mollie'); + $msg = $this->mollieHelper->__( + 'Creating an online refund with adjustment fee\'s is not supported by Mollie' + ); $this->mollieHelper->addTolog('error', $msg); Mage::throwException($msg); } diff --git a/app/code/community/Mollie/Mpm/Model/Client/Payments.php b/app/code/community/Mollie/Mpm/Model/Client/Payments.php index 70d44188..e36b63a9 100644 --- a/app/code/community/Mollie/Mpm/Model/Client/Payments.php +++ b/app/code/community/Mollie/Mpm/Model/Client/Payments.php @@ -249,10 +249,14 @@ public function processTransaction(Mage_Sales_Model_Order $order, $type = 'webho if ($status == 'open') { if ($paymentData->method == 'banktransfer' && !$order->getEmailSent()) { $order->sendNewOrderEmail()->setEmailSent(true)->save(); - $defaultStatusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId); - $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT; $message = $this->mollieHelper->__('New order email sent'); - $order->setState($defaultStatusPending, $status, $message, false)->save(); + if (!$statusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId)) { + $statusPending = $order->getStatus(); + } + + $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT); + $order->addStatusToHistory($statusPending, $message, true); + $order->save(); } $msg = array('success' => true, 'status' => 'open', 'order_id' => $orderId, 'type' => $type); diff --git a/app/code/community/Mollie/Mpm/Model/Method/Abstract.php b/app/code/community/Mollie/Mpm/Model/Method/Abstract.php index 47a88e37..56b3d965 100644 --- a/app/code/community/Mollie/Mpm/Model/Method/Abstract.php +++ b/app/code/community/Mollie/Mpm/Model/Method/Abstract.php @@ -60,4 +60,16 @@ class Mollie_Mpm_Model_Method_Abstract extends Mollie_Mpm_Model_Mollie protected $_canRefundInvoicePartial = true; protected $_canCapture = true; + /** + * @param mixed $data + * + * @return $this|Mage_Payment_Model_Info + * @throws Mage_Core_Exception + */ + public function assignData($data) + { + parent::assignData($data); + $this->getInfoInstance()->setAdditionalInformation('selected_issuer', null); + return $this; + } } \ No newline at end of file diff --git a/app/code/community/Mollie/Mpm/Model/Method/Kbc.php b/app/code/community/Mollie/Mpm/Model/Method/Kbc.php index 7b37d30c..7c59fcc3 100644 --- a/app/code/community/Mollie/Mpm/Model/Method/Kbc.php +++ b/app/code/community/Mollie/Mpm/Model/Method/Kbc.php @@ -49,4 +49,19 @@ class Mollie_Mpm_Model_Method_Kbc extends Mollie_Mpm_Model_Method_Abstract */ protected $_paymentMethod = self::PAYMENT_METHOD; + /** + * @param mixed $data + * + * @return $this|Mage_Payment_Model_Info + * @throws Mage_Core_Exception + */ + public function assignData($data) + { + parent::assignData($data); + + $selectedIssuer = Mage::app()->getRequest()->getParam('mollie_kbc_issuer'); + $this->getInfoInstance()->setAdditionalInformation('selected_issuer', $selectedIssuer); + + return $this; + } } diff --git a/app/code/community/Mollie/Mpm/Model/Method/Paymentlink.php b/app/code/community/Mollie/Mpm/Model/Method/Paymentlink.php index ad92b840..3b350914 100644 --- a/app/code/community/Mollie/Mpm/Model/Method/Paymentlink.php +++ b/app/code/community/Mollie/Mpm/Model/Method/Paymentlink.php @@ -85,4 +85,19 @@ public function initialize($paymentAction, $stateObject) $this->startTransaction($order); } + /** + * @param mixed $data + * + * @return $this|Mage_Payment_Model_Info + * @throws Mage_Core_Exception + */ + public function assignData($data) + { + parent::assignData($data); + + $limitedMethods = Mage::app()->getRequest()->getParam('limited_methods', null); + $this->getInfoInstance()->setAdditionalInformation('limited_methods', $limitedMethods); + return $this; + } + } diff --git a/app/code/community/Mollie/Mpm/Model/Mollie.php b/app/code/community/Mollie/Mpm/Model/Mollie.php index 72c1c2a7..67aa6f33 100644 --- a/app/code/community/Mollie/Mpm/Model/Mollie.php +++ b/app/code/community/Mollie/Mpm/Model/Mollie.php @@ -243,6 +243,7 @@ public function refund(Varien_Object $payment, $amount) */ $checkoutType = $this->mollieHelper->getCheckoutType($order); if ($checkoutType == 'order') { + Mage::register('online_refund', true); return $this; } diff --git a/app/code/community/Mollie/Mpm/Model/OrderLines.php b/app/code/community/Mollie/Mpm/Model/OrderLines.php index 0917bad7..974a1c97 100644 --- a/app/code/community/Mollie/Mpm/Model/OrderLines.php +++ b/app/code/community/Mollie/Mpm/Model/OrderLines.php @@ -288,13 +288,18 @@ public function getShipmentOrderLines(Mage_Sales_Model_Order_Shipment $shipment) } /** - * @param $lineId + * @param $itemId * * @return Mollie_Mpm_Model_Resource_OrderLines */ public function getOrderLineByItemId($itemId) { - return $this->load($itemId, 'item_id'); + $orderLine = $this->getCollection() + ->addFieldToFilter('item_id', array('eq' => $itemId)) + ->addFieldToFilter('line_id', array('notnull' => true)) + ->getLastItem(); + + return $orderLine; } /** @@ -353,8 +358,8 @@ public function getOpenForShipmentQty($orderId) ->addFieldToFilter('type', array('eq' => 'physical')) ->addExpressionFieldToSelect( 'open', - 'SUM(qty_paid - qty_shipped - qty_refunded)', - array('qty_paid', 'qty_shipped', 'qty_refunded') + 'SUM(qty_ordered - qty_shipped - qty_refunded)', + array('qty_ordered', 'qty_shipped', 'qty_refunded') ); $orderLinesCollection->getSelect()->group('order_id'); @@ -380,8 +385,8 @@ public function getOpenForRefundQty($orderId) ->addFieldToFilter('type', array('in' => array('physical', 'digital'))) ->addExpressionFieldToSelect( 'open', - 'SUM(qty_paid - qty_refunded)', - array('qty_paid', 'qty_refunded') + 'SUM(qty_ordered - qty_refunded)', + array('qty_ordered', 'qty_refunded') ); $orderLinesCollection->getSelect()->group('order_id'); @@ -393,5 +398,4 @@ public function getOpenForRefundQty($orderId) return $qty; } -} - +} \ No newline at end of file diff --git a/app/code/community/Mollie/Mpm/Model/Resource/OrderLines.php b/app/code/community/Mollie/Mpm/Model/Resource/OrderLines.php index 048f7ee8..54651772 100644 --- a/app/code/community/Mollie/Mpm/Model/Resource/OrderLines.php +++ b/app/code/community/Mollie/Mpm/Model/Resource/OrderLines.php @@ -79,6 +79,12 @@ protected function _beforeSave(Mage_Core_Model_Abstract $object) $object->setData('vat_amount', $vatAmountValue); } + $gmtDate = Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s'); + $object->setData('updated_at', $gmtDate); + if (!$object->getId()) { + $object->setData('created_at', $gmtDate); + } + return parent::_beforeSave($object); } diff --git a/app/code/community/Mollie/Mpm/etc/config.xml b/app/code/community/Mollie/Mpm/etc/config.xml index 9b139e67..00e66964 100644 --- a/app/code/community/Mollie/Mpm/etc/config.xml +++ b/app/code/community/Mollie/Mpm/etc/config.xml @@ -33,7 +33,7 @@ - 5.0.1 + 5.0.2 @@ -109,7 +109,7 @@ - + singleton @@ -117,7 +117,7 @@ salesOrderShipmentSaveBefore - + diff --git a/app/design/adminhtml/default/default/template/mollie/mpm/payment/form.phtml b/app/design/adminhtml/default/default/template/mollie/mpm/payment/form.phtml index fa662a61..60d0ee75 100644 --- a/app/design/adminhtml/default/default/template/mollie/mpm/payment/form.phtml +++ b/app/design/adminhtml/default/default/template/mollie/mpm/payment/form.phtml @@ -31,7 +31,33 @@ * @license http://www.opensource.org/licenses/bsd-license.php BSD-License 2 */ ?> -getMethodCode() ?> -