Avec ws->getCredit uniquement int

This commit is contained in:
Claire DELBOS 2017-02-27 17:17:23 +01:00
parent 9576cb16d6
commit 99b461b292
4 changed files with 64 additions and 100 deletions

View File

@ -11,6 +11,11 @@ class Achatclient_IndexController extends Zend_Controller_Action
protected $logger;
protected $tranches=array(
'1' => array(
'200' => array('montant' => 2000,'montantht' => 1667, 'tva' => 333, ),
'500' => array('montant' => 5000,'montantht' => 4167, 'tva' => 833, ),
'1000' => array('montant' => 10000,'montantht' => 8333, 'tva' => 1667, ),
),
'195' => array(
'200' => array('montant' => 2000,'montantht' => 1667, 'tva' => 333, ),
'500' => array('montant' => 5000,'montantht' => 4167, 'tva' => 833, ),
@ -45,18 +50,21 @@ class Achatclient_IndexController extends Zend_Controller_Action
if(!$ok){
$this->error('index','Fonction indisponible');
}
$ws = new WsScores();
$ws = new WsScores('credit');
$customer_credit = $ws->getCredit();
$infos=array('user' => $user,'wscredit' => $customer_credit,'tranches' => $this->tranches);
if(intval($customer_credit)>$this->maxcredit){
$this->view->msg='Vous détenez déjà le plafond de crédits autorisé.';
return;
}
$this->logger->info(print_r($user,1));
if ($customer_credit === false and false) {
if ($customer_credit === false) {
$this->error('index','Compte indisponible');
$this->forward('soap', 'error');
}
if(!isset($this->tranches[$user->getIdClient()])){
$this->error('index','Fonction indisponible pour ce client');
}
$infos=array('user' => $user,'wscredit' => $customer_credit,'tranches' => $this->tranches[$user->getIdClient()]);
if(intval($customer_credit)>$this->maxcredit){
$this->view->msg='Vous détenez le plafond de crédits autorisé.';
return;
}
$this->logger->info(print_r($user,1));
//Récupération des Parametres
$infos=array('user' => $user,'wscredit' => intval($customer_credit),'tranches' => $this->tranches[$user->getIdClient()]);
//var_dump($infos);die;
@ -67,7 +75,7 @@ class Achatclient_IndexController extends Zend_Controller_Action
public function paiementAction()
{
//Validation
$request = $this->getRequest('');
$request = $this->getRequest();
$user = new Scores_Utilisateur();
$ok=$user->checkperm($this->libdroits);
if(!$ok){
@ -89,9 +97,11 @@ class Achatclient_IndexController extends Zend_Controller_Action
$pbparam=array();
$pbparams['cmdId']=implode('#',array($user->identity->id,time()));
$pbparams['email']=$user->identity->email;
$pbparams['montant']=$this->tranches[$idClient][$nb_credit]['montant']/100;
$pbparams['montantht']=$this->tranches[$idClient][$nb_credit]['montantht']/100;
$pbparams['tva']=$this->tranches[$idClient][$nb_credit]['tva']/100;
$pbparams['montant']=$this->tranches[$idClient][$nb_credit]['montant'];
$pbparams['montantht']=$this->tranches[$idClient][$nb_credit]['montantht'];
$pbparams['tva']=$this->tranches[$idClient][$nb_credit]['tva'];
$pbparams['login']=$user->identity->username;
$pbparams['nb_credit']=$nb_credit;
$ws = new WsScores();
//$customer_credit = $ws->addCredit();
$insdata=array(
@ -120,7 +130,7 @@ class Achatclient_IndexController extends Zend_Controller_Action
$paybox->setUrlPaiement();
$paybox->setEmail($pbparams['email']);
$paybox->setReference($pbparams['cmdId']);
$paybox->setMontant($pbparams['montant']);
$paybox->setMontant($pbparams['montant']/100);
//echo "http://".$request->getHttpHost()."/achatclient/pbanswer";die;
//$paybox->setUrlRepondreA("http://".$request->getHttpHost()."/achatclient/checkpmt");
$paybox->setUrlParameters("http://".$request->getHttpHost()."/achatclient/pbanswer");
@ -132,81 +142,35 @@ class Achatclient_IndexController extends Zend_Controller_Action
$this->view->PayboxValues = $paybox->getFormParameters();
}
public function pbanswer(){
echo 'thanks';die;
}
/**
* Sélection du mode de paiement
*/
public function paiementTestAction()
{
$this->_helper->layout()->disableLayout();
public function pbanswerAction(){
$request = $this->getRequest();
//Commande ID
$cmdId = $request->getParam('id');
//Write the state to the session
$cmdState = 3;
$session = new Zend_Session_Namespace('Cmd');
//@todo : verifications
$cmdId = '525ffc4501a4d';
$this->view->CmdID = $cmdId;
$this->view->Siren = isset($session->CmdSiren)?$session->CmdSiren:'000000000';
$this->view->RaisonSociale = isset($session->CmdRaisonSociale)?$session->CmdRaisonSociale:'testdev';
$this->view->AdresseL1 = isset($session->CmdAdresseL1)?$session->CmdAdresseL1:'';
$this->view->AdresseL2 = isset($session->CmdAdresseL2)?$session->CmdAdresseL2:'';
$this->montantht=20;
$this->montant=20;
$this->tva=0;
//Lire la bdd
//$commandM = new Application_Model_Command();
//$row = $commandM->fetchRow('cmdId="'.$cmdId.'"');
$row=array('email' => 'test20170224091345.demo@intescia.com','id'=>4925);
if ($row !== null) {
$this->view->montant = $this->montantht." € HT" . " (".$this->montant." € TTC)";
$data = array(
'mt' => $this->montantht,
'tax' => $this->tva,
);
//$commandM->update($data, 'id='.$row->id);
//Paybox
require_once 'Paybox/Config.php';
require_once 'Paybox/Config/test.php';
require_once 'Paybox/System.php';
$paybox = new Paybox_System('test');
$paybox->setUrlPaiement();
$paybox->setEmail($row['email']);
$paybox->setReference($cmdId);
$paybox->setMontant($this->montant);
$paybox->setUrlRepondreA("http://".$request->getHttpHost()."/report/checkpmt");
$paybox->setUrlParameters("http://".$request->getHttpHost()."/report/retour");
$paybox->calculateHMAC();
$this->view->PayboxUrl = $paybox->getFormUrl();
$this->view->PayboxValues = $paybox->getFormParameters();
$this->view->PayboxVerif=$paybox->URL_PARAMETERS;
$user = new Scores_Utilisateur();
$ok=$user->checkperm($this->libdroits);
if(!$ok){
$this->view->msg='Problème d\'autentification';
}
if(empty($this->view->msg)){
$this->view->msg='Annulation de votre transaction';
}
switch($answer){
case "error":
return;
break;
}
if(empty($this->view->msg)){
$this->view->msg='Annulation de votre transaction';
}
}
public function footerAction(){
}
private function error($ligne=0,$message=""){
$request = $this->getRequest();
switch($ligne){
case "index":
case "paiement":
$this->view->msg=$message;
throw new Exception($message);
break;
//$this->redirect( $this->view->url(array('action'=>'pbanswer')));
//break;
default:
echo $ligne.' : '.$message;die;
}

View File

@ -5,9 +5,9 @@ div .credit{
</style>
<div id="center">
<h1><?=$this->titre?></h1>
<h1>Votre compte crédits en ligne</h1>
<h2>Votre compte crédit</h2>
<h2>Fiche crédits</h2>
<div class="credit">
<p>
Le compte <?=isset($this->infos['user']->identity->username)?$this->infos['user']->identity->username:""?> détient actuellement <?=intval($this->infos['wscredit'])?> crédits.<br>
@ -15,11 +15,11 @@ Le compte <?=isset($this->infos['user']->identity->username)?$this->infos['user'
<div id="message" class="alert alert-info"><?=$this->msg?></div>
</div>
<?php if(isset($this->infos) && isset($this->infos['tranches'])):?>
<h2>Vos choix de commande</h2>
<h2>Commander des crédits</h2>
<form action="<?=$this->url(array('controller'=>'index', 'action'=>'paiement'))?>" method="GET" id="creditform">
<div class="credit">
<?php $ok=true;foreach($this->infos['tranches'] as $credit => $item):?>
<input type="radio" name="nb_credit" value="<?=$credit?>" <?php if($ok){?>checked="checked"<?php }$ok=false;?> />&nbsp;&nbsp;<?=$credit?>&nbsp;Crédits (<?=$item['montant']/100?> Euros)
<br><input type="radio" name="nb_credit" value="<?=$credit?>" <?php if($ok){?>checked="checked"<?php }$ok=false;?> />&nbsp;&nbsp;<?=$credit?>&nbsp;Crédits (<?=$item['montant']/100?> Euros)
<?php endforeach;?>
</div>
<div class="submit">

View File

@ -2,6 +2,9 @@
div .credit{
margin-left:25px;
}
td.nbr{
text-align:right;
}
</style>
@ -10,20 +13,25 @@ div .credit{
<?php //if ( $this->CmdID ):?>
<h2>Informations de la commande</h2>
<div class="credit">
Identifiant de commande : <?=$this->pbparams['cmdId']?><br>
Une fois le paiement effectué cliquer sur le bouton "Retour boutique" afin de
consulter vos documents, si la redirection automatique ne se fait pas.
<div class="credit"><table class="data" style="max-width:80%;">
<tr><td>Identifiant de commande : </td><td><?=$this->pbparams['cmdId']?></td></tr>
<tr><td>Client : </td><td><?=$this->pbparams['login']?></td></tr>
<tr><td>Nombre de crédits commandés : </td><td><?=$this->pbparams['nb_credit']?></td></tr>
<tr><td>Montant HT : </td><td class="nbr"><?=number_format($this->pbparams['montantht']/100,2,","," ")?> euros</td></tr>
<tr><td>Tva : </td><td class="nbr"><?=number_format($this->pbparams['tva']/100,2,","," ")?> euros</td></tr>
<tr><td>Montant TTC : </td><td class="nbr"><?=number_format($this->pbparams['montant']/100,2,","," ")?> euros</td></tr>
</table>
<p>Une fois le paiement effectué cliquer sur le bouton "Retour boutique" afin de
consulter vos documents, si la redirection automatique ne se fait pas.</p>
</div>
<h2>Sélection du mode de paiement</h2>
<h2>Démarrer le paiement</h2>
<div class="credit">
<?php if ($this->PayboxValues) {?>
<?=$this->PayboxVerif?>
<form method="post" action="<?=$this->PayboxUrl?>">
<?php foreach ( $this->PayboxValues as $field) {?>
<?=$field['name']?> ===> <?=$field['value']?><br>
<input type="hidden" name="<?=$field['name']?>" value="<?=$field['value']?>" />
<?php }?>

View File

@ -3352,23 +3352,15 @@ class WsScores
*/
public function getCredit()
{
$filename = 'prefs';
$cache = new Cache($filename);
if ($cache->exist() && $this->cacheEnable ){
return $cache->getBlock('prefs');
}
//try {
try {
$client = $this->loadClient('credit');
$reponse = $client->getCredit();
$cache->deletefile();
$cache->setBlock($reponse->getCreditResult);
var_dump($reponse);
return $reponse->credit;
/*} catch (SoapFault $fault) {
return $reponse->getCreditResult;
} catch (SoapFault $fault) {
$this->soaperror(__FUNCTION__, $fault, $client->__getLastRequest(), $client->__getLastResponse());
//Placer exception pour affichage message
return false;
}*/
}
}