require_once("MedodoDiPagamento.php");
class WorldLine extends MedodoDiPagamento{
var $nome_metodo = "Carta di credito";
var $domain = 'pay.worldlineitalia.it';
var $licenseKeyAPI = '';//nell'area esercente https://pay.worldlineitalia.it/access/
var $licenseKeyEasyCheckout = '';//nell'area esercente https://pay.worldlineitalia.it/access/
var $accessToken = '';//si genera nell'area esercente (bottone sotto "License Key Easy Checkout")
function demoInfo(){
return "Per il pagamento usare 4111111111111111 (ok) o 5453010000073205 (KO). SSL sito obbligatorio. Area esercente (carlo@tnx.it / richard)";
}
function setValuta($currencyCode){
$this->valuta = $currencyCode;
}
function auto(){
if(function_exists("mod_pc_salva_servizio")) mod_pc_salva_servizio("worldline");
// $this->Procedura->logga(array(
// 'identificativo_ordine' => $this->identificativo,
// 'ultimo_stato' => 'Fine procedura di conferma'
// ));
if($this->demo){
$this->domain = 'pay-sandbox.worldlineitalia.it';
$this->licenseKeyAPI = 'VP0W734-9BF4D0S-HNG77CR-N1WW4DX';
$this->licenseKeyEasyCheckout = 'PFC0EN7-96M4Y98-M7BYSB0-HBQF6PV';
$this->accessToken = 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJxRlItM0w0SGo2RzNWbmNEYmo0alp6YmNhV2lMNmRtNmlYYUNtck9IQ2RRIn0.eyJleHAiOjIwNTcxMzkyODEsImlhdCI6MTc0MTc5MTA4NCwiYXV0aF90aW1lIjoxNzQxNzkxMDg0LCJqdGkiOiI1ODFlZDFkNS03ZjRkLTQ4NTktODk5NC04OGYyY2EzNTJiN2YiLCJpc3MiOiJodHRwczovL3Nzby53b3JsZGxpbmVpdGFsaWEuaXQvYXV0aC9yZWFsbXMvTWVyY2hhbnQiLCJhdWQiOlsicGctcGF5bWVudC1hcGktaW5ldCIsInBnLXBheW1lbnQtYXBpLWluZXQtc2FuZGJveCJdLCJzdWIiOiIxNjI3YjRmYi1mZWNhLTQ1MDEtYmQwYi0yOWZmOTUyYzQ5ZmYiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJwZy1wYXltZW50LWFwaS1pbmV0Iiwic2Vzc2lvbl9zdGF0ZSI6IjliNzQyMDQ2LWJhMjktNDg0Yy04ODM3LTgwYmZmNzMzOWQwMSIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cHM6Ly9wYXkuYXhlcHRhLml0IiwiaHR0cHM6Ly9wYXkud29ybGRsaW5laXRhbGlhLml0Il0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJvZmZsaW5lX2FjY2VzcyJdfSwicmVzb3VyY2VfYWNjZXNzIjp7InBnLXBheW1lbnQtYXBpLWluZXQtc2FuZGJveCI6eyJyb2xlcyI6WyJ1c2VyIl19fSwic2NvcGUiOiJvcGVuaWQgZW1haWwgb2ZmbGluZV9hY2Nlc3MgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoiY2FybG9AdG54Lml0IiwiZW1haWwiOiJjYXJsb0B0bnguaXQifQ.VcgI9bNveq8PbTapHaSOyJRUehbcOtSna74LoOPbXuW7FN9Yvz-imnH_HhmD6ENBbQHasd4nB0d6zh7sn3JVRDVTfEMdvx8qZ_1f41JR85xN9qLY1suAkvg4qJvNpCbh_0ItXvDwnvb4gE8gze1RyeHsLGjYjDNSW5TGkdC7ti-XbCDLAwtv_37ljAslx2f2OC4xKXH4437iNcw6g4U3jw6Qj1bM2VL7OqmA2DEjcnolK009xRL6SNg43zmg17njSaUglr70cys8bkqNFE7R73u0GCJ1hL894NmJ1KfraulXIzfe6LHwY7f0FbSaT-8LyV9ZY5GjRIGBO7gDo13q1g';
}
$this->importo = number_format(str_replace(",", ".", $this->importo), 2, ".", "");
if(!$this->lingua){
switch($GLOBALS['DATI']["lang"]) {
case "ita":
$this->lingua = "IT";
break;
case "fra":
$this->lingua = "FR";
break;
case "spa":
$this->lingua = "ES";
break;
case "ger":
$this->lingua = "DE";
break;
case "nld":
$this->lingua = "NL";
break;
default:
$this->lingua = "EN";
break;
}
}
switch($_GET[$this->step_var]){
default:
$init = $this->initPayment();
if($init->paymentID){
$this->Procedura->iniziato($this->nome_metodo);
return '
';
}
else{
$this->Procedura->comunicazione_s2s($this->identificativo, $init->message." (".$init->code.")");
trigger_error($init->message." (".$init->code.")");
return $this->Procedura->errore();
}
break;
case 'return_ok':
return $this->Procedura->concluso();
// case 'return_ko':
// return $this->Procedura->errore("descrizione");
case 'error':
return $this->Procedura->errore();
case 's2s':
$input = json_decode(file_get_contents("php://input"), true);
// mailtnx($_SERVER['TNX_SERVER_ID']=='demo'?'c@localhost':"carlo@tnx.it", "Worldline ".$input['description_status']." (".$input['transaction_code'].")", __FILE__.":".__LINE__."\n".print_r(array($input, $_REQUEST, $_SERVER), true));
if($input['additionals'][0]['value'] && $input['responseHash'] == hash_hmac('sha256', $input['paymentId'].$input['shopID'].$input['transaction_code'].$input['transactionAt'].$input['amount'], $this->licenseKeyAPI)){
$identificativo = $input['additionals'][0]['value'];
$this->Procedura->comunicazione_s2s($identificativo, $input['description_status']." (".$input['transaction_code'].")");
if($input['transaction_code'] == 'PG_01010') $this->Procedura->confermato($identificativo);
}
else{
$this->Procedura->comunicazione_s2s($this->identificativo, "Errore verifica firma: ".file_get_contents("php://input"));
}
break;
}
}
function initPayment(){
$data = [
'transaction_type' => 'PURCHASE',
'currency' => $this->valuta,
'language' => $this->lingua,
'amount' => $this->importo,
//fine parametri obbligatori
'redirect_successUrl' => $this->Procedura->genera_link_agg(array($this->step_var=>"return_ok")),
'redirect_failureUrl' => $this->Procedura->genera_link_agg(array($this->step_var=>"error")),
'callback_url' => $this->Procedura->genera_link_agg(array($this->step_var=>"s2s")),
'shopID' => $this->uniqueID(64),
'additionals' => [
['value' => $this->identificativo, 'key' => 'identificativo']
],
];
if($this->cliente_email) $data['notifications']['email'] = $this->cliente_email;
if($this->cliente_telefono) $data['notifications']['smartphone'] = $this->cliente_telefono;
if($data['notifications']) $data['notifications']['name'] = $this->cliente_nome;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://'.$this->domain.'/api/v1/payment/initPayment',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer '.$this->accessToken,
'x-license-key: '.$this->licenseKeyAPI
),
));
$response = json_decode(curl_exec($curl));
curl_close($curl);
return $response;
}
}
?>