+ Fix bugs with currency rounding
This commit is contained in:
parent
c5d6373fde
commit
d8743775c7
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\ConfigWallet;
|
||||
use App\Models\Country;
|
||||
use App\Models\User;
|
||||
use App\Models\WalletsUser;
|
||||
use App\Traits\ApiResponser;
|
||||
use Illuminate\Http\Request;
|
||||
|
@ -60,4 +61,30 @@ class HelperController extends Controller
|
|||
public function country($code_dial){
|
||||
return $this->successResponse(Country::where('code_dial',$code_dial)->firstOrFail());
|
||||
}
|
||||
|
||||
public function init(){
|
||||
//Mettre a jour tous les utilisateurs qui n'ont pas de wallet iLink
|
||||
$users = User::whereNull('user_code')->orWhere('user_code','')->get();
|
||||
foreach ($users as $user){
|
||||
do{
|
||||
$user_code=$this->generateUserCode();
|
||||
$result = collect(DB::select('SELECT * FROM users WHERE user_code = :code',['code'=>$user_code]));
|
||||
$codeCorrect=sizeof($result)<0;
|
||||
}while($codeCorrect);
|
||||
$user->user_code = $user_code;
|
||||
DB::insert('INSERT INTO wallets_users (idUser) VALUES (?);', [$user->id]);
|
||||
$user->save();
|
||||
}
|
||||
return $this->successResponse('OK :-) , Have a nice day dear ! ');
|
||||
}
|
||||
|
||||
private function generateUserCode($length = 10) {
|
||||
$characters = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -654,9 +654,8 @@ class iLinkTransactionController extends Controller
|
|||
break;
|
||||
case 2: //User - Envoi de wallet à carte
|
||||
$frais = $request->montant * $config->taux_com_user_wallet_carte / 100;
|
||||
$data['frais'] = $this->toMoney($frais, $init_country);
|
||||
$data['montant_net_init'] = $this->toMoney($request->montant - $frais, $init_country);
|
||||
$data['montant_net_final'] = $this->toMoneyWithCurrency($request->montant - $frais, $init_country ,$request->final_country );
|
||||
$data['frais'] = $frais;
|
||||
$data['montant_net_init'] = $request->montant - $frais;
|
||||
return $this->successResponse($data);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Traits;
|
|||
|
||||
use App\Models\CountriesCurrency;
|
||||
use App\Models\Country;
|
||||
use Brick\Money\Context\CustomContext;
|
||||
use DateTime;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Brick\Money\CurrencyConverter;
|
||||
|
@ -16,7 +17,6 @@ use Brick\Money\Money;
|
|||
use Brick\Math\RoundingMode;
|
||||
use PDO;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Brick\Money\Context\AutoContext;
|
||||
|
||||
trait Helper
|
||||
{
|
||||
|
@ -54,14 +54,14 @@ trait Helper
|
|||
$currency = collect(DB::select('SELECT cu.code FROM networks n INNER JOIN countries c ON c.id = n.country_id INNER JOIN currencies cu ON cu.id = c.idCurrency
|
||||
WHERE n.id = :id',['id'=>$id_network]))->first();
|
||||
|
||||
$money = Money::of(round($amount, 0),$currency ? $currency->code : 'XAF',new AutoContext());
|
||||
$money = Money::of(round($amount, 2),$currency ? $currency->code : 'XAF',new CustomContext(2));
|
||||
return $money->formatTo('fr_FR');
|
||||
}
|
||||
|
||||
public function toMoney($amount, $id_country)
|
||||
{
|
||||
$country = Country::findOrFail($id_country);
|
||||
$money = Money::of(round($amount, 0),$country->currency->code,new AutoContext());
|
||||
$money = Money::of(round($amount, 2),$country->currency->code,new CustomContext(2));
|
||||
return $money->formatTo('fr_FR');
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ trait Helper
|
|||
$converter = new CurrencyConverter($provider);
|
||||
$init_country = Country::findOrFail($init_country);
|
||||
$final_country = Country::findOrFail($final_country);
|
||||
$init_money = Money::of(round($amount, 0),$init_country->currency->code,new AutoContext());
|
||||
$init_money = Money::of(round($amount, 2),$init_country->currency->code,new CustomContext(2));
|
||||
return $converter->convert($init_money, $final_country->currency->code, RoundingMode::DOWN);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
$router->get('countries','HelperController@countries');
|
||||
$router->get('countries/{dial_code}','HelperController@country');
|
||||
$router->post('paying_networks','HelperController@paying_networks');
|
||||
$router->get('init','HelperController@init');
|
||||
|
||||
// Transactions routes
|
||||
$router->group(['prefix' => '/transactions'] , function () use ($router){
|
||||
|
|
Loading…
Reference in New Issue