diff --git a/app/Exceptions/AppException.php b/app/Exceptions/AppException.php new file mode 100644 index 0000000..0d45cbe --- /dev/null +++ b/app/Exceptions/AppException.php @@ -0,0 +1,25 @@ +code}]: {$this->message}\n"; + } + +} diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index fc4cd98..d82e7f7 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -132,6 +132,10 @@ class Handler extends ExceptionHandler return $this->errorResponse($message, $code); } + if ($exception instanceof AppException) { + return $this->errorResponse($exception->getMessage(), $exception->getCode()); + } + if (env('APP_DEBUG', false)) { return parent::render($request, $exception); } diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index ca6c3d5..0322867 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Exceptions\AppException; use App\Models\AgentPlus; use App\Models\CodeGenerer; use App\Models\ConfigWallet; @@ -1861,6 +1862,10 @@ class iLinkTransactionController extends Controller } //Calcul des frais internationaux + + /** + * @throws AppException + */ private function calculateFees(array $paliers, $montant) { $size = sizeof($paliers); @@ -1877,15 +1882,9 @@ class iLinkTransactionController extends Controller } if ($palier) { - $fees = (($palier->min + $palier->max) / 2 * $palier->taux / 100); + $fees = ($montant * $palier->taux / 100); } else { - if ($montant < $min) { - $palier = $paliers[0]; - $fees = $min * $palier->taux / 100; - } else if ($montant > $max) { - $palier = $paliers[$size - 1]; - $fees = $max * $palier->taux / 100; - } + throw new AppException(trans('errors.amount_not_allowed', ['min' => floatval($min), 'max' => floatval($max)])); } if (!empty($palier->plafond) && ($fees > $palier->plafond)) { diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index b79636f..a64d9c1 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -85,4 +85,5 @@ Paying network : :network :country', "update_banking_information" => "Update your banking information", "wallet_already_linked_to_bank_account" => "Your wallet is already linked to your bank account", "users_group_not_found" => "This group code does not exist", + "amount_not_allowed" => "Ce montant n'est pas autorisé. Il doit être compris entre :min et :max" ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 5a98e65..9e6a46d 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -85,4 +85,5 @@ Réseau payeur : :network :country', "update_banking_information" => "Mettez à jour vos informations bancaires", "wallet_already_linked_to_bank_account" => "Votre wallet est déjà rattaché à votre compte bancaire", "users_group_not_found" => "Ce code de groupe n'existe pas", + "amount_not_allowed" => "Ce montant n'est pas autorisé. Il doit être compris entre :min et :max" ];