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