diff --git a/src/Payutc/Bom/User.php b/src/Payutc/Bom/User.php index 02a53f8..a9ceea5 100644 --- a/src/Payutc/Bom/User.php +++ b/src/Payutc/Bom/User.php @@ -310,6 +310,16 @@ public function isAdult() { public function isCotisant() { return $this->gingerUser->is_cotisant; } + + /** + * Retourne si l'utilisateur à le droit de recharger ou non + * + * @return bool + */ + public function canReload() { + return $this->gingerUser->is_cotisant && + ($this->getCredit() + Config::get('rechargement_min', 1000)) <= Config::get('credit_max'); + } /** * Returns the last purchases from the user (to allow the seller to cancel them) diff --git a/src/Payutc/Mapping/Services.php b/src/Payutc/Mapping/Services.php index 61ff369..79faf97 100644 --- a/src/Payutc/Mapping/Services.php +++ b/src/Payutc/Mapping/Services.php @@ -14,7 +14,8 @@ class Services { 'ADMINRIGHT', 'BLOCKED', 'GESARTICLE', - 'PAYLINE' + 'PAYLINE', + 'RELOAD' ); public static function get($name) { diff --git a/src/Payutc/Service/ADMINRIGHT.php b/src/Payutc/Service/ADMINRIGHT.php index 8785428..395dfec 100644 --- a/src/Payutc/Service/ADMINRIGHT.php +++ b/src/Payutc/Service/ADMINRIGHT.php @@ -79,6 +79,12 @@ public function getServices() { "desc" => "Permet de récupérer différentes informations statistiques sur la fundation.", "user" => true, "app" => true + ), array( + "service" => "RELOAD", + "name" => "Rechargement", + "desc" => "Permettre le rechargement des utilisateurs", + "user" => false, + "app" => false ) ); } diff --git a/src/Payutc/Service/RELOAD.php b/src/Payutc/Service/RELOAD.php new file mode 100644 index 0000000..c667736 --- /dev/null +++ b/src/Payutc/Service/RELOAD.php @@ -0,0 +1,61 @@ +checkRight(false, true, true, null); + // on a un user ? + if(!$this->user()) { + throw new \Payutc\Exception\CheckRightException("Vous devez connecter un utilisateur ! (method loginCas)"); + } + 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()); + } + + /** + * Fonction pour recharger un client. + * + * @param int $amount (en centimes) + * @param String $callbackUrl + * @return String $url + */ + public function reload($amount, $callbackUrl) { + // On a une appli qui a les droits ? + $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)"); + } + // Verification de la possiblité de recharger + if(!$this->user()->canReload($amount)) { + throw new \Payutc\Exception\CannotReloadException("Vous ne pouvez pas recharger."); + } + + $pl = new \Payutc\Bom\Payline($this->application()->getId(), $this->service_name); + return $pl->doWebPayment($this->user(), $amount, $callbackUrl); + } + + }