Skip to content

Commit

Permalink
Merge pull request #95 from mollie/5.0.2
Browse files Browse the repository at this point in the history
5.0.2
  • Loading branch information
Marvin-Magmodules authored Dec 20, 2018
2 parents 126822d + 3788452 commit 1e0bd99
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 35 deletions.
52 changes: 33 additions & 19 deletions app/code/community/Mollie/Mpm/Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down
10 changes: 7 additions & 3 deletions app/code/community/Mollie/Mpm/Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Method/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
15 changes: 15 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Method/Kbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
15 changes: 15 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Method/Paymentlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
1 change: 1 addition & 0 deletions app/code/community/Mollie/Mpm/Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 12 additions & 8 deletions app/code/community/Mollie/Mpm/Model/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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');

Expand All @@ -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');

Expand All @@ -393,5 +398,4 @@ public function getOpenForRefundQty($orderId)

return $qty;
}
}

}
6 changes: 6 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Resource/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions app/code/community/Mollie/Mpm/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<config>
<modules>
<Mollie_Mpm>
<version>5.0.1</version>
<version>5.0.2</version>
</Mollie_Mpm>
</modules>
<global>
Expand Down Expand Up @@ -109,15 +109,15 @@
</mollie_sales_order_creditmemo_save_after>
</observers>
</sales_order_creditmemo_save_after>
<sales_order_shipment_save_after>
<sales_order_shipment_save_before>
<observers>
<mollie_sales_order_shipment_save_after>
<type>singleton</type>
<class>Mollie_Mpm_Model_Observer</class>
<method>salesOrderShipmentSaveBefore</method>
</mollie_sales_order_shipment_save_after>
</observers>
</sales_order_shipment_save_after>
</sales_order_shipment_save_before>
<sales_order_shipment_track_save_after>
<observers>
<mollie_sales_order_shipment_track_save_after>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,33 @@
* @license http://www.opensource.org/licenses/bsd-license.php BSD-License 2
*/
?>
<?php $_code=$this->getMethodCode() ?>
<ul id="payment_form_<?php echo $_code ?>" style="display:none">
<?php $_code = $this->getMethodCode() ?>
<ul id="payment_form_<?= $_code ?>" style="display:none">
<?= $this->__('Create a Mollie Payment link and add this to the order email.'); ?>
<ul class="inner-form">
<li>
<label for="<?= $_code ?>_methods"><?= $this->__('Limit to the following method(s)') ?>:</label>
<div class="input-box">
<select id="<?= $_code ?>_methods" name="limited_methods[]" multiple>
<option value="bancontact">Bancontact</option>
<option value="banktransfer">Banktransfer</option>
<option value="belfius">Belfius</option>
<option value="bitcoin">Bitcoin</option>
<option value="creditcard">Creditcard</option>
<option value="eps">EPS</option>
<option value="giftcard">Giftcard</option>
<option value="giropay">Giropay</option>
<option value="ideal">iDEAL</option>
<option value="inghomepay">ING Homepay</option>
<option value="kbc">KBC/CBC</option>
<option value="klarnapaylater">Klarna Pay Later</option>
<option value="klarnasliceit">Klarna Slice It</option>
<option value="paypal">Paypal</option>
<option value="paysafecard">Paysafecard</option>
<option value="sofort">Sofort</option>
</select>
</div>
<p><?= $this->__('If one method is chosen, it will skip the selection screen and the customer is sent directly to the payment method.'); ?></p>
</li>
</ul>
</ul>
21 changes: 21 additions & 0 deletions skin/adminhtml/default/default/mollie/mpm/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,25 @@ a.mollie-tooltip:hover span {
height: 30px;
display: -webkit-inline-box;
float: left;
}

#mollie_paymentlink_methods {
width: 300px;
border: 0px;
min-height: 260px;
padding: 5px;
border: 1px solid #D6D6D6;
display: block;
}

#payment_form_mollie_paymentlink label {
color: black;
font-weight: normal;
}

#payment_form_mollie_paymentlink p {
margin-top: 10px;
color: #333D46;
font-weight: lighter;
line-height: normal;
}

0 comments on commit 1e0bd99

Please sign in to comment.