Skip to content

Commit

Permalink
Merge pull request #61 from mollie/1.3.2b
Browse files Browse the repository at this point in the history
 Fixed currency value format
  • Loading branch information
Marvin-Magmodules authored May 16, 2018
2 parents 34841cd + 56e7376 commit 516bc08
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
47 changes: 32 additions & 15 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class General extends AbstractHelper

const MODULE_CODE = 'Mollie_Payment';
const SUPPORTED_LOCAL = ['en_US', 'de_AT', 'de_CH', 'de_DE', 'es_ES', 'fr_BE', 'fr_FR', 'nl_BE', 'nl_NL'];
const CURRENCIES_WITHOUT_DECIMAL = ['JPY'];

const XML_PATH_MODULE_ACTIVE = 'payment/mollie_general/enabled';
const XML_PATH_API_MODUS = 'payment/mollie_general/type';
Expand Down Expand Up @@ -366,22 +367,48 @@ public function getOrderAmountByOrder($order)
if ($baseCurrency) {
$orderAmount = [
"currency" => $order->getBaseCurrencyCode(),
"value" => number_format($order->getBaseGrandTotal(), 2)
"value" => $this->formatCurrencyValue($order->getBaseGrandTotal(), $order->getBaseCurrencyCode())
];
} else {
$orderAmount = [
"currency" => $order->getOrderCurrencyCode(),
"value" => number_format($order->getGrandTotal(), 2)
"value" => $this->formatCurrencyValue($order->getGrandTotal(), $order->getOrderCurrencyCode())
];
}

return $orderAmount;
}

/**
* @param int $storeId
*
* @return int
*/
public function useBaseCurrency($storeId = 0)
{
return (int)$this->getStoreConfig(self::XML_PATH_USE_BASE_CURRENCY, $storeId);
}

/**
* @param $value
* @param $currency
*
* @return string
*/
public function formatCurrencyValue($value, $currency)
{
$decimalPrecision = 2;
if (in_array($currency, self::CURRENCIES_WITHOUT_DECIMAL)) {
$decimalPrecision = 0;
}

return number_format($value, $decimalPrecision, '.', '');
}

/**
* Order Currency and Value array for payment request
*
* @param \Magento|Quote $quote
* @param \Magento\Quote\Model\Quote $quote
*
* @return array
*/
Expand All @@ -392,28 +419,18 @@ public function getOrderAmountByQuote($quote)
if ($baseCurrency) {
$orderAmount = [
"currency" => $quote->getBaseCurrencyCode(),
"value" => number_format($quote->getBaseGrandTotal(), 2)
"value" => $this->formatCurrencyValue($quote->getBaseGrandTotal(), $quote->getBaseCurrencyCode())
];
} else {
$orderAmount = [
"currency" => $quote->getQuoteCurrencyCode(),
"value" => number_format($quote->getGrandTotal(), 2)
"value" => $this->formatCurrencyValue($quote->getGrandTotal(), $quote->getQuoteCurrencyCode())
];
}

return $orderAmount;
}

/**
* @param int $storeId
*
* @return int
*/
public function useBaseCurrency($storeId = 0)
{
return (int)$this->getStoreConfig(self::XML_PATH_USE_BASE_CURRENCY, $storeId);
}

/**
* Determine Locale
*
Expand Down
2 changes: 1 addition & 1 deletion Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
$payment->refund([
"amount" => [
"currency" => $order->getOrderCurrencyCode(),
"value" => number_format($amount, 2)
"value" => $this->mollieHelper->formatCurrencyValue($amount, $order->getOrderCurrencyCode())
]
]);
} catch (\Exception $e) {
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.3.1",
"version": "1.3.2",
"require": {
"php": "~5.6.5|7.0.2|7.0.4|~7.0.6|~7.1.0",
"mollie/mollie-api-php": "^2.0"
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.3.1" />
<module name="Mollie_Payment" setup_version="1.3.2" />
</config>

0 comments on commit 516bc08

Please sign in to comment.