This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from pmclain/feature/precision
Fix amount when using zero-decimal currencies
- Loading branch information
Showing
42 changed files
with
1,271 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* Pmclain_Stripe extension | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the OSL 3.0 License | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/osl-3.0.php | ||
* | ||
* @category Pmclain | ||
* @package Pmclain_Stripe | ||
* @copyright Copyright (c) 2017-2018 | ||
* @license Open Software License (OSL 3.0) | ||
*/ | ||
|
||
namespace Pmclain\Stripe\Gateway\Helper; | ||
|
||
use Pmclain\Stripe\Gateway\Config\Config; | ||
|
||
class PriceFormatter | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* Formatter constructor. | ||
* @param Config $config | ||
*/ | ||
public function __construct( | ||
Config $config | ||
) { | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* @param string $price | ||
* @return string | ||
*/ | ||
public function formatPrice($price) | ||
{ | ||
$price = sprintf('%.' . ($this->isZeroDecimalCurrency() ? '0' : '2') . 'F', $price); | ||
|
||
return str_replace('.', '', $price); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
private function isZeroDecimalCurrency() | ||
{ | ||
return in_array($this->config->getCurrency(), $this->getZeroDecimalCurrencies(), true); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getZeroDecimalCurrencies() | ||
{ | ||
return [ | ||
'BIF', | ||
'CLP', | ||
'DJF', | ||
'GNF', | ||
'JPY', | ||
'KMF', | ||
'KRW', | ||
'MGA', | ||
'PYG', | ||
'RWF', | ||
'UGX', | ||
'VND', | ||
'VUV', | ||
'XAF', | ||
'XOF', | ||
'XPF', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.