This commit is contained in:
Michael RICOIS 2013-11-15 08:24:12 +00:00
parent ceca8dc894
commit 30f488204b
4 changed files with 29 additions and 19 deletions

View File

@ -250,12 +250,13 @@ class ReportController extends Zend_Controller_Action
$this->view->montant = $c->profil->report->montant . " €"; $this->view->montant = $c->profil->report->montant . " €";
//Paybox //Paybox
$paybox = new Paybox_System(); $paybox = new Paybox_System(true);
$paybox->setUrlPaiement(); $paybox->setUrlPaiement();
$paybox->setEmail($row->email); $paybox->setEmail($row->email);
$paybox->setReference($cmdId); $paybox->setReference($cmdId);
$paybox->setMontant($c->profil->report->montant); $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(); $paybox->calculateHMAC();
$this->view->PayboxUrl = $paybox->getFormUrl(); $this->view->PayboxUrl = $paybox->getFormUrl();

View File

@ -13,9 +13,9 @@ class Paybox_Config
protected $URL_PAIEMENT; protected $URL_PAIEMENT;
public function __construct() public function __construct($test = false)
{ {
if (APPLICATION_ENV == 'production') { if ($test === false) {
$config = new Paybox_Config_Prod(); $config = new Paybox_Config_Prod();
} else { } else {
$config = new Paybox_Config_Test(); $config = new Paybox_Config_Test();

View File

@ -7,7 +7,7 @@ class Paybox_Response
protected $errCode = 0; protected $errCode = 0;
protected $errLabel = 'Erreur inconnue.'; protected $errLabel = 'Impossible de valider le paiement.';
public function __construct(){} public function __construct(){}
@ -29,12 +29,22 @@ class Paybox_Response
$i = 0; $i = 0;
$max = count($values); $max = count($values);
foreach( $values as $key => $val ) { foreach( $values as $key => $val ) {
if ( !in_array($key, array('eta', 'id', 'type', 'mt', 'auto', 'idtrans')))
continue;
$this->data.= $key."=".urlencode($val); $this->data.= $key."=".urlencode($val);
$i++; $i++;
if ( $i<$max ) { if ( $i<$max ) {
$this->data.= '&'; $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) 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() protected function isDataSign()
{ {
if ($this->data === null) if (empty($this->data))
return false; return false;
if ($this->sign === null) if (empty($this->sign))
return false; return false;
$fp = fopen(__DIR__ . '/pubkey.pem', 'r'); $cert = file_get_contents(__DIR__ . '/pubkey.pem');
$cert = fread($fp, 8192);
fclose($fp);
$pubkeyid = openssl_get_publickey($cert); $pubkeyid = openssl_pkey_get_public($cert);
// state whether signature is okay or not // 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 // free the key from memory
openssl_free_key($pubkeyid); openssl_free_key($pubkeyid);

View File

@ -151,8 +151,8 @@ class Paybox_System extends Paybox_Config
protected $URL_PARAMETERS; protected $URL_PARAMETERS;
public function __construct() { public function __construct($test = false) {
parent::__construct(); parent::__construct($test);
} }
public function getFormUrl() public function getFormUrl()
@ -238,11 +238,11 @@ class Paybox_System extends Paybox_Config
$params.= '&'; $params.= '&';
} }
} }
}
// If the last char is &, remove it // If the last char is &, remove it
if ( substr($params, -1) == '&' ) { if ( substr($params, -1) == '&' ) {
$params = substr($params, 0, strlen($params)-1); $params = substr($params, 0, strlen($params)-1);
}
} }
$this->URL_PARAMETERS = $params; $this->URL_PARAMETERS = $params;
@ -270,6 +270,7 @@ class Paybox_System extends Paybox_Config
public function calculateHMAC() public function calculateHMAC()
{ {
$binKey = pack("H*", $this->KEY); $binKey = pack("H*", $this->KEY);
echo "URL_PARAMETERS : ".$this->URL_PARAMETERS;
$this->PBX_HMAC = strtoupper(hash_hmac('sha512', $this->URL_PARAMETERS, $binKey)); $this->PBX_HMAC = strtoupper(hash_hmac('sha512', $this->URL_PARAMETERS, $binKey));
} }