diff --git a/application/controllers/ReportController.php b/application/controllers/ReportController.php index 6711af4..7d70040 100644 --- a/application/controllers/ReportController.php +++ b/application/controllers/ReportController.php @@ -250,12 +250,13 @@ class ReportController extends Zend_Controller_Action $this->view->montant = $c->profil->report->montant . " €"; //Paybox - $paybox = new Paybox_System(); + $paybox = new Paybox_System(true); $paybox->setUrlPaiement(); $paybox->setEmail($row->email); $paybox->setReference($cmdId); $paybox->setMontant($c->profil->report->montant); - $paybox->setUrlParameters("http://partner.sd.dev/report/retour"); + $paybox->setUrlParameters("http://".$request->getHttpHost()."/report/retour"); + //$paybox->setUrlParameters(); $paybox->calculateHMAC(); $this->view->PayboxUrl = $paybox->getFormUrl(); diff --git a/library/Paybox/Config.php b/library/Paybox/Config.php index ac0fd59..4268802 100644 --- a/library/Paybox/Config.php +++ b/library/Paybox/Config.php @@ -13,9 +13,9 @@ class Paybox_Config protected $URL_PAIEMENT; - public function __construct() + public function __construct($test = false) { - if (APPLICATION_ENV == 'production') { + if ($test === false) { $config = new Paybox_Config_Prod(); } else { $config = new Paybox_Config_Test(); diff --git a/library/Paybox/Response.php b/library/Paybox/Response.php index ba5cb03..c93916e 100644 --- a/library/Paybox/Response.php +++ b/library/Paybox/Response.php @@ -7,7 +7,7 @@ class Paybox_Response protected $errCode = 0; - protected $errLabel = 'Erreur inconnue.'; + protected $errLabel = 'Impossible de valider le paiement.'; public function __construct(){} @@ -29,12 +29,22 @@ class Paybox_Response $i = 0; $max = count($values); foreach( $values as $key => $val ) { + + if ( !in_array($key, array('eta', 'id', 'type', 'mt', 'auto', 'idtrans'))) + continue; + $this->data.= $key."=".urlencode($val); $i++; + if ( $i<$max ) { $this->data.= '&'; } } + + // If the last char is &, remove it + if ( substr($this->data, -1) == '&' ) { + $this->data = substr($this->data, 0, strlen($this->data)-1); + } } /** @@ -43,7 +53,7 @@ class Paybox_Response */ protected function setSign($value) { - $this->sign = base64_decode(urldecode($value)); + $this->sign = base64_decode($value); } /** @@ -51,20 +61,18 @@ class Paybox_Response */ protected function isDataSign() { - if ($this->data === null) + if (empty($this->data)) return false; - if ($this->sign === null) + if (empty($this->sign)) return false; - $fp = fopen(__DIR__ . '/pubkey.pem', 'r'); - $cert = fread($fp, 8192); - fclose($fp); + $cert = file_get_contents(__DIR__ . '/pubkey.pem'); - $pubkeyid = openssl_get_publickey($cert); + $pubkeyid = openssl_pkey_get_public($cert); // state whether signature is okay or not - $ok = openssl_verify($this->data, $this->sign, $pubkeyid); + $ok = openssl_verify($this->data, $this->sign, $pubkeyid, OPENSSL_ALGO_SHA1); // free the key from memory openssl_free_key($pubkeyid); diff --git a/library/Paybox/System.php b/library/Paybox/System.php index 36a7953..49527f9 100644 --- a/library/Paybox/System.php +++ b/library/Paybox/System.php @@ -151,8 +151,8 @@ class Paybox_System extends Paybox_Config protected $URL_PARAMETERS; - public function __construct() { - parent::__construct(); + public function __construct($test = false) { + parent::__construct($test); } public function getFormUrl() @@ -238,11 +238,11 @@ class Paybox_System extends Paybox_Config $params.= '&'; } } + } - // If the last char is &, remove it - if ( substr($params, -1) == '&' ) { - $params = substr($params, 0, strlen($params)-1); - } + // If the last char is &, remove it + if ( substr($params, -1) == '&' ) { + $params = substr($params, 0, strlen($params)-1); } $this->URL_PARAMETERS = $params; @@ -270,6 +270,7 @@ class Paybox_System extends Paybox_Config public function calculateHMAC() { $binKey = pack("H*", $this->KEY); + echo "URL_PARAMETERS : ".$this->URL_PARAMETERS; $this->PBX_HMAC = strtoupper(hash_hmac('sha512', $this->URL_PARAMETERS, $binKey)); }