fix: add 6 decimal while calculate commission
This commit is contained in:
parent
9942b62ed3
commit
4b3bac0774
|
@ -24,7 +24,9 @@ use App\Models\WalletsUser;
|
||||||
use Barryvdh\DomPDF\Facade as PDF;
|
use Barryvdh\DomPDF\Facade as PDF;
|
||||||
use Brick\Math\RoundingMode;
|
use Brick\Math\RoundingMode;
|
||||||
use Brick\Money\Context\AutoContext;
|
use Brick\Money\Context\AutoContext;
|
||||||
|
use Brick\Money\Context\CustomContext;
|
||||||
use Brick\Money\CurrencyConverter;
|
use Brick\Money\CurrencyConverter;
|
||||||
|
use Brick\Money\Exception\CurrencyConversionException;
|
||||||
use Brick\Money\ExchangeRateProvider\BaseCurrencyProvider;
|
use Brick\Money\ExchangeRateProvider\BaseCurrencyProvider;
|
||||||
use Brick\Money\ExchangeRateProvider\PDOProvider;
|
use Brick\Money\ExchangeRateProvider\PDOProvider;
|
||||||
use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration;
|
use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration;
|
||||||
|
@ -211,9 +213,36 @@ trait Helper
|
||||||
return $this->convertMoney($amount, $init_country, $final_country)->getAmount()->toFloat();
|
return $this->convertMoney($amount, $init_country, $final_country)->getAmount()->toFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws CurrencyConversionException
|
||||||
|
*/
|
||||||
public function getExchangeRate($init_country, $final_country)
|
public function getExchangeRate($init_country, $final_country)
|
||||||
{
|
{
|
||||||
return $this->toMoney(1, $init_country) . ' = ' . $this->toMoneyWithCurrency(1, $init_country, $final_country, 6);
|
// set to whatever your rates are relative to
|
||||||
|
$baseCurrency = 'USD';
|
||||||
|
|
||||||
|
// use your own credentials, or re-use your existing PDO connection
|
||||||
|
$pdo = new PDO('mysql:host=' . env('DB_HOST') . ';dbname=' . env('DB_DATABASE'), env('DB_USERNAME'), env('DB_PASSWORD'));
|
||||||
|
|
||||||
|
$configuration = new PDOProviderConfiguration();
|
||||||
|
|
||||||
|
$configuration->tableName = 'exchange_rate';
|
||||||
|
$configuration->exchangeRateColumnName = 'exchange_rate';
|
||||||
|
$configuration->targetCurrencyColumnName = 'target_currency';
|
||||||
|
$configuration->sourceCurrencyCode = $baseCurrency;
|
||||||
|
|
||||||
|
// this provider loads exchange rates from your database
|
||||||
|
$provider = new PDOProvider($pdo, $configuration);
|
||||||
|
|
||||||
|
// this provider calculates exchange rates relative to the base currency
|
||||||
|
$provider = new BaseCurrencyProvider($provider, $baseCurrency);
|
||||||
|
|
||||||
|
$sourceCurrencyCode = CountriesCurrency::findOrFail($init_country)->currency_code;
|
||||||
|
$targetCurrencyCode = CountriesCurrency::findOrFail($final_country)->currency_code;
|
||||||
|
|
||||||
|
$rate = round($provider->getExchangeRate($sourceCurrencyCode, $targetCurrencyCode)->toFloat(), 6);
|
||||||
|
|
||||||
|
return $this->toMoneyWithCurrencyCode(1, $sourceCurrencyCode) . ' = ' . $rate. ' '. $targetCurrencyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toUSDAmount($amount, $init_country, $final_currency_code = 'USD')
|
public function toUSDAmount($amount, $init_country, $final_currency_code = 'USD')
|
||||||
|
|
Loading…
Reference in New Issue