2015-01-23 13:09:30 +00:00
|
|
|
<?php
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
require_once('vn/web/util.php');
|
|
|
|
require_once(__DIR__.'/tpv.php');
|
2016-07-22 20:00:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets transaction confirmation from SOAP service.
|
|
|
|
**/
|
2018-05-23 10:14:20 +00:00
|
|
|
class ConfirmSoap extends Vn\Web\RestRequest {
|
|
|
|
function run($db) {
|
2016-07-22 20:00:27 +00:00
|
|
|
global $tpvConfirmSoap;
|
|
|
|
|
|
|
|
$tpvConfirmSoap = $this;
|
2018-05-23 10:14:20 +00:00
|
|
|
ini_set('soap.wsdl_cache_enabled', FALSE);
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$server = new SoapServer(__DIR__ .'/soap.wsdl');
|
|
|
|
$server->addFunction('procesaNotificacionSIS');
|
|
|
|
$server->handle();
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function procesaNotificacionSIS($XML) {
|
2016-07-22 20:00:27 +00:00
|
|
|
global $tpvConfirmSoap;
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$db = $tpvConfirmSoap->app->getSysConn();
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
$status = 'OK';
|
|
|
|
$requestString = $XML;
|
|
|
|
|
|
|
|
// Processes the request
|
|
|
|
|
|
|
|
try {
|
2018-05-23 10:14:20 +00:00
|
|
|
$xml = new SimpleXMLElement($requestString);
|
|
|
|
$params =(array) $xml->{'Request'};
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (!(isset($params['Ds_Amount'])
|
|
|
|
&& isset($params['Ds_Order'])
|
|
|
|
&& isset($params['Ds_MerchantCode'])
|
|
|
|
&& isset($params['Ds_Currency'])
|
|
|
|
&& isset($params['Ds_Response'])))
|
|
|
|
throw new Exception('Missing required parameters');
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
// Checks the signature
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$start = strpos($requestString, '<Request');
|
|
|
|
$end = strrpos($requestString, '</Request>');
|
|
|
|
$shaString = substr($requestString, $start, $end - $start + 10);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$key = $db->getValue(
|
2017-12-20 11:34:04 +00:00
|
|
|
'SELECT secretKey FROM tpvMerchant WHERE id = #'
|
2016-08-22 10:41:05 +00:00
|
|
|
,[$params['Ds_MerchantCode']]
|
2015-01-23 13:09:30 +00:00
|
|
|
);
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (sha1($shaString.$key) != $xml->{'Signature'})
|
|
|
|
throw new Exception('Invalid signature');
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
// Confirms the transaction
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
Tpv::confirm($db, $params);
|
2018-05-23 11:09:55 +00:00
|
|
|
} catch (Exception $e) {
|
2015-01-23 13:09:30 +00:00
|
|
|
$status = 'KO';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generates the response
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$responseString = file_get_contents(__DIR__ .'/soap-reply.xml');
|
|
|
|
$xml = new SimpleXMLElement($responseString);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
$response = $xml->{'Response'};
|
|
|
|
$response->{'Ds_Response_Merchant'} = $status;
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$xml->{'Signature'} = sha1($response->asXML().$key);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
return $xml->asXML();
|
2015-01-23 13:09:30 +00:00
|
|
|
/*
|
|
|
|
// Another way to generate the response
|
|
|
|
|
|
|
|
$xmlResponse =
|
|
|
|
'<Response Ds_Version="0.0">
|
|
|
|
<Ds_Response_Merchant>'. $status .'</Ds_Response_Merchant>
|
|
|
|
</Response>';
|
|
|
|
|
|
|
|
$xmlMessage =
|
|
|
|
'<Message>
|
|
|
|
'. $xmlResponse .'
|
2018-05-23 10:14:20 +00:00
|
|
|
<Signature>'. sha1($xmlResponse.$key) .'</Signature>
|
2015-01-23 13:09:30 +00:00
|
|
|
</Message>';
|
|
|
|
|
|
|
|
return $xmlMessage;
|
|
|
|
*/}
|
|
|
|
|