Skip to content

Commit

Permalink
Ajout du service RELOAD, pour recharger un compte
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgu74 committed Oct 2, 2013
1 parent 52c102e commit 5690686
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Payutc/Bom/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Payutc/Mapping/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Services {
'ADMINRIGHT',
'BLOCKED',
'GESARTICLE',
'PAYLINE'
'PAYLINE',
'RELOAD'
);

public static function get($name) {
Expand Down
6 changes: 6 additions & 0 deletions src/Payutc/Service/ADMINRIGHT.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
Expand Down
61 changes: 61 additions & 0 deletions src/Payutc/Service/RELOAD.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Payutc\Service;

use \Payutc\Config;

/**
* RELOAD.php
*
* Ce service expose les méthodes pour permettre d'effectuer le rechargement d'un compte utilisateur.
*
*/

class RELOAD extends \ServiceBase {

public function __construct() {
parent::__construct();
}

/**
* Retourne les infos utiles pour recharger (Min recharge, Max recharge, Can reload (true/false)
* @return array
*/
public function info() {
// 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)");
}
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);
}

}

0 comments on commit 5690686

Please sign in to comment.