From e402c34d0ba12ae29ab01c8bf213820c41dfe67e Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 18 Dec 2017 11:34:21 +0100 Subject: [PATCH] 1.1.4 --- Helper/General.php | 59 +++++++++++++++ Model/Adminhtml/Source/Locale.php | 72 +++++++++++++++++++ Model/Mollie.php | 14 +++- Model/MollieConfigProvider.php | 57 +++++++-------- composer.json | 2 +- etc/adminhtml/system.xml | 7 ++ etc/module.xml | 2 +- etc/payment.xml | 22 +++--- view/frontend/layout/checkout_index_index.xml | 5 +- view/frontend/web/css/styles.css | 10 ++- .../web/template/payment/default.html | 2 +- .../web/template/payment/giftcard.html | 2 +- view/frontend/web/template/payment/ideal.html | 2 +- 13 files changed, 207 insertions(+), 49 deletions(-) create mode 100644 Model/Adminhtml/Source/Locale.php diff --git a/Helper/General.php b/Helper/General.php index de5bef8140e..7b89a99bb4b 100644 --- a/Helper/General.php +++ b/Helper/General.php @@ -12,6 +12,7 @@ use Magento\Framework\Module\ModuleListInterface; use Magento\Config\Model\ResourceModel\Config; use Magento\Framework\App\ProductMetadataInterface; +use Magento\Framework\Locale\Resolver; use Mollie\Payment\Logger\MollieLogger; class General extends AbstractHelper @@ -28,6 +29,8 @@ class General extends AbstractHelper const XML_PATH_STATUS_PENDING = 'payment/mollie_general/order_status_pending'; const XML_PATH_STATUS_PENDING_BANKTRANSFER = 'payment/mollie_methods_banktransfer/order_status_pending'; const XML_PATH_INVOICE_NOTIFY = 'payment/mollie_general/invoice_notify'; + const XML_PATH_LOCALE = 'payment/mollie_general/locale'; + const XML_PATH_IMAGES = 'payment/mollie_general/payment_images'; protected $metadata; protected $storeManager; @@ -38,6 +41,11 @@ class General extends AbstractHelper protected $apiCheck; protected $apiKey; + /** + * @var Resolver + */ + private $resolver; + /** * General constructor. * @@ -46,6 +54,7 @@ class General extends AbstractHelper * @param Config $resourceConfig * @param ModuleListInterface $moduleList * @param ProductMetadataInterface $metadata + * @param Resolver $resolver * @param MollieLogger $logger */ public function __construct( @@ -54,6 +63,7 @@ public function __construct( Config $resourceConfig, ModuleListInterface $moduleList, ProductMetadataInterface $metadata, + Resolver $resolver, MollieLogger $logger ) { $this->storeManager = $storeManager; @@ -61,6 +71,7 @@ public function __construct( $this->urlBuilder = $context->getUrlBuilder(); $this->moduleList = $moduleList; $this->metadata = $metadata; + $this->resolver = $resolver; $this->logger = $logger; parent::__construct($context); } @@ -204,6 +215,21 @@ public function useLoadingScreen($storeId) return $this->getStoreConfig(self::XML_PATH_LOADING_SCREEN, $storeId); } + + /** + * @param $storeId + * + * @return mixed + */ + public function useImage($storeId = null) + { + if ($storeId == null) { + $storeId = $this->storeManager->getStore()->getId(); + } + + return $this->getStoreConfig(self::XML_PATH_IMAGES, $storeId); + } + /** * Disable extension function. * Used when Mollie API is not installed @@ -331,6 +357,39 @@ public function sendInvoice($storeId = 0) return (int)$this->getStoreConfig(self::XML_PATH_INVOICE_NOTIFY, $storeId); } + /** + * @return string + */ + public function getLocaleCode() + { + $locale = $this->getStoreConfig(self::XML_PATH_LOCALE); + + if (!$locale) { + return ''; + } + + if ($locale == 'store') { + $localeCode = $this->resolver->getLocale(); + if (in_array($localeCode, $this->getSupportedLocal())) { + return $localeCode; + } else { + return ''; + } + } + + return $locale; + } + + /** + * List of supported local codes Mollie. + * + * @return array + */ + public function getSupportedLocal() + { + return ['en_US', 'de_AT', 'de_CH', 'de_DE', 'es_ES', 'fr_BE', 'fr_FR', 'nl_BE', 'nl_NL']; + } + /** * Returns array of active methods with maximum order value * diff --git a/Model/Adminhtml/Source/Locale.php b/Model/Adminhtml/Source/Locale.php new file mode 100644 index 00000000000..476700b9e98 --- /dev/null +++ b/Model/Adminhtml/Source/Locale.php @@ -0,0 +1,72 @@ +options) { + $this->options = [ + [ + 'value' => '', + 'label' => __('Autodetect') + ], + [ + 'value' => 'store', + 'label' => __('Store Locale') + ], + [ + 'value' => 'en_US', + 'label' => __('en_US') + ], + [ + 'value' => 'de_AT', + 'label' => __('de_AT') + ], + [ + 'value' => 'de_CH', + 'label' => __('de_CH') + ], + [ + 'value' => 'de_DE', + 'label' => __('de_DE') + ], + [ + 'value' => 'es_ES', + 'label' => __('es_ES') + ], + [ + 'value' => 'fr_BE', + 'label' => __('fr_BE') + ], + [ + 'value' => 'nl_BE', + 'label' => __('nl_BE') + ], + [ + 'value' => 'nl_NL', + 'label' => __('nl_NL') + ], + ]; + } + return $this->options; + } +} diff --git a/Model/Mollie.php b/Model/Mollie.php index f08261c7842..ca03b2cdce6 100644 --- a/Model/Mollie.php +++ b/Model/Mollie.php @@ -145,7 +145,8 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) * @param string $paymentAction * @param object $stateObject * - * @return $this + * @return void + * @throws \Magento\Framework\Exception\LocalizedException */ public function initialize($paymentAction, $stateObject) { @@ -166,6 +167,7 @@ public function initialize($paymentAction, $stateObject) * @param \Magento\Sales\Model\Order $order * * @return bool + * @throws \Exception */ public function startTransaction(Order $order) { @@ -204,7 +206,8 @@ public function startTransaction(Order $order) 'metadata' => [ 'order_id' => $orderId, 'store_id' => $order->getStoreId() - ] + ], + 'locale' => $this->mollieHelper->getLocaleCode() ]; if ($billingAddress) { @@ -265,6 +268,7 @@ public function loadMollieApi($apiKey) * @param string $type * * @return array + * @throws \Exception */ public function processTransaction($orderId, $type = 'webhook') { @@ -303,6 +307,9 @@ public function processTransaction($orderId, $type = 'webhook') if (($paymentData->isPaid() == true) && ($paymentData->isRefunded() == false)) { $amount = $paymentData->amount; + if (abs($paymentData->amount - $order->getBaseGrandTotal()) < 0.01) { + $amount = $order->getBaseGrandTotal(); + } $payment = $order->getPayment(); if (!$payment->getIsTransactionClosed() && $type == 'webhook') { @@ -366,6 +373,8 @@ public function processTransaction($orderId, $type = 'webhook') * @param \Magento\Sales\Model\Order $order * * @return bool + * @throws \Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function cancelOrder($order) { @@ -384,6 +393,7 @@ protected function cancelOrder($order) * @param \Magento\Framework\DataObject $data * * @return $this + * @throws \Magento\Framework\Exception\LocalizedException */ public function assignData(DataObject $data) { diff --git a/Model/MollieConfigProvider.php b/Model/MollieConfigProvider.php index 9674dccae72..d575507c8cd 100644 --- a/Model/MollieConfigProvider.php +++ b/Model/MollieConfigProvider.php @@ -13,14 +13,10 @@ use Magento\Payment\Helper\Data as PaymentHelper; use Magento\Framework\View\Asset\Repository as AssetRepository; use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Store\Model\ScopeInterface; -use Magento\Store\Model\StoreManagerInterface; class MollieConfigProvider implements ConfigProviderInterface { - const XML_PATH_IMAGES = 'payment/mollie_general/payment_images'; - protected $methodCodes = [ 'mollie_methods_bancontact', 'mollie_methods_banktransfer', @@ -42,17 +38,17 @@ class MollieConfigProvider implements ConfigProviderInterface protected $storeManager; protected $mollieModel; protected $mollieHelper; + protected $paymentHelper; /** * MollieConfigProvider constructor. * - * @param Mollie $mollieModel - * @param MollieHelper $mollieHelper - * @param PaymentHelper $paymentHelper - * @param AssetRepository $assetRepository - * @param ScopeConfigInterface $scopeConfig - * @param StoreManagerInterface $storeManager - * @param Escaper $escaper + * @param Mollie $mollieModel + * @param MollieHelper $mollieHelper + * @param PaymentHelper $paymentHelper + * @param AssetRepository $assetRepository + * @param ScopeConfigInterface $scopeConfig + * @param Escaper $escaper */ public function __construct( MollieModel $mollieModel, @@ -60,18 +56,30 @@ public function __construct( PaymentHelper $paymentHelper, AssetRepository $assetRepository, ScopeConfigInterface $scopeConfig, - StoreManagerInterface $storeManager, Escaper $escaper ) { $this->mollieModel = $mollieModel; $this->mollieHelper = $mollieHelper; + $this->paymentHelper = $paymentHelper; $this->escaper = $escaper; $this->assetRepository = $assetRepository; $this->scopeConfig = $scopeConfig; - $this->storeManager = $storeManager; - foreach ($this->methodCodes as $code) { - $this->methods[$code] = $paymentHelper->getMethodInstance($code); + $this->methods[$code] = $this->getMethodInstance($code); + } + } + + /** + * @param $code + * + * @return \Magento\Payment\Model\MethodInterface + */ + public function getMethodInstance($code) + { + try { + return $this->paymentHelper->getMethodInstance($code); + } catch (\Exception $e) { + $this->mollieHelper->addTolog('error', 'Function: getMethodInstance: ' . $e->getMessage()); } } @@ -84,6 +92,7 @@ public function getConfig() { $config = []; $apiKey = $this->mollieHelper->getApiKey(); + $useImage = $this->mollieHelper->useImage(); try { $mollieApi = $this->mollieModel->loadMollieApi($apiKey); @@ -99,9 +108,13 @@ public function getConfig() if (!empty($activeMethods[$code])) { $config['payment']['isActive'][$code] = true; $config['payment']['instructions'][$code] = $this->getInstructions($code); - $config['payment']['image'][$code] = (isset($activeMethods[$code]['image']) ? $activeMethods[$code]['image'] : ''); $config['payment']['min'][$code] = (isset($activeMethods[$code]['min']) ? $activeMethods[$code]['min'] : ''); $config['payment']['max'][$code] = (isset($activeMethods[$code]['max']) ? $activeMethods[$code]['max'] : ''); + if ($useImage && isset($activeMethods[$code]['image'])) { + $config['payment']['image'][$code] = $activeMethods[$code]['image']; + } else { + $config['payment']['image'][$code] = ''; + } if ($code == 'mollie_methods_ideal') { $config['payment']['issuers'][$code] = $this->getIdealIssuers($mollieApi); } @@ -194,16 +207,4 @@ public function getGiftcardIssuers($mollieApi) return []; } - /** - * Get Store Config Value - * - * @param $path - * - * @return mixed - */ - public function getStoreConfig($path) - { - $storeId = $this->storeManager->getStore()->getId(); - return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId); - } } diff --git a/composer.json b/composer.json index dc6943329f0..0074b8c7043 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/magento2", "description": "Mollie Payment Module for Magento 2", - "version": "1.1.3", + "version": "1.1.4", "require": { "php": "~5.6.5|7.0.2|7.0.4|~7.0.6|~7.1.0", "mollie/mollie-api-php": "^1.9.3" diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index f7e58f66b12..3568dac0eca 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -102,6 +102,13 @@ payment/mollie_general/invoice_notify + + + Mollie\Payment\Model\Adminhtml\Source\Locale + payment/mollie_general/locale + + diff --git a/etc/module.xml b/etc/module.xml index 52b30546b52..98df00f4ddc 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,5 +1,5 @@ - + diff --git a/etc/payment.xml b/etc/payment.xml index 4c643e78901..63aa13b601a 100644 --- a/etc/payment.xml +++ b/etc/payment.xml @@ -2,37 +2,37 @@ - 1 + 0 - 1 + 0 - 1 + 0 - 1 + 0 - 1 + 0 - 1 + 0 - 1 + 0 - 1 + 0 - 1 + 0 - 1 + 0 - 1 + 0 diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 3dace02c1ea..64b53838f66 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -1,5 +1,8 @@ - + + + + diff --git a/view/frontend/web/css/styles.css b/view/frontend/web/css/styles.css index 54692768485..a7a524ce907 100644 --- a/view/frontend/web/css/styles.css +++ b/view/frontend/web/css/styles.css @@ -3,9 +3,15 @@ text-align: center; } +.mollie-payment-icon { + width: 25px; + margin-right: 5px; + vertical-align: middle; +} + .mollie-loading .loader { - border: 16px solid #e3f0fa; - border-top: 16px solid #31a8f0; + border: 16px solid #E3F0FA; + border-top: 16px solid #31A8F0; border-radius: 50%; width: 50px; height: 50px; diff --git a/view/frontend/web/template/payment/default.html b/view/frontend/web/template/payment/default.html index e27e53efae3..5162fb7e1ec 100644 --- a/view/frontend/web/template/payment/default.html +++ b/view/frontend/web/template/payment/default.html @@ -6,7 +6,7 @@ data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/> diff --git a/view/frontend/web/template/payment/giftcard.html b/view/frontend/web/template/payment/giftcard.html index b815f7b5d77..bff85633987 100644 --- a/view/frontend/web/template/payment/giftcard.html +++ b/view/frontend/web/template/payment/giftcard.html @@ -6,7 +6,7 @@ data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/> diff --git a/view/frontend/web/template/payment/ideal.html b/view/frontend/web/template/payment/ideal.html index 675b48d66c6..b1b7c5b3d1e 100644 --- a/view/frontend/web/template/payment/ideal.html +++ b/view/frontend/web/template/payment/ideal.html @@ -6,7 +6,7 @@ data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>