require_once("MedodoDiPagamento.php"); class XPay extends MedodoDiPagamento{ var $nome_metodo = "Carta di credito"; var $apiKey = "5d952446-9004-4023-9eae-a527a152846b"; // Api-Key terminale contabilizzazione implicita: 5d952446-9004-4023-9eae-a527a152846b // Api-Key terminale contabilizzazione esplicita: 2d708950-50a1-434e-9a93-5d3ae2f1dd9f var $apiKey_demo = "5d952446-9004-4023-9eae-a527a152846b"; var $apiUrl = "https://xpay.nexigroup.com/api/phoenix-0.0/psp/api/v1/"; var $apiUrl_demo = "https://stg-ta.nexigroup.com/api/phoenix-0.0/psp/api/v1/"; var $descrizione = ''; var $restart_params = array( 'paymentid' => '' ); var $valuta = 'eur'; function setValuta($code){ //Three-letter ISO currency code, in lowercase. => https://www.iso.org/iso-4217-currency-codes.html $this->valuta = strtoupper($code); } function demoInfo(){ return 'Carte ambiente demo: qui'; } function apiCall($url, $requestBodyData = null){ $ch = curl_init($this->apiUrl . $url); if($requestBodyData) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestBodyData)); $rawCorrelationId = bin2hex(openssl_random_pseudo_bytes(16)); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "X-Api-Key: " . $this->apiKey, "Content-Type: application/json", "Correlation-Id: " . substr($rawCorrelationId, 0, 8)."-".substr($rawCorrelationId, 8, 4)."-".substr($rawCorrelationId, 12, 4)."-".substr($rawCorrelationId, 16, 4)."-".substr($rawCorrelationId, 20), )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $resultJson = curl_exec($ch); if(curl_errno($ch)) $e = "Curl error $ch durante al chiamata $url"; $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if($http_code != 200) $e = "Riposta $http_code durante al chiamata $url"; if($e){ trigger_error($e, E_USER_ERROR); $this->Procedura->errore($e); if($_SERVER['REMOTE_ADDR'] == '192.168.0.177' || $_GET['debugtnx']){ echo '
';
$debugBacktrace = debug_backtrace(); array_unshift($debugBacktrace, array('file'=>__FILE__, 'line'=>__LINE__, 'function'=>'debugTnx')); foreach($debugBacktrace as $debugLine) echo "".str_replace("/tnx/www/html/www/", "", $debugLine['file']).""." ".$debugLine['function']."()
";
$printMe = $e; ob_start(); if(is_object($printMe)||is_array($printMe)) print_r($printMe); else var_dump($printMe); echo htmlentities(ob_get_clean(), ENT_COMPAT|ENT_HTML401|ENT_SUBSTITUTE, 'UTF-8');
echo '';
// die;
}
if($_SERVER['REMOTE_ADDR'] == '192.168.0.177' || $_GET['debugtnx']){
echo '';
$debugBacktrace = debug_backtrace(); array_unshift($debugBacktrace, array('file'=>__FILE__, 'line'=>__LINE__, 'function'=>'debugTnx')); foreach($debugBacktrace as $debugLine) echo "".str_replace("/tnx/www/html/www/", "", $debugLine['file']).""." ".$debugLine['function']."()
";
$printMe = json_decode($resultJson, true); ob_start(); if(is_object($printMe)||is_array($printMe)) print_r($printMe); else var_dump($printMe); echo htmlentities(ob_get_clean(), ENT_COMPAT|ENT_HTML401|ENT_SUBSTITUTE, 'UTF-8');
echo '';
die;
}
}
curl_close($ch);
return json_decode($resultJson, true);
}
function auto(){
$this->indiLingua();
if($this->demo){
$this->apiUrl = $this->apiUrl_demo;
$this->apiKey = $this->apiKey_demo;
}
$this->importo = number_format(str_replace(",", ".", $this->importo), 2, ".", "");
switch($_GET[$this->step_var]){
default:
$this->Procedura->iniziato($this->nome_metodo);
$requestBodyData = array(
"order" => array(
"orderId"=> $this->identificativo,
"amount"=> $this->importo*100,
"currency"=> $this->valuta,
"customerInfo" => array(
"cardHolderName" => $this->cliente_nome,
"cardHolderEmail" => $this->cliente_email,
)
),
"paymentSession" => array(
"actionType"=> "PAY",
"language" => $this->lingua,
"amount"=> $this->importo*100,
// "recurrence" => array(
// "action" => "NO_RECURRING",
// ),
// "captureType" => "EXPLICIT",
// "exemptions" => "NO_PREFERENCE",
"resultUrl"=> $this->Procedura->genera_link_agg(array($this->step_var=>"return")),
"cancelUrl"=> $this->Procedura->genera_link_agg(array($this->step_var=>"cancel")),
"notificationUrl"=> $this->Procedura->genera_link_agg(array($this->step_var=>"s2s")),
),
);
$response = $this->apiCall("orders/hpp", $requestBodyData);
if(!$response['hostedPage']){
return $this->Procedura->errore();
}
else{
// $this->Procedura->comunicazione_s2s($this->identificativo, "Ricevuto securityToken: ".$response['securityToken']);
$this->Procedura->redirect($response['hostedPage']);
}
break;
case 'return':
$response = $this->apiCall("operations/".$_GET['paymentid']);
if($response['operationResult'] == 'EXECUTED'){
$this->Procedura->redirect($this->Procedura->genera_link_agg(array('paymentid'=>'', "step"=>"return_ok")));
}
else{
$this->Procedura->redirect($this->Procedura->genera_link_agg(array('paymentid'=>'', "step"=>"return_ko")));
}
case 'cancel':
return $this->Procedura->annulla();
case 'return_ok':
return $this->Procedura->concluso();
case 'return_ko':
return $this->Procedura->errore("Il pagamento non รจ andato a buon fine");
case 's2s':
$data = json_decode(file_get_contents('php://input'), true);
$this->Procedura->comunicazione_s2s($data['operation']['orderId'], "Operazione ".$data['operation']['operationId']." ".($data['operation']['operationAmount']/100).$data['operation']['operationCurrency']." ".$data['operation']['operationResult']);
if($data['operation']['operationResult'] === 'EXECUTED'){
$this->Procedura->confermato($data['operation']['orderId']);
}
else{
$this->Procedura->comunicazione_s2s($this->identificativo, print_r($data, true));
}
die;
// [eventId] => 523b8b26-2645-4adf-a179-251e4e1343fc
// [eventTime] => 2023-03-22 18:03:33.808
// [securityToken] => 1b6f0501ff0847f4a31b047d25d91aff
// [operation] => stdClass Object
// (
// [orderId] => 156
// [operationId] => 610189289389030819
// [channel] => ECOMMERCE
// [operationType] => AUTHORIZATION
// [operationResult] => EXECUTED
// [operationTime] => 2023-03-22 18:03:33.737
// [paymentMethod] => CARD
// [paymentCircuit] => VISA
// [paymentInstrumentInfo] => ***0906
// [paymentEndToEndId] => 972114
// [cancelledOperationId] =>
// [operationAmount] => 1500
// [operationCurrency] => EUR
// [customerInfo] => stdClass Object
// (
// [cardHolderName] =>
// [cardHolderEmail] => DEMO_carlo@tnx.it
// [billingAddress] =>
// [shippingAddress] =>
// [mobilePhoneCountryCode] =>
// [mobilePhone] =>
// [homePhone] =>
// [workPhone] =>
// [cardHolderAcctInfo] =>
// [merchantRiskIndicator] =>
// )
// [warnings] =>
// [paymentLinkId] =>
// [additionalData] => stdClass Object
// (
// [maskedPan] => 434994******0906
// [functionCode] => 100
// [cardCountry] => ITA
// [authorizationCode] => 972114
// [cardType] => MONETA
// [settlementDate] =>
// [transactionTime] => 1679504610188
// [threeDS] => S
// [authorizationStatus] => 000
// [cardExpiryDate] => 202304
// [amountInMerchantCurrency] =>
// [rrn] => 308100088501
// [schemaTID] =>
// [originalTraceId] => stdClass Object
// (
// [circuit] =>
// [originalTraceIdValue] =>
// [validationCode] =>
// [acquirerTransactionIdentifier] =>
// [extendedData] => A537MA08001-00000230322308100088501110001
// )
// [messageReasonCode] => 1510
// [omnichannelId] => MA08001-00000230322308100088501110001
// [posDataCode] => 100050J00100
// [exchangeRate] =>
// [cardId] => 79e199c6bfb632f58ee2e6810aa39f7abcabc11ce66360d602ca61408171e230
// [merchantCurrency] =>
// [status] => CAPTURED
// )
// )
}
}
function indiLingua(){
$this->lingua = $GLOBALS['DATI']["lang"];
}
}
?>