From 69f2d5ec72b7971c2611e0d99d42c44b4496b382 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 7 Nov 2013 17:15:58 +0000 Subject: [PATCH] =?UTF-8?q?Int=C3=A9gration=20Paybox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/Bootstrap.php | 15 + application/configs/application.ini | 1 + application/controllers/PrestaController.php | 20 +- application/controllers/ReportController.php | 189 ++++++++++++- application/views/scripts/presta/index.phtml | 1 + application/views/scripts/report/cmd.phtml | 39 ++- .../views/scripts/report/deliver.phtml | 3 +- application/views/scripts/report/index.phtml | 14 +- .../views/scripts/report/paiement.phtml | 89 ++++++ .../presta.phtml => report/retour.phtml} | 0 library/Application/Form/Command.php | 2 +- library/Paybox/Config.php | 61 +++++ library/Paybox/Config/Prod.php | 17 ++ library/Paybox/Config/Test.php | 19 ++ library/Paybox/Response.php | 7 + library/Paybox/System.php | 257 ++++++++++++++++++ 16 files changed, 713 insertions(+), 21 deletions(-) create mode 100644 application/views/scripts/presta/index.phtml create mode 100644 application/views/scripts/report/paiement.phtml rename application/views/scripts/{presta/presta.phtml => report/retour.phtml} (100%) create mode 100644 library/Paybox/Config.php create mode 100644 library/Paybox/Config/Prod.php create mode 100644 library/Paybox/Config/Test.php create mode 100644 library/Paybox/Response.php create mode 100644 library/Paybox/System.php diff --git a/application/Bootstrap.php b/application/Bootstrap.php index eb3e0a9..268c8c0 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -90,4 +90,19 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap ); Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); } + + protected function _initRouter() + { + $this->bootstrap('frontController'); + $front = $this->getResource('frontController'); + $router = $front->getRouter(); + + //Route pour prestations + $route = new Zend_Controller_Router_Route('/id/:client/*', array( + 'controller' => 'presta', + 'action' => 'index', + )); + $router->addRoute('presta', $route); + return $router; + } } \ No newline at end of file diff --git a/application/configs/application.ini b/application/configs/application.ini index cb32d73..0a89cad 100644 --- a/application/configs/application.ini +++ b/application/configs/application.ini @@ -12,6 +12,7 @@ resources.layout.layoutPath = APPLICATION_PATH "/views" resources.view.basePath = APPLICATION_PATH "/views" autoloaderNamespaces[] = "Application_" autoloaderNamespaces[] = "Scores_" +autoloaderNamespaces[] = "Paybox_" ; Scores configuration profil.server.name = local diff --git a/application/controllers/PrestaController.php b/application/controllers/PrestaController.php index 8e4055b..b47eec8 100644 --- a/application/controllers/PrestaController.php +++ b/application/controllers/PrestaController.php @@ -1,5 +1,23 @@ getRequest(); + + $id = $request->getParam('client'); + + switch($id) { + //Prestation KOMPASS, livraison rapport pdf + case '144': + $siren = $request->getParam('siren'); + $url = '/report/index/siren/'.$siren; + $this->redirect($url); + break; + default: + //Erreur + break; + } + + } } \ No newline at end of file diff --git a/application/controllers/ReportController.php b/application/controllers/ReportController.php index 1b7eefb..2ba85e9 100644 --- a/application/controllers/ReportController.php +++ b/application/controllers/ReportController.php @@ -49,6 +49,12 @@ class ReportController extends Zend_Controller_Action 'siren'=>$response->Siren )); + //Session + $session->CmdSiren = $response->Siren; + $session->CmdRaisonSociale = $response->Nom; + $session->CmdAdresseL1 = $response->Adresse; + $session->CmdAdresseL2 = $response->CP . ' ' . $response->Ville;; + //Nombre $response = $ws->getLiens($siren); if ( $response !== false ) { @@ -92,7 +98,7 @@ class ReportController extends Zend_Controller_Action 'controller' => 'report', 'action' => 'index', 'siren' => $siren, - )); + ), null, true); //Affichage du formulaires $form = new Application_Form_Command(); @@ -118,19 +124,24 @@ class ReportController extends Zend_Controller_Action $commandM = new Application_Model_Command(); try { $commandM->insert($form->getValues()); + //Passage à la page suivante $url = $this->view->url(array( 'controller'=>'report', - 'action'=>'deliver', + 'action'=>'paiement', //deliver 'id' => $form->getValue('cmdId'), - )); + ), null, true); $this->redirect($url); + + //=> Aller à la page de paiement + + } catch (Zend_Db_Adapter_Exception $e) { $this->view->msg = "Impossible de passer la commande."; } } - } else { + } /*else { //Write the state to the session $cmdState = 1; @@ -139,15 +150,19 @@ class ReportController extends Zend_Controller_Action $this->redirect($url); } else { $session->state = $cmdState; + $this->view->Siren = $session->CmdSiren; + $this->view->RaisonSociale = $session->CmdRaisonSociale; + $this->view->AdresseL1 = $session->CmdAdresseL1; + $this->view->AdresseL2 = $session->CmdAdresseL2; } if ( !isset($session->CmdID) || empty($session->CmdID) ) { //Get the report if (intval($siren)>100) { - $report = new Scores_Partner_Report('indiscore3', $siren, 'mricois', 'ju2loh6o'); - $html = $report->getContent(); - + //$report = new Scores_Partner_Report('indiscore3', $siren, 'mricois', 'ju2loh6o'); + //$html = $report->getContent(); + $html = 'blabla'; if ( $html !== false ) { $c = Zend_Registry::get('config'); @@ -169,11 +184,160 @@ class ReportController extends Zend_Controller_Action } - } + }*/ + + //Test + $session = new Zend_Session_Namespace('Cmd'); + $this->view->CmdID = 'test'; + $this->view->Siren = $session->CmdSiren; + $this->view->RaisonSociale = $session->CmdRaisonSociale; + $this->view->AdresseL1 = $session->CmdAdresseL1; + $this->view->AdresseL2 = $session->CmdAdresseL2; $this->view->form = $form; $this->view->siren = $siren; + } + + /** + * Sélection du mode de paiement + */ + public function paiementAction() + { + $this->_helper->layout()->disableLayout(); + + $request = $this->getRequest(); + + //Commande ID + $cmdId = $request->getParam('id'); + + //Write the state to the session + $cmdState = 4; + + $session = new Zend_Session_Namespace('Cmd'); + /*if ( $session->state > $cmdState || $session->CmdID != $cmdId ) { + $url = $this->view->url(array( + 'controller' => 'report', + 'action' => 'index', + 'siren' => $session->CmdSiren, + ), null, true); + $this->redirect($url); + } else { + $session->state = $cmdState; + }*/ + + $this->view->CmdID = $session->CmdID; + + $cmdId = '525ffc4501a4d'; + $this->view->CmdID = $cmdId; + $this->view->Siren = $session->CmdSiren; + $this->view->RaisonSociale = $session->CmdRaisonSociale; + $this->view->AdresseL1 = $session->CmdAdresseL1; + $this->view->AdresseL2 = $session->CmdAdresseL2; + + //Lire la bdd + $commandM = new Application_Model_Command(); + $row = $commandM->fetchRow('cmdId="'.$cmdId.'"'); + if ($row !== null) { + + //Paybox : Liste des types de paiements possible + $paybox = new Paybox_System(); + $paybox->setUrlPaiement(); + $paybox->setEmail($row->email); + $paybox->setReference($cmdId); + $paybox->setMontant(10.00); + $paybox->setUrlParameters(); + $paybox->calculateHMAC(); + + //Set PBX_EFFECTUE, PBX_REFUSE, PBX_ANNULE, PBX_ATTENTE, PBX_REPONDRE_A + + $this->view->PayboxUrl = $paybox->getFormUrl(); + $this->view->PayboxValues = $paybox->getFormParameters(); + + } + + + + } + + /** + * + */ + public function retourAction() + { + $this->_helper->layout()->disableLayout(); + + $request = $this->getRequest(); + + //PBX_RETOUR + /* + * eta:E + * ref:R => Référence commande (précisée dans PBX_CMD) + * auto:A => numéro d'Autorisation (numéro remis par le centre d’autorisation) + * type:P => Type de Paiement retenu (cf. PBX_TYPEPAIEMENT) + * transaction:S => Numéro de TranSaction Paybox + * pays:Y => Code paYs de la banque émettrice de la carte. Format : ISO 3166 (alphabétique) + * sign:K => Signature sur les variables de l’URL. Format : url-encodé + */ + + /* Code retour eta:E +00000 +Opération réussie. +00001 +La connexion au centre d’autorisation a échoué ou une erreur interne est survenue. Dans ce cas, il est souhaitable de faire une tentative sur le site secondaire : tpeweb1.paybox.com. +001xx +Paiement refusé par le centre d’autorisation [voir §12.1 Codes réponses du centre d’autorisation]. +En cas d’autorisation de la transaction par le centre d’autorisation de la banque ou de l’établissement financier privatif, le code erreur “00100” sera en fait remplacé directement par “00000”. +=> Liste des codes erreurs + +00003 +Erreur Paybox. Dans ce cas, il est souhaitable de faire une tentative sur le site secondaire FQDN tpeweb1.paybox.com. +00004 +Numéro de porteur ou cryptogramme visuel invalide. +00006 +Accès refusé ou site/rang/identifiant incorrect. +00008 +Date de fin de validité incorrecte. +00009 +Erreur de création d’un abonnement. +00010 +Devise inconnue. +00011 +Montant incorrect. +00015 +Paiement déjà effectué. +00016 +Abonné déjà existant (inscription nouvel abonné). Valeur ‘U’ de la variable PBX_RETOUR. +00021 +Carte non autorisée. +00029 +Carte non conforme. Code erreur renvoyé lors de la documentation de la variable « PBX_EMPREINTE ». +00030 +Temps d’attente > 15 mn par l’internaute/acheteur au niveau de la page de paiements. +00031 +Réservé +00032 +Réservé +00033 +Code pays de l’adresse IP du navigateur de l’acheteur non autorisé. +00040 +Opération sans authentification 3-DSecure, bloquée par le filtre. +99999 +Opération en attente de validation par l’émetteur du moyen de paiement. + */ + + + //Get cmd id + $eta = $request->getParam('eta'); + + + + //Request PAYBOX to validate the payment + //Valider les bons de commande + + + + } @@ -183,6 +347,10 @@ class ReportController extends Zend_Controller_Action $request = $this->getRequest(); + //Get the response from PAYBOX + + + $c = Zend_Registry::get('config'); $pathCmd = $c->profil->path->data; @@ -194,6 +362,11 @@ class ReportController extends Zend_Controller_Action $session = new Zend_Session_Namespace('Cmd'); if ( $session->state > $cmdState || $session->CmdID != $cmdId ) { + $url = $this->view->url(array( + 'controller' => 'report', + 'action' => 'index', + 'siren' => $session->CmdSiren, + ), null, true); $this->redirect($url); } else { $session->state = $cmdState; diff --git a/application/views/scripts/presta/index.phtml b/application/views/scripts/presta/index.phtml new file mode 100644 index 0000000..c0ed4e0 --- /dev/null +++ b/application/views/scripts/presta/index.phtml @@ -0,0 +1 @@ +
Erreur !
diff --git a/application/views/scripts/report/cmd.phtml b/application/views/scripts/report/cmd.phtml index afb0c25..26c9636 100644 --- a/application/views/scripts/report/cmd.phtml +++ b/application/views/scripts/report/cmd.phtml @@ -21,12 +21,36 @@
msg?>
-

* Champs obligatoires

- -
+ +
+ +
+ +

Informations de la commande

+ +
+
Siren :
+
Siren?>
+
Raison Sociale :
+
RaisonSociale?>
+
Adresse :
+
AdresseL1?>
+
+
AdresseL2?>
+
+ +
Prix : 10,00 €
+ +
+ +
+ +

Informations personnelles

+

* Champs obligatoires

+
@@ -135,7 +159,11 @@
- +
+ +
+ +
@@ -153,5 +181,4 @@ inlineScript(); ?> - - + \ No newline at end of file diff --git a/application/views/scripts/report/deliver.phtml b/application/views/scripts/report/deliver.phtml index 7837b11..4aa0f7f 100644 --- a/application/views/scripts/report/deliver.phtml +++ b/application/views/scripts/report/deliver.phtml @@ -84,5 +84,4 @@ inlineScript(); ?> - - + \ No newline at end of file diff --git a/application/views/scripts/report/index.phtml b/application/views/scripts/report/index.phtml index 59bb578..de24e59 100644 --- a/application/views/scripts/report/index.phtml +++ b/application/views/scripts/report/index.phtml @@ -73,8 +73,17 @@ +
- +
+
Prix : 10,00 €
+
+ +
+ Commander +
+ +
@@ -87,5 +96,4 @@ inlineScript(); ?> - - + \ No newline at end of file diff --git a/application/views/scripts/report/paiement.phtml b/application/views/scripts/report/paiement.phtml new file mode 100644 index 0000000..9168887 --- /dev/null +++ b/application/views/scripts/report/paiement.phtml @@ -0,0 +1,89 @@ + + + + + + +Kompass - Achat Bilan Financier + + + + + + +
+ + + + CmdID ) {?> + +
+ + + +
+ +
+ +

Informations de la commande

+ +
+
Siren :
+
Siren?>
+
Raison Sociale :
+
RaisonSociale?>
+
Adresse :
+
AdresseL1?>
+
+
AdresseL2?>
+
+ +
Prix : 10,00 €
+ +
+ +
+ +

Sélection du mode de paiement

+ + PayboxValues) {?> + + + + PayboxValues as $field) {?> + + + + + + + + Une fois le paiement effectué merci de cliquer sur le bouton "Retour boutique" afin de + consulter vos documents. + + + +
+ +
+ + + + + +
Erreur !
+ + + + + + +
+ + inlineScript(); ?> + + \ No newline at end of file diff --git a/application/views/scripts/presta/presta.phtml b/application/views/scripts/report/retour.phtml similarity index 100% rename from application/views/scripts/presta/presta.phtml rename to application/views/scripts/report/retour.phtml diff --git a/library/Application/Form/Command.php b/library/Application/Form/Command.php index 4bd8f89..2292ff3 100644 --- a/library/Application/Form/Command.php +++ b/library/Application/Form/Command.php @@ -79,7 +79,7 @@ class Application_Form_Command extends Zend_Form ) ); $this->addElement('submit', 'submit',array( - 'label' => 'Commander', + 'label' => 'Mode de paiement', 'ignore' => true, ) ); diff --git a/library/Paybox/Config.php b/library/Paybox/Config.php new file mode 100644 index 0000000..4417db4 --- /dev/null +++ b/library/Paybox/Config.php @@ -0,0 +1,61 @@ +variables as $var => $value ) { + $this->{'PBX_'.$var} = $value; + } + + $this->KEY = $config->key; + $this->SERVER = $config->server; + + } + + /** + * Check server availability and set the paiement url + * @return boolean + */ + public function checkservers() + { + $serveurOK = ""; + foreach($this->SERVER as $serveur) + { + $doc = new DOMDocument(); + $doc->loadHTMLFile($serveur['ping']); + $server_status = ""; + $element = $doc->getElementById('server_status'); + if($element){ + $server_status = $element->textContent; + } + if($server_status == "OK"){ + //Le serveur est prêt et les services opérationnels + $serveurOK = $serveur; + $this->PAIEMENT_URL = $serveur['url']; + return true; + break; + } + // else : La machine est disponible mais les services ne le sont pas. + } + if(!$serveurOK){ + return false; + } + } + +} \ No newline at end of file diff --git a/library/Paybox/Config/Prod.php b/library/Paybox/Config/Prod.php new file mode 100644 index 0000000..03e6492 --- /dev/null +++ b/library/Paybox/Config/Prod.php @@ -0,0 +1,17 @@ + "https://tpeweb.paybox.com/load.html", + 'url' => "https://tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi", + ), + array( + 'ping' => "https://tpeweb1.paybox.com/load.html", + 'url' => "https://tpeweb1.paybox.com/cgi/MYchoix_pagepaiement.cgi", + ), + ); + +} \ No newline at end of file diff --git a/library/Paybox/Config/Test.php b/library/Paybox/Config/Test.php new file mode 100644 index 0000000..a35e625 --- /dev/null +++ b/library/Paybox/Config/Test.php @@ -0,0 +1,19 @@ + "https://preprod-tpeweb.paybox.com/load.html", + 'url' => "https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi", + ), + ); + + public $variables = array( + 'SITE' => '1999888', + 'RANG' => '32', + 'IDENTIFIANT' => '110647233', + ); + +} \ No newline at end of file diff --git a/library/Paybox/Response.php b/library/Paybox/Response.php new file mode 100644 index 0000000..9ddeea1 --- /dev/null +++ b/library/Paybox/Response.php @@ -0,0 +1,7 @@ + Pour le test clé définie + +Page de paiement paybox +======================== +Personnalisation +- Le logo en haut de page +- L’affichage du logo Paybox +- Les boutons de validation/annulation/retour boutique +- Les langues +- Le fond d’écran +- Et bien d’autres options via un fichier CSS +=> Transmettre ces éléments à PayBox + + + +*/ +class Paybox_System extends Paybox_Config +{ + /** + * Algorithme utilisé pour la signature du message + * SHA512, RIPEMD160, SHA224, SHA256, SHA384, MDC2 + * @var string + */ + protected $PBX_HASH = 'SHA512'; + + /** + * Date à laquelle l’empreinte HMAC a été calculée. Doit être URL-encodée + * Date au format ISO8601. + * @var string + */ + protected $PBX_TIME; + + protected $PBX_HMAC; + + /** + * Référence de commande + * @var string + */ + protected $PBX_CMD; + + /** + * Devise (monnaie) + * Code monnaie de la transaction suivant la norme ISO 4217 (code numérique) + * Exemples : + * - Euro : 978 + * - US Dollar : 840 + * @var string + */ + protected $PBX_DEVISE = '978'; + + /** + * URL de retour en cas de succès + * @var string + */ + protected $PBX_EFFECTUE; + + /** + * URL de retour en cas d'abandon + * @var string + */ + protected $PBX_ANNULE; + + /** + * URL de retour en cas de refus de paiement + * @var string + */ + protected $PBX_REFUSE; + + /** + * Configuration de la réponse + * Chaine : concaténé par ; + * @var string + */ + protected $PBX_RETOUR; + + /** + * Langue de la page de paiement + * @var string + */ + protected $PBX_LANGUE = ''; + + /** + * Adresse email du client + * @var string + */ + protected $PBX_PORTEUR = ''; + + /** + * TEST + * Code erreur à renvoyer pour tests + * @var string + */ + protected $PBX_ERRORCODETEST; + + /** + * ORDRE des champs pour l'affichage du formulaire et le calcul du HMAC + * @var array + */ + protected $stackfields = array( + 'PBX_SITE', + 'PBX_RANG', + 'PBX_IDENTIFIANT', + 'PBX_TOTAL', + 'PBX_DEVISE', + 'PBX_CMD', + 'PBX_PORTEUR', + 'PBX_RETOUR', + 'PBX_HASH', + 'PBX_TIME', + ); + + protected $URL_PAIEMENT; + + protected $URL_PARAMETERS; + + public function __construct() { + parent::__construct(); + } + + public function getFormUrl() + { + return $this->URL_PAIEMENT; + } + + public function getFormParameters() + { + $params = array(); + foreach ( $this->stackfields as $field ) { + $value = $this->{$field}; + if ( !empty($value) ) { + $params[] = array( + 'name' => $field, + 'value' => $value, + ); + } + } + + $params[] = array( + 'name' => 'PBX_HMAC', + 'value' => $this->PBX_HMAC, + ); + + return $params; + } + + /** + * Défini le montant + * @param float $value + */ + public function setMontant($value) + { + $montant = str_replace(',', '', number_format($value, 2, ',', '')); + $this->PBX_TOTAL = $montant; + } + + /** + * Set the command reference + * @param string $value + */ + public function setReference($value) + { + $this->PBX_CMD = $value; + } + + /** + * Set user email + * @param string $value + */ + public function setEmail($value) + { + $this->PBX_PORTEUR = $value; + } + + /** + * + */ + public function setUrlParameters() + { + $dateTime = date('c'); + $this->PBX_TIME = $dateTime; + $params = ''; + $i = 0; + foreach ( $this->stackfields as $field ) { + $value = $this->{$field}; + if ( !empty($value) ) { + $params.= $field.'='.$value; + $i++; + if ( $i < count($this->stackfields) ) { + $params.= '&'; + } + } + + // If the last char is &, remove it + if ( substr($params, -1) == '&' ) { + $params = substr($params, 0, strlen($params)-1); + } + } + + $this->URL_PARAMETERS = $params; + } + + /** + * Return the paiement URL if available + * @return string|boolean + */ + public function setUrlPaiement() + { + $this->checkservers(); + + if ( !empty($this->URL_PAEIMENT) ) { + return $this->URL_PAIEMENT; + } + + return false; + } + + /** + * Calcul le HMAC + * @return void + */ + public function calculateHMAC() + { + $binKey = pack("H*", $this->KEY); + $this->PBX_HMAC = strtoupper(hash_hmac('sha512', $this->URL_PARAMETERS, $binKey)); + } + +} \ No newline at end of file