From e616236ba88f51be5b812de5e9baa5466f31a525 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Tue, 18 Dec 2018 10:14:58 +0100 Subject: [PATCH 1/3] Fix for discount on shipping line --- Model/OrderLines.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Model/OrderLines.php b/Model/OrderLines.php index 11e5df2f093..b91d1e91eba 100644 --- a/Model/OrderLines.php +++ b/Model/OrderLines.php @@ -133,15 +133,24 @@ public function getOrderLines(Order $order) } if (!$order->getIsVirtual()) { - $totalAmount = $forceBaseCurrency ? $order->getBaseShippingInclTax() : $order->getShippingInclTax(); - $vatRate = $this->getShippingVatRate($order); + $baseShipping = $forceBaseCurrency ? $order->getBaseShippingAmount() : $order->getShippingAmount(); + $rowTotalInclTax = $forceBaseCurrency ? $baseShipping + $order->getBaseShippingTaxAmount() : $baseShipping + $order->getShippingTaxAmount(); + $discountAmount = $forceBaseCurrency ? $order->getBaseShippingDiscountAmount() : $order->getShippingDiscountAmount(); + + /** + * The total amount of the line, including VAT and discounts + * Should Match: (unitPrice × quantity) - discountAmount + * NOTE: TotalAmount can differ from actutal Total Amount due to rouding in tax or exchange rate + */ + $totalAmount = $rowTotalInclTax - $discountAmount; /** * The amount of VAT on the line. * Should Match: totalAmount × (vatRate / (100 + vatRate)). - * Due to Mollie API requirements, we calculate this instead of using $item->getTaxAmount() to overcome + * Due to Mollie API requirements, we calculate this instead of using $order->getBaseShippingTaxAmount() to overcome * any rouding issues. */ + $vatRate = $this->getShippingVatRate($order); $vatAmount = round($totalAmount * ($vatRate / (100 + $vatRate)), 2); $orderLines[] = [ @@ -149,9 +158,9 @@ public function getOrderLines(Order $order) 'type' => 'shipping_fee', 'name' => preg_replace("/[^A-Za-z0-9 -]/", "", $order->getShippingDescription()), 'quantity' => 1, - 'unitPrice' => $this->mollieHelper->getAmountArray($currency, $totalAmount), + 'unitPrice' => $this->mollieHelper->getAmountArray($currency, $rowTotalInclTax), 'totalAmount' => $this->mollieHelper->getAmountArray($currency, $totalAmount), - 'discountAmount' => $this->mollieHelper->getAmountArray($currency, '0'), + 'discountAmount' => $this->mollieHelper->getAmountArray($currency, $discountAmount), 'vatRate' => sprintf("%.2f", $vatRate), 'vatAmount' => $this->mollieHelper->getAmountArray($currency, $vatAmount), 'sku' => $order->getShippingMethod() From 8c040e274e4b4b606aab83dd73a97a42802d1185 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Tue, 18 Dec 2018 10:59:48 +0100 Subject: [PATCH 2/3] Added KBC/CBC issuer list option (dropdown, radio or none) --- Helper/General.php | 12 +--- Model/Mollie.php | 2 +- Model/MollieConfigProvider.php | 9 +++ etc/adminhtml/methods/kbc.xml | 12 +++- etc/config.xml | 3 +- view/frontend/web/css/styles.css | 10 +++ .../web/js/view/payment/method-renderer.js | 3 +- .../js/view/payment/method-renderer/kbc.js | 51 +++++++++++++ view/frontend/web/template/payment/kbc.html | 72 +++++++++++++++++++ 9 files changed, 161 insertions(+), 13 deletions(-) create mode 100755 view/frontend/web/js/view/payment/method-renderer/kbc.js create mode 100644 view/frontend/web/template/payment/kbc.html diff --git a/Helper/General.php b/Helper/General.php index c5c488fba10..609b5a48e5e 100755 --- a/Helper/General.php +++ b/Helper/General.php @@ -70,12 +70,11 @@ class General extends AbstractHelper const XML_PATH_IMAGES = 'payment/mollie_general/payment_images'; const XML_PATH_USE_BASE_CURRENCY = 'payment/mollie_general/currency'; const XML_PATH_SHOW_TRANSACTION_DETAILS = 'payment/mollie_general/transaction_details'; - const XML_PATH_IDEAL_ISSUER_LIST_TYPE = 'payment/mollie_methods_ideal/issuer_list_type'; const XML_PATH_ADD_QR = 'payment/mollie_methods_ideal/add_qr'; - const XML_PATH_GIFTCARD_ISSUER_LIST_TYPE = 'payment/mollie_methods_giftcard/issuer_list_type'; const XML_PATH_PAYMENTLINK_ADD_MESSAGE = 'payment/mollie_methods_paymentlink/add_message'; const XML_PATH_PAYMENTLINK_MESSAGE = 'payment/mollie_methods_paymentlink/message'; const XML_PATH_API_METHOD = 'payment/%method%/method'; + const XPATH_ISSUER_LIST_TYPE = 'payment/%method%/issuer_list_type'; /** * @var ProductMetadataInterface @@ -311,13 +310,8 @@ public function useImage($storeId = null) */ public function getIssuerListType($method) { - if ($method == 'mollie_methods_ideal') { - return $this->getStoreConfig(self::XML_PATH_IDEAL_ISSUER_LIST_TYPE); - } - - if ($method == 'mollie_methods_giftcard') { - return $this->getStoreConfig(self::XML_PATH_GIFTCARD_ISSUER_LIST_TYPE); - } + $methodXpath = str_replace('%method%', $method, self::XPATH_ISSUER_LIST_TYPE); + return $this->getStoreConfig($methodXpath); } /** diff --git a/Model/Mollie.php b/Model/Mollie.php index b6b36900f34..624a3dac322 100644 --- a/Model/Mollie.php +++ b/Model/Mollie.php @@ -494,7 +494,7 @@ public function getIssuers($mollieApi, $method, $issuerListType) ]); } - if ($this->mollieHelper->addQrOption()) { + if ($this->mollieHelper->addQrOption() && $methodCode == 'ideal') { $issuers[] = [ 'resource' => 'issuer', 'id' => '', diff --git a/Model/MollieConfigProvider.php b/Model/MollieConfigProvider.php index 3d3bd82cd49..9ae700bf1a1 100644 --- a/Model/MollieConfigProvider.php +++ b/Model/MollieConfigProvider.php @@ -162,6 +162,15 @@ public function getConfig() $issuerListType ); } + if ($code == 'mollie_methods_kbc') { + $issuerListType = $this->mollieHelper->getIssuerListType($code); + $config['payment']['issuersListType'][$code] = $issuerListType; + $config['payment']['issuers'][$code] = $this->mollieModel->getIssuers( + $mollieApi, + $code, + $issuerListType + ); + } if ($code == 'mollie_methods_giftcard') { $issuerListType = $this->mollieHelper->getIssuerListType($code); $config['payment']['issuersListType'][$code] = $issuerListType; diff --git a/etc/adminhtml/methods/kbc.xml b/etc/adminhtml/methods/kbc.xml index 4b494f0c5b4..e1d3911892a 100644 --- a/etc/adminhtml/methods/kbc.xml +++ b/etc/adminhtml/methods/kbc.xml @@ -3,7 +3,7 @@ xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd"> - + @@ -30,6 +30,16 @@ Order API
Use the new Order API Platform and get additional insights in the orders. Read more.]]>
+ + + payment/mollie_methods_kbc/issuer_list_type + Mollie\Payment\Model\Adminhtml\Source\IssuerListType + + + 1 + + diff --git a/etc/config.xml b/etc/config.xml index 50c59e2fcaa..d667cb99d8b 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -69,8 +69,9 @@ 0 Mollie\Payment\Model\Methods\Kbc - KBC + KBC/CBC order + none 0 diff --git a/view/frontend/web/css/styles.css b/view/frontend/web/css/styles.css index 390774b83f1..b2943b88fd9 100644 --- a/view/frontend/web/css/styles.css +++ b/view/frontend/web/css/styles.css @@ -71,6 +71,16 @@ max-height: 30px; } +.checkout-payment-method #mollie_methods_kbc-form .label { + height: 35px; + display: inline-block; +} + +.checkout-payment-method #mollie_methods_kbc-form .payment-icon { + width: 35px; + max-height: 30px; +} + .checkout-payment-method #mollie_methods_giftcard-form .label { height: 40px; display: inline-block; diff --git a/view/frontend/web/js/view/payment/method-renderer.js b/view/frontend/web/js/view/payment/method-renderer.js index 609c62204a4..a4e5795437a 100644 --- a/view/frontend/web/js/view/payment/method-renderer.js +++ b/view/frontend/web/js/view/payment/method-renderer.js @@ -12,6 +12,7 @@ define( 'use strict'; var defaultComponent = 'Mollie_Payment/js/view/payment/method-renderer/default'; var idealComponent = 'Mollie_Payment/js/view/payment/method-renderer/ideal'; + var kbcComponent = 'Mollie_Payment/js/view/payment/method-renderer/kbc'; var giftcardComponent = 'Mollie_Payment/js/view/payment/method-renderer/giftcard'; var methods = [ {type: 'mollie_methods_bancontact', component: defaultComponent}, @@ -20,7 +21,7 @@ define( {type: 'mollie_methods_bitcoin', component: defaultComponent}, {type: 'mollie_methods_creditcard', component: defaultComponent}, {type: 'mollie_methods_ideal', component: idealComponent}, - {type: 'mollie_methods_kbc', component: defaultComponent}, + {type: 'mollie_methods_kbc', component: kbcComponent}, {type: 'mollie_methods_paypal', component: defaultComponent}, {type: 'mollie_methods_paysafecard', component: defaultComponent}, {type: 'mollie_methods_sofort', component: defaultComponent}, diff --git a/view/frontend/web/js/view/payment/method-renderer/kbc.js b/view/frontend/web/js/view/payment/method-renderer/kbc.js new file mode 100755 index 00000000000..1c76e3e05be --- /dev/null +++ b/view/frontend/web/js/view/payment/method-renderer/kbc.js @@ -0,0 +1,51 @@ +define( + [ + 'ko', + 'jquery', + 'Mollie_Payment/js/view/payment/method-renderer/default' + ], + function (ko, $, Component) { + var checkoutConfig = window.checkoutConfig.payment; + 'use strict'; + return Component.extend( + { + defaults: { + template: 'Mollie_Payment/payment/kbc', + selectedIssuer: null + }, + getForm: function () { + return $('#' + this.item.method + '-form'); + }, + getIssuers: function () { + return checkoutConfig.issuers[this.item.method]; + }, + getIssuerListType: function () { + return checkoutConfig.issuersListType[this.item.method]; + }, + getSelectedIssuer: function () { + if (this.getIssuerListType() === 'radio') { + return $('input[name=issuer]:checked', this.getForm()).val(); + } + if (this.getIssuerListType() === 'dropdown') { + return this.selectedIssuer; + } + }, + getData: function () { + return { + 'method': this.item.method, + 'additional_data': { + "selected_issuer": this.getSelectedIssuer() + } + }; + }, + validate: function () { + var $form = this.getForm(); + if (this.getIssuerListType() === 'radio') { + return $form.validation() && $form.validation('isValid'); + } + return $form.validation(); + } + } + ); + } +); \ No newline at end of file diff --git a/view/frontend/web/template/payment/kbc.html b/view/frontend/web/template/payment/kbc.html new file mode 100644 index 00000000000..b997c335900 --- /dev/null +++ b/view/frontend/web/template/payment/kbc.html @@ -0,0 +1,72 @@ +
+
+ + + +
+
+ + + + + + +
+ + +
+
+ + +
+
+ +
+ + +
+
+
+
+
+ + + +
+ + + +
+ +
+ + + +
+
+
+ +
+
+
+
From f4cd5e7e874e68ebbe30d80dd2c0a59245c485dd Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Tue, 18 Dec 2018 11:00:18 +0100 Subject: [PATCH 3/3] Version bump --- composer.json | 2 +- etc/module.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d1ad486c7b0..4062d2ff183 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/magento2", "description": "Mollie Payment Module for Magento 2", - "version": "1.4.4", + "version": "1.4.5", "require": { "mollie/mollie-api-php": "^2.1", "magento/framework": ">=100.1.0", diff --git a/etc/module.xml b/etc/module.xml index d1843c82a8e..b481d687bb7 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,4 +1,4 @@ - +