Created
September 6, 2019 11:34
-
-
Save mgsmus/a46803e01e59847c90da899b607bb651 to your computer and use it in GitHub Desktop.
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
<?php | |
use Money\Currencies\ISOCurrencies; | |
use Money\Parser\DecimalMoneyParser; | |
use Money\Formatter\IntlMoneyFormatter; | |
use Money\Converter; | |
use Money\Currency; | |
use Money\Exchange\FixedExchange; | |
use Money\Exchange\ReversedCurrenciesExchange; | |
$currencies = new ISOCurrencies(); | |
$moneyParser = new DecimalMoneyParser($currencies); | |
$moneyFormatter = new IntlMoneyFormatter( | |
new \NumberFormatter('tr_TR', \NumberFormatter::CURRENCY), | |
$currencies | |
); | |
$usdMoneyFormatter = new IntlMoneyFormatter( | |
new \NumberFormatter('en_US', \NumberFormatter::CURRENCY), | |
$currencies | |
); | |
$converter = new Converter($currencies, | |
new ReversedCurrenciesExchange( | |
new FixedExchange([ | |
'USD' => [ | |
'TRY' => 5.70 | |
] | |
]) | |
) | |
); | |
$price = $moneyParser->parse('1115.55', new Currency('TRY')); | |
$tax = $price->multiply(18)->divide(100); | |
$priceWithTax = $price->add($tax); | |
$installments = []; | |
$USD = $converter->convert($priceWithTax, new Currency('USD')); | |
foreach ($priceWithTax->allocateTo(4) as $installment) { | |
$installments[] = $moneyFormatter->format($installment); | |
} | |
$result = [ | |
'price' => $moneyFormatter->format($price), | |
'tax' => $moneyFormatter->format($tax), | |
'priceWithTax' => $moneyFormatter->format($priceWithTax), | |
'usd' => $usdMoneyFormatter->format($USD), | |
'installments' => $installments | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment