Skip to content

Commit

Permalink
Merge pull request #103 from mollie/1.4.5
Browse files Browse the repository at this point in the history
1.4.5
  • Loading branch information
Marvin-Magmodules authored Dec 18, 2018
2 parents 473365a + f4cd5e7 commit 988b8f8
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 20 deletions.
12 changes: 3 additions & 9 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public function getIssuers($mollieApi, $method, $issuerListType)
]);
}

if ($this->mollieHelper->addQrOption()) {
if ($this->mollieHelper->addQrOption() && $methodCode == 'ideal') {
$issuers[] = [
'resource' => 'issuer',
'id' => '',
Expand Down
9 changes: 9 additions & 0 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 14 additions & 5 deletions Model/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,34 @@ 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[] = [
'item_id' => '',
'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()
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 11 additions & 1 deletion etc/adminhtml/methods/kbc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="mollie_methods_kbc" translate="label" type="text" sortOrder="8" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>KBC</label>
<label>KBC/CBC</label>
<field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Enabled</label>
Expand All @@ -30,6 +30,16 @@
<strong>Order API</strong><br>Use the new Order API Platform and get additional insights in the orders.
Read <a href="https://docs.mollie.com/orders/why-use-orders" target="_blank" >more.</a>]]></comment>
</field>
<field id="issuer_list_type" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Issuer List Style</label>
<config_path>payment/mollie_methods_kbc/issuer_list_type</config_path>
<source_model>Mollie\Payment\Model\Adminhtml\Source\IssuerListType</source_model>
<comment><![CDATA[Select the way you want to show the issuer list in the checkout.]]></comment>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="96" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Payment from Applicable Countries</label>
Expand Down
3 changes: 2 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@
<mollie_methods_kbc>
<active>0</active>
<model>Mollie\Payment\Model\Methods\Kbc</model>
<title>KBC</title>
<title>KBC/CBC</title>
<payment_action>order</payment_action>
<issuer_list_type>none</issuer_list_type>
<allowspecific>0</allowspecific>
<instructions/>
</mollie_methods_kbc>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mollie_Payment" setup_version="1.4.4" />
<module name="Mollie_Payment" setup_version="1.4.5" />
</config>
10 changes: 10 additions & 0 deletions view/frontend/web/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion view/frontend/web/js/view/payment/method-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down
51 changes: 51 additions & 0 deletions view/frontend/web/js/view/payment/method-renderer/kbc.js
Original file line number Diff line number Diff line change
@@ -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();
}
}
);
}
);
72 changes: 72 additions & 0 deletions view/frontend/web/template/payment/kbc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="payment-method-title field choice">
<input type="radio"
name="payment[method]"
class="radio"
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
<label data-bind="attr: {'for': getCode()}" class="label">
<!-- ko if: getMethodImage() -->
<img data-bind="attr: {src: getMethodImage()}" class="mollie-payment-icon"/>
<!--/ko-->
<span data-bind="text: getTitle()"></span>
</label>

</div>
<div class="payment-method-content">
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->

<!-- ko if: getIssuers() -->
<!-- ko if: getIssuerListType() == 'dropdown' -->
<div class="field-select-billing">
<strong><span data-bind="i18n: 'Select Bank'"></span></strong>
<select data-bind="options: getIssuers(), optionsText: 'name', optionsValue: 'id', value: selectedIssuer"></select>
</div>
<br/>
<!--/ko-->
<!-- ko if: getIssuerListType() == 'radio' -->
<div class="payment-method-title field choice">
<form class="form" data-bind="attr: {'id': getCode() + '-form'}">
<strong><span data-bind="i18n: 'Select Bank'"></span></strong>
<div data-bind="foreach: {data: getIssuers(), as :'issuer' }" class="field choice">
<input type="radio" name="issuer" data-bind="attr: {value: issuer.id}" class="radio" data-validate="{'validate-one-required-by-name':true}">
<label data-bind="attr: {'for': issuer.id}" class="label">
<img data-bind="attr: {src: issuer.image.size2x}" class="payment-icon"/>
<span data-bind="text: issuer.name"></span>
</label>
<br/>
</div>
</form>
</div>
<br/>
<!--/ko-->
<!--/ko-->

<div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>

<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout"
type="submit"
data-bind="
click: placeOrder,
attr: {title: $t('Place Order')},
css: {disabled: !isPlaceOrderActionAllowed()},
enable: (getCode() == isChecked())"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
</button>
</div>
</div>
</div>
</div>

0 comments on commit 988b8f8

Please sign in to comment.