239 lines
7.6 KiB
PHP
239 lines
7.6 KiB
PHP
|
<?php
|
|||
|
/*****************************************************************************
|
|||
|
*
|
|||
|
* "open source" kit for Monetico paiement(TM)
|
|||
|
*
|
|||
|
* File "MoneticoPaiement_Ept.inc.php":
|
|||
|
*
|
|||
|
* Author : Euro-Information/e-Commerce
|
|||
|
* Version : 4.0
|
|||
|
* Date : 05/06/2014
|
|||
|
*
|
|||
|
* Copyright: (c) 2014 Euro-Information. All rights reserved.
|
|||
|
* License : see attached document "License.txt".
|
|||
|
*
|
|||
|
*****************************************************************************/
|
|||
|
|
|||
|
/*****************************************************************************
|
|||
|
*
|
|||
|
* Classe / Class : MoneticoPaiement_Ept
|
|||
|
*
|
|||
|
*****************************************************************************/
|
|||
|
|
|||
|
class MoneticoPaiement_Ept {
|
|||
|
|
|||
|
|
|||
|
public $sVersion; // Version du TPE - EPT Version (Ex : 3.0)
|
|||
|
public $sNumero; // Numero du TPE - EPT Number (Ex : 1234567)
|
|||
|
public $sCodeSociete; // Code Societe - Company code (Ex : companyname)
|
|||
|
public $sLangue; // Langue - Language (Ex : FR, DE, EN, ..)
|
|||
|
public $sUrlOK; // Url de retour OK - Return URL OK
|
|||
|
public $sUrlKO; // Url de retour KO - Return URL KO
|
|||
|
public $sUrlPaiement; // Url du serveur de paiement - Payment Server URL (Ex : https://p.monetico-services.com/paiement.cgi)
|
|||
|
|
|||
|
private $_sCle; // La cl<63> - The Key
|
|||
|
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
//
|
|||
|
// Constructeur / Constructor
|
|||
|
//
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
function __construct($sLangue = "FR") {
|
|||
|
|
|||
|
// contr<74>le de l'existence des constantes de param<61>trages.
|
|||
|
$aRequiredConstants = array('MONETICOPAIEMENT_KEY', 'MONETICOPAIEMENT_VERSION', 'MONETICOPAIEMENT_EPTNUMBER', 'MONETICOPAIEMENT_COMPANYCODE');
|
|||
|
$this->_checkEptParams($aRequiredConstants);
|
|||
|
|
|||
|
$this->sVersion = MONETICOPAIEMENT_VERSION;
|
|||
|
$this->_sCle = MONETICOPAIEMENT_KEY;
|
|||
|
$this->sNumero = MONETICOPAIEMENT_EPTNUMBER;
|
|||
|
$this->sUrlPaiement = MONETICOPAIEMENT_URLSERVER . MONETICOPAIEMENT_URLPAYMENT;
|
|||
|
|
|||
|
$this->sCodeSociete = MONETICOPAIEMENT_COMPANYCODE;
|
|||
|
$this->sLangue = $sLangue;
|
|||
|
|
|||
|
$this->sUrlOK = MONETICOPAIEMENT_URLOK;
|
|||
|
$this->sUrlKO = MONETICOPAIEMENT_URLKO;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
//
|
|||
|
// Fonction / Function : getCle
|
|||
|
//
|
|||
|
// Renvoie la cl<63> du TPE / return the EPT Key
|
|||
|
//
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
public function getCle() {
|
|||
|
return $this->_sCle;
|
|||
|
}
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
//
|
|||
|
// Fonction / Function : _checkEptParams
|
|||
|
//
|
|||
|
// Contr<74>le l'existence des constantes d'initialisation du TPE
|
|||
|
// Check for the initialising constants of the EPT
|
|||
|
//
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
private function _checkEptParams($aConstants) {
|
|||
|
|
|||
|
for ($i = 0; $i < count($aConstants); $i++)
|
|||
|
if (!defined($aConstants[$i]))
|
|||
|
die ("Erreur param<61>tre " . $aConstants[$i] . " ind<6E>fini");
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*****************************************************************************
|
|||
|
*
|
|||
|
* Classe / Class : MoneticoPaiement_Hmac
|
|||
|
*
|
|||
|
*****************************************************************************/
|
|||
|
|
|||
|
class MoneticoPaiement_Hmac {
|
|||
|
|
|||
|
private $_sUsableKey; // La cl<63> du TPE en format op<6F>rationnel / The usable TPE key
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
//
|
|||
|
// Constructeur / Constructor
|
|||
|
//
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
function __construct($oEpt) {
|
|||
|
|
|||
|
$this->_sUsableKey = $this->_getUsableKey($oEpt);
|
|||
|
}
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
//
|
|||
|
// Fonction / Function : _getUsableKey
|
|||
|
//
|
|||
|
// Renvoie la cl<63> dans un format utilisable par la certification hmac
|
|||
|
// Return the key to be used in the hmac function
|
|||
|
//
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
private function _getUsableKey($oEpt){
|
|||
|
|
|||
|
$hexStrKey = substr($oEpt->getCle(), 0, 38);
|
|||
|
$hexFinal = "" . substr($oEpt->getCle(), 38, 2) . "00";
|
|||
|
|
|||
|
$cca0=ord($hexFinal);
|
|||
|
|
|||
|
if ($cca0>70 && $cca0<97)
|
|||
|
$hexStrKey .= chr($cca0-23) . substr($hexFinal, 1, 1);
|
|||
|
else {
|
|||
|
if (substr($hexFinal, 1, 1)=="M")
|
|||
|
$hexStrKey .= substr($hexFinal, 0, 1) . "0";
|
|||
|
else
|
|||
|
$hexStrKey .= substr($hexFinal, 0, 2);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return pack("H*", $hexStrKey);
|
|||
|
}
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
//
|
|||
|
// Fonction / Function : computeHmac
|
|||
|
//
|
|||
|
// Renvoie le sceau HMAC d'une chaine de donn<6E>es
|
|||
|
// Return the HMAC for a data string
|
|||
|
//
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
public function computeHmac($sData) {
|
|||
|
|
|||
|
return strtolower(hash_hmac("sha1", $sData, $this->_sUsableKey));
|
|||
|
|
|||
|
// If you don't have PHP 5 >= 5.1.2 and PECL hash >= 1.1
|
|||
|
// you may use the hmac_sha1 function defined below
|
|||
|
//return strtolower($this->hmac_sha1($this->_sUsableKey, $sData));
|
|||
|
}
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
//
|
|||
|
// Fonction / Function : hmac_sha1
|
|||
|
//
|
|||
|
// RFC 2104 HMAC implementation for PHP >= 4.3.0 - Creates a SHA1 HMAC.
|
|||
|
// Eliminates the need to install mhash to compute a HMAC
|
|||
|
// Adjusted from the md5 version by Lance Rushing .
|
|||
|
//
|
|||
|
// Impl<70>mentation RFC 2104 HMAC pour PHP >= 4.3.0 - Cr<43>ation d'un SHA1 HMAC.
|
|||
|
// Elimine l'installation de mhash pour le calcul d'un HMAC
|
|||
|
// Adapt<70>e de la version MD5 de Lance Rushing.
|
|||
|
//
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
public function hmac_sha1 ($key, $data) {
|
|||
|
|
|||
|
$length = 64; // block length for SHA1
|
|||
|
if (strlen($key) > $length) { $key = pack("H*",sha1($key)); }
|
|||
|
$key = str_pad($key, $length, chr(0x00));
|
|||
|
$ipad = str_pad('', $length, chr(0x36));
|
|||
|
$opad = str_pad('', $length, chr(0x5c));
|
|||
|
$k_ipad = $key ^ $ipad ;
|
|||
|
$k_opad = $key ^ $opad;
|
|||
|
|
|||
|
return sha1($k_opad . pack("H*",sha1($k_ipad . $data)));
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
// function getMethode
|
|||
|
//
|
|||
|
// IN:
|
|||
|
// OUT: Donn<6E>es soumises par GET ou POST / Data sent by GET or POST
|
|||
|
// description: Renvoie le tableau des donn<6E>es / Send back the data array
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
function getMethode()
|
|||
|
{
|
|||
|
if ($_SERVER["REQUEST_METHOD"] == "GET")
|
|||
|
return $_GET;
|
|||
|
|
|||
|
if ($_SERVER["REQUEST_METHOD"] == "POST")
|
|||
|
return $_POST;
|
|||
|
|
|||
|
die ('Invalid REQUEST_METHOD (not GET, not POST).');
|
|||
|
}
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
// function HtmlEncode
|
|||
|
//
|
|||
|
// IN: chaine a encoder / String to encode
|
|||
|
// OUT: Chaine encod<6F>e / Encoded string
|
|||
|
//
|
|||
|
// Description: Encode special characters under HTML format
|
|||
|
// ********************
|
|||
|
// Encodage des caract<63>res sp<73>ciaux au format HTML
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
function HtmlEncode ($data)
|
|||
|
{
|
|||
|
$SAFE_OUT_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890._-";
|
|||
|
$encoded_data = "";
|
|||
|
$result = "";
|
|||
|
for ($i=0; $i<strlen($data); $i++)
|
|||
|
{
|
|||
|
if (strchr($SAFE_OUT_CHARS, $data{$i})) {
|
|||
|
$result .= $data{$i};
|
|||
|
}
|
|||
|
else if (($var = bin2hex(substr($data,$i,1))) <= "7F"){
|
|||
|
$result .= "&#x" . $var . ";";
|
|||
|
}
|
|||
|
else
|
|||
|
$result .= $data{$i};
|
|||
|
|
|||
|
}
|
|||
|
return $result;
|
|||
|
}
|
|||
|
?>
|