diff --git a/library/WsScore/Credit/v0.1/Config.php b/library/WsScore/Credit/v0.1/Config.php index 5f4f10a5..ea52cb43 100644 --- a/library/WsScore/Credit/v0.1/Config.php +++ b/library/WsScore/Credit/v0.1/Config.php @@ -1,8 +1,9 @@ 'Credit', - 'infoCredit' => 'InfoCredit', -// 'addCredit' => 'AddCredit', -// 'subCredit' => 'SubCredit', -// 'updateCredit' => 'UpdateCredit', -); \ No newline at end of file + 'GetCredit' => 'GetCredit', + 'infoCredit' => 'infoCredit', + 'PayCredit' => 'PayCredit', + 'AddCredit' => 'AddCredit', + 'SubCredit' => 'SubCredit', + 'UpdateCredit' => 'UpdateCredit', +); diff --git a/library/WsScore/Credit/v0.1/Service.php b/library/WsScore/Credit/v0.1/Service.php index 49da085e..6e7b7157 100644 --- a/library/WsScore/Credit/v0.1/Service.php +++ b/library/WsScore/Credit/v0.1/Service.php @@ -34,10 +34,11 @@ class Credit extends Scores_Ws_Server $this->wsLog('credit', $idUser); return $credit; } + /** * Retourne la totalite des infos de crédit à un utilisateur * @return infoCredit - */ + */ public function infoCredit() { $info=new infoCredit(); @@ -71,6 +72,38 @@ class Credit extends Scores_Ws_Server return $info; } + /** + * Mettre à jour la table Credit_paid + * @param string ligneCredit + * @return PayCredit + */ + public function payCredit($ligneCredit='toto') + { + $PayCreditResult=new PayCredit(); + $this->authenticate(); + $PayCreditResult->ligneCredit=$ligneCredit; + $PayCreditResult->message=''; + $ir=(array)json_decode($ligneCredit); + if(empty($ir) || !isset($ir['idCmd'])){ + $PayCreditResult->message='Bad data format'; + $PayCreditResult->result=false; + return $PayCreditResult; + } + $sql = "SELECT transaction FROM sdv1.credit__paid c + WHERE c.idCmd=:idCmd"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('idCmd', $ir['idCmd']); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $r = $this->conn->update('sdv1.credit__paid', $ir,'idCmd='.$ir['idCmd=']); + }else{ + $r = $this->conn->insert('sdv1.credit__paid', $ir); + } + $PayCreditResult->result=true; + $this->wsLog('payCredit', $idUser); + return $PayCreditResult; + } + /** * Ajoute des crédits supplémentaires à un utilisateur * @param $nbCredit diff --git a/library/WsScore/Credit/v0.1/Types.php b/library/WsScore/Credit/v0.1/Types.php index b5702c89..e2faf787 100644 --- a/library/WsScore/Credit/v0.1/Types.php +++ b/library/WsScore/Credit/v0.1/Types.php @@ -3,6 +3,7 @@ class GetCredit { } + class infoCredit{ /** * Etat actuel du compte @@ -20,19 +21,26 @@ class infoCredit{ */ public $used; } -class balance{ - /** - * Date de creation - * @var date - */ - public $created; - /** - * Balance des credits - * @var int - */ - public $balance; +class PayCredit +{ + /** + * Success or failed + * @var boolean + */ + public $result; + /** + * Message + * @var string + */ + public $message; + /** + * Params sent + * @var string + */ + public $ligneCredit; } + class AddCredit {