require_once("MedodoDiPagamento.php");
class EmsAbnAmro extends MedodoDiPagamento{
var $nome_metodo = "Ems Abn Amro";
var $storename = '';
var $username = '';
var $sharedSecret = '';
var $currency = '978';
var $customerid = '';//avevano detto che in questa maniera sarebbe stato riportato anche sull'estratto conto dell'esercente, invece pare non sia possibile, forse riguarda solo il cliente, lo tolgo
var $paymentMethod = '';//per forzare la selezione di un solo metodo
function hashEms($arrayOfStringToHash){
return hash('sha256', bin2hex(implode("",$arrayOfStringToHash)));
}
function demoInfo(){
return "Usa 4147463011110109 VISA (oppure https://emspay.stoplight.io/docs/online/f38bfbb844ac9-credit-card), data nel futuro e cvv di 3 cifre). Nell'ambiente di test, gli importi con ultima cifra dispari (es. 13.01€ o 13.99€) ***POSSONO*** DARE ESITO NEGATIVO. La pagina di pagamento dovrebbe essere in SSL perchè a fine procedura c'è un POST di dati che altrimenti genera un avviso.";
}
//per le autorizzazioni
// function ignoreSetupError() {
// return $this->importo === 0;
// }
function auto(){
// $this->Procedura->logga(array(
// 'identificativo_ordine' => $this->identificativo,
// 'ultimo_stato' => 'Fine procedura di conferma'
// ));
if($this->demo){
// $this->importo = "0.01";
$this->storename = '2320600367';
$this->username = '2320600367';
$this->sharedSecret = 'cw6!XkDpq;';
$url = 'https://test.ipg-online.com/connect/gateway/processing';
}
else $url = 'https://www.ipg-online.com/connect/gateway/processing';
// if(!is_tnx()) mail("c@localhost", "Primi pagamenti EMS", __FILE__.":".__LINE__."\n".print_r(array($_REQUEST, $_SERVER), true));
$this->importo = number_format(str_replace(",", ".", $this->importo), 2, ",", "");
$importoPunto = str_replace(",", ".", $this->importo);
switch($_GET[$this->step_var]){
default:
$this->Procedura->iniziato($this->nome_metodo);
//Please note that if you want to use this feature, you have to store the ‘txndatetime’ that you have submitted with the transaction request in order to be able to validate the response hash.
//(io nella s2s lo prendo dal post...)
$time = date("Y:m:d-H:i:s");
switch($GLOBALS['DATI']["lang"]) {
case "ita":
$lingua = "it_IT";
break;
case "fra":
$lingua = "fr_FR";
break;
case "spa":
$lingua = "es_ES";
break;
case "ger":
$lingua = "es_ES";
break;
case "nld":
$lingua = "nl_NL";
break;
default:
$lingua = "en_US";
break;
}
$form = '
';
//
//c'è anche un versione classic per cui è necessario specificare manualmente l'opzione mobile:
//
//
if(false&&$this->demo)
$form = "DUMP DEL FORM (DEMO): ".nl2br($this->Procedura->htmlentities($form)).str_replace("", '', $form);
else
$form .= $this->autoSubmitForm('form_pagamento_tnx');
return $form;
break;
case 'return_ok':
if($_POST) $this->controllaResponseHashEms();
//else potrebbe essere un back del browser o un ripristino sessione
return $this->Procedura->concluso();
// case 'return_ko':
// $this->controllaResponseHashEms();
// return $this->Procedura->annulla();
case 'error':
//responseFailURL viene usato sul tasto "annulla" ma anche in caso di errore, ad esempio "brand not supported"
if($_POST) $this->controllaResponseHashEms();
//else potrebbe essere un back del browser o un ripristino sessione
$this->Procedura->comunicazione_s2s($this->identificativo, "Errore: ".$_POST['approval_code']);
return $this->Procedura->errore($_POST['fail_reason']);//serve anche per loggare il tipo di errore perchè in caso di problemi con iDEAL ho visto che la s2s non viene fatta
case 's2s':
// mail("c@localhost", "Debug", __FILE__.":".__LINE__."\n".print_r(array($_REQUEST, $_SERVER), true));
$verificato = $this->controllaHashEms(
//chargetotal + sharedsecret + currency + txndatetime + storename + approval_code
array($_POST['chargetotal'],$this->sharedSecret,$this->currency,$_POST['txndatetime'],$this->storename,$_POST['approval_code']),
$_POST['notification_hash']
);
if($verificato){
$confermato = false;
switch(substr($_POST['approval_code'],0,1)){
case "Y"://‘Y’ indicates that the transaction has been successful
$info = "Esito positivo";
$confermato = true;
break;
case "N"://‘N’ indicates that the transaction has not been successful
$info = "Esito negativo";
break;
default://“?” indicates that the transaction has been successfully initialised, but a final result is not yet available since the transaction is now in a waiting status. The transaction status will be updated at a later stage.
$info = "Transazione in attesa";
break;
}
$info .= " (id: ".$_POST['ipgTransactionId'].", code: ".$_POST['approval_code'].")";
$identificativo = $this->identificativoFromUniqueID($_POST['oid']);
$this->Procedura->comunicazione_s2s($identificativo, $info);
if($confermato) $this->Procedura->confermato($identificativo);
}
//else c'è un log in controllaHashEms
$this->pulisciOutput();
die;
}
}
function controllaResponseHashEms(){//per curiosità e per log, il controllo utile è quello sul notification_hash della s2s
//sharedsecret + approval_code + chargetotal + currency + txndatetime + storename
return $this->controllaHashEms(array(
$this->sharedSecret,
$_POST['approval_code'],
$_POST['chargetotal']/*lo prendo da post perchè per vesuvio al momento returnok $this->importo si modifica dinamicamente dopo aver registrato la variazione via s2s*/,
$this->currency,
$_POST['txndatetime'],
$this->storename
), $_POST['response_hash']);
}
function controllaHashEms($calcola, $ricevuto){
$calcolato = $this->hashEms($calcola);
$ok = $calcolato == $ricevuto;
if(!$ok){
$e = 'Errore nella verifica delle informazioni ricevute dalla banca nello step '.$_GET[$this->step_var].' ('.$calcolato.' != '.$ricevuto.')'."\n".print_r($_POST, true);
trigger_error($e);
$this->Procedura->logga(array(
'identificativo_ordine' => $this->identificativo,
'ultimo_stato' => $e
));
}
return $ok;
}
}
?>