Skip to content

Commit

Permalink
Exceptions dans checkReload (remplace canReload)
Browse files Browse the repository at this point in the history
  • Loading branch information
apuyou committed Oct 3, 2013
1 parent e02ad12 commit 5ac7b99
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
25 changes: 18 additions & 7 deletions src/Payutc/Bom/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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($amount<Config::get('rechargement_min', 1000)) {
return false;
public function checkReload($amount = null) {
if($amount === null){
$amount = Config::get('rechargement_min', 1000);
}

if($amount < Config::get('rechargement_min', 1000)) {
throw new CannotReload("Le montant du rechargement est inférieur au minimum autorisé");
}

if(($this->getCredit() + $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');
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Payutc/Exception/CannotReload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Payutc\Exception;

class CannotReload extends PayutcException {}
14 changes: 8 additions & 6 deletions src/Payutc/Service/RELOAD.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public function info() {
if(!$this->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()
);
}

/**
Expand All @@ -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);
Expand Down

0 comments on commit 5ac7b99

Please sign in to comment.