pay
<?php
/**
*
*
* USERNAME , .
* PASSWORD , .
* WSDL -.
* RETURN_URL ,
* .
*/
define(‘USERNAME’, ‘eraglonass-operator’);
define(‘PASSWORD’, ‘eraglonass’);
define(‘WSDL’, ‘https://server/payment/webservices/merchant-ws?wsdl’);
define(‘RETURN_URL’, ‘http://eraglonass.ru/ws.php’);
/**
*
* SoapClient.
*/
class Gateway extends SoapClient {
/**
*
* SOAP- WS_Security.
*
*
* SoapHeader SOAP-
*/
private function generateWSSecurityHeader() {
$xml = ‘
‘ . USERNAME . ‘
‘ . PASSWORD . ‘
‘ . sha1(mt_rand()) . ‘
‘;
return new
SoapHeader(‘http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecu
rity-secext-1.0.xsd’, ‘Security’, new SoapVar($xml, XSD_ANYXML), true);
}
/**
*
* SoapClient::__call().
*
*
* method API.
* data .
*
*
* response .
*/
public function __call($method, $data) {
$this->__setSoapHeaders($this->generateWSSecurityHeader()); //
return parent::__call($method, $data); // SoapClient::__call()
}
}
/**
*
*/
if ($_SERVER[‘REQUEST_METHOD’] == ‘GET’ && !isset($_GET[‘orderId’])) {
echo ‘
‘;
}
/**
*
*/
else if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
$client = new Gateway(WSDL);
$data = array(‘orderParams’ => array(
‘returnUrl’ => RETURN_URL,
‘merchantOrderNumber’ => urlencode($_POST[‘orderNumber’]),
‘amount’ => urlencode($_POST[‘amount’])
));
/**
*
* registerOrder
*
*
* merchantOrderNumber .
* amount .
* returnUrl , .
*
*
* :
* errorCode . .
* errorMessage .
*
* :
* orderId . .
* formUrl URL , .
*
*
* 0 .
* 1 ;
* .
* 3 () .
* 4 .
* 5 .
* 7 .
*/
$response = $client->__call(‘registerOrder’, $data);
/**
*
* registerOrderPreAuth
*
* , .
* registerOrder, registerOrderPreAuth.
*/
// $response = $client->__call(‘registerOrderPreAuth’, $data);
if ($response->errorCode != 0) { //
echo ‘ #’ . $response->errorCode . ‘: ‘ . $response->errorMessage;
} else { //
header(‘Location: ‘ . $response->formUrl);
die();
}
}
/**
*
*/
else if ($_SERVER[‘REQUEST_METHOD’] == ‘GET’ && isset($_GET[‘orderId’])){
$client = new Gateway(WSDL);
$data = array(‘orderParams’ => array(‘orderId’ => $_GET[‘orderId’]));
/**
*
* getOrderStatus
*
*
* orderId . .
*
*
* ErrorCode . .
* OrderStatus .
* . , .
*
*
* 0 .
* 2 .
* 5 ;
* ;
* .
* 6 .
* 7 .
*
*
* 0 , .
* 1 ( ).
* 2 .
* 3 .
* 4 .
* 5 ACS -.
* 6 .
*/
$response = $client->__call(‘getOrderStatus’, $data);
//
echo ‘
Error code: ‘ . $response->errorCode . ‘
Order status: ‘ . $response->orderStatus . ‘
‘;
}
?>