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

CAB-823: Currency I18N #39

Merged
merged 2 commits into from
Nov 2, 2023
Merged
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
37 changes: 35 additions & 2 deletions Api/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
'vi' => 'Visa',
];

/**
* Japan locale code
*/
private const JAPAN_LOCALE_CODE = 'ja_JP';

protected $_localeResolver;

/**
* Constructor
*
Expand All @@ -60,7 +67,8 @@
\Magento\Directory\Model\Currency $currency,
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
\Magento\Customer\Model\Customer $customer,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface $orderCollectionFactory
\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface $orderCollectionFactory,
\Magento\Framework\Locale\ResolverInterface $localeResolver
) {

parent::__construct($logger, $curl);
Expand All @@ -69,6 +77,7 @@
$this->customerRepository = $customerRepository;
$this->customer = $customer;
$this->orderCollectionFactory = $orderCollectionFactory;
$this->_localeResolver = $localeResolver;
}

/**
Expand Down Expand Up @@ -269,7 +278,7 @@
$last4 = $payment->decrypt($last4);
}

if (isset($last4) && !empty($last4) && strlen($last4) == 4 && ctype_digit($last4)) {

Check warning on line 281 in Api/RequestHandler.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 85 characters; contains 92 characters
return $last4;
}
}
Expand Down Expand Up @@ -307,7 +316,7 @@
$expYear = $payment->getCcExpYear();

// Pad a one-digit month with a 0;
if (isset($expMonth) && !empty($expMonth)){

Check failure on line 319 in Api/RequestHandler.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected "if (...) {\n"; found "if (...){\n"

Check failure on line 319 in Api/RequestHandler.php

View workflow job for this annotation

GitHub Actions / phpcs

There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
if (strlen($expMonth) == 1) {
$expMonth = "0" . $expMonth;
}
Expand All @@ -321,7 +330,7 @@
// NoFraud requires an expiration year;
// If year is invalid, return nothing;
// Else if year is four digits (1999), truncate it to two (99);
if (isset($expYear) && !empty($expYear)){

Check failure on line 333 in Api/RequestHandler.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected "if (...) {\n"; found "if (...){\n"

Check failure on line 333 in Api/RequestHandler.php

View workflow job for this annotation

GitHub Actions / phpcs

There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found 0 spaces
if (strlen($expYear) > 4) {
return;
} elseif (strlen($expYear) == 4) {
Expand Down Expand Up @@ -407,8 +416,32 @@
if (empty($amount)) {
return;
}

$value = $this->currency->formatTxt($amount, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);

$separatorComa = strpos($value, ',');
$separatorDot = strpos($value, '.');
$price = $value;

return $this->currency->formatTxt($amount, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
if ($separatorComa !== false && $separatorDot !== false) {
if ($separatorComa > $separatorDot) {
$price = preg_replace("/(\d+)\.(\d+),(\d+)/", "$1,$2.$3", $value);
}
} elseif ($separatorComa !== false) {
$locale = $this->_localeResolver->getLocale();

/**
* It's hard code for Japan locale.
*/
$price = number_format(
(float)
str_replace(',', $locale === self::JAPAN_LOCALE_CODE ? '' : '.', $value),
2,
'.',
','
);
}
return $price;
}

/**
Expand Down
Loading