From 5ac7b99233b35f6e3c9a122d274a2a4f0d16eb88 Mon Sep 17 00:00:00 2001 From: Arthur Puyou Date: Thu, 3 Oct 2013 21:09:21 +0200 Subject: [PATCH] Exceptions dans checkReload (remplace canReload) --- src/Payutc/Bom/User.php | 25 ++++++++++++++++++------- src/Payutc/Exception/CannotReload.php | 5 +++++ src/Payutc/Service/RELOAD.php | 14 ++++++++------ 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 src/Payutc/Exception/CannotReload.php diff --git a/src/Payutc/Bom/User.php b/src/Payutc/Bom/User.php index 55e8dd0..66ff254 100644 --- a/src/Payutc/Bom/User.php +++ b/src/Payutc/Bom/User.php @@ -26,6 +26,7 @@ use \Payutc\Exception\GingerFailure; use \Payutc\Exception\UpdateFailed; use \Payutc\Exception\LoginError; +use \Payutc\Exception\CannotReload; use \Payutc\Exception\TransferException; use \Payutc\Bom\Blocked; use \Payutc\Bom\MsgPerso; @@ -352,16 +353,26 @@ public function isCotisant() { } /** - * Retourne si l'utilisateur à le droit de recharger ou non + * Vérifie qu'un utilisateur peut recharger * - * @return bool + * @throws CannotReload */ - public function canReload($amount=1000) { - if($amountgetCredit() + $amount) > Config::get('credit_max')){ + throw new CannotReload("Le rechargement ferait dépasser le plafond maximum"); + } + + if(!$this->isCotisant()){ + throw new CannotReload("Il faut être cotisant pour pouvoir recharger"); } - return $this->gingerUser->is_cotisant && - ($this->getCredit() + $amount) <= Config::get('credit_max'); } /** diff --git a/src/Payutc/Exception/CannotReload.php b/src/Payutc/Exception/CannotReload.php new file mode 100644 index 0000000..24b43f3 --- /dev/null +++ b/src/Payutc/Exception/CannotReload.php @@ -0,0 +1,5 @@ +user()) { throw new \Payutc\Exception\CheckRightException("Vous devez connecter un utilisateur ! (method loginCas)"); } + + // Check that the user can reload + $this->user()->checkReload(); + return array( "min" => Config::get('rechargement_min', 1000), "max_credit" => Config::get('credit_max', 10000), - "max_reload" => Config::get('credit_max', 10000) - $this->user()->getCredit(), - "can" => $this->user()->canReload()); + "max_reload" => Config::get('credit_max', 10000) - $this->user()->getCredit() + ); } /** @@ -43,12 +47,10 @@ public function reload($amount, $callbackUrl) { $this->checkRight(false, true, true, null); // On a un user ? if(!$this->user()) { - throw new \Payutc\Exception\CheckRightException("Vous devez connecter un utilisateur ! (method loginCas)"); + throw new \Payutc\Exception\CheckRightException("Vous devez connecter un utilisateur !"); } // Verification de la possiblité de recharger - if(!$this->user()->canReload($amount)) { - throw new \Payutc\Exception\CannotReloadException("Vous ne pouvez pas recharger."); - } + $this->user()->checkReload($amount); $pl = new \Payutc\Bom\Payline($this->application()->getId(), $this->service_name); return $pl->doWebPayment($this->user(), $amount, $callbackUrl);