Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1.4 #44

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -38,6 +41,11 @@ class General extends AbstractHelper
protected $apiCheck;
protected $apiKey;

/**
* @var Resolver
*/
private $resolver;

/**
* General constructor.
*
Expand All @@ -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(
Expand All @@ -54,13 +63,15 @@ public function __construct(
Config $resourceConfig,
ModuleListInterface $moduleList,
ProductMetadataInterface $metadata,
Resolver $resolver,
MollieLogger $logger
) {
$this->storeManager = $storeManager;
$this->resourceConfig = $resourceConfig;
$this->urlBuilder = $context->getUrlBuilder();
$this->moduleList = $moduleList;
$this->metadata = $metadata;
$this->resolver = $resolver;
$this->logger = $logger;
parent::__construct($context);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down
72 changes: 72 additions & 0 deletions Model/Adminhtml/Source/Locale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © 2017 Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Model\Adminhtml\Source;

use Magento\Framework\Option\ArrayInterface;

class Locale implements ArrayInterface
{

/**
* Options array
*
* @var array
*/
public $options = null;

/**
* @return array
*/
public function toOptionArray()
{
if (!$this->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;
}
}
14 changes: 12 additions & 2 deletions Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -166,6 +167,7 @@ public function initialize($paymentAction, $stateObject)
* @param \Magento\Sales\Model\Order $order
*
* @return bool
* @throws \Exception
*/
public function startTransaction(Order $order)
{
Expand Down Expand Up @@ -204,7 +206,8 @@ public function startTransaction(Order $order)
'metadata' => [
'order_id' => $orderId,
'store_id' => $order->getStoreId()
]
],
'locale' => $this->mollieHelper->getLocaleCode()
];

if ($billingAddress) {
Expand Down Expand Up @@ -265,6 +268,7 @@ public function loadMollieApi($apiKey)
* @param string $type
*
* @return array
* @throws \Exception
*/
public function processTransaction($orderId, $type = 'webhook')
{
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
57 changes: 29 additions & 28 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -42,36 +38,48 @@ 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,
MollieHelper $mollieHelper,
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());
}
}

Expand All @@ -84,6 +92,7 @@ public function getConfig()
{
$config = [];
$apiKey = $this->mollieHelper->getApiKey();
$useImage = $this->mollieHelper->useImage();

try {
$mollieApi = $this->mollieModel->loadMollieApi($apiKey);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
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.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"
Expand Down
7 changes: 7 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
<config_path>payment/mollie_general/invoice_notify</config_path>
<comment><![CDATA[Set the notification for to Notify the customer with the Invoice]]></comment>
</field>
<field id="locale" translate="label comment" type="select" sortOrder="26" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Language Payment Page</label>
<source_model>Mollie\Payment\Model\Adminhtml\Source\Locale</source_model>
<config_path>payment/mollie_general/locale</config_path>
<comment><![CDATA[Let Mollie automatically detect the language or force the language from the store view.]]></comment>
</field>
<field id="heading_debug" translate="label comment" type="text" sortOrder="80" showInDefault="1"
showInWebsite="0" showInStore="0">
<label>Debug</label>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?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.1.3">
<module name="Mollie_Payment" setup_version="1.1.4">
</module>
</config>
Loading