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 . " €";
//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();

View File

@ -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();

View File

@ -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);

View File

@ -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));
}