# Пример обработчика на PHP

```php
<?php
$secret = 'secret2'; // Секретный ключ №2 из настроек магазина
$amount = 100.32; // Сумма заказа
$currency = 'RUB'; // Валюта

if($_SERVER['REQUEST_METHOD'] !== 'POST') {
	die("wrong request method");
}

if($_POST['amount'] < $amount) {
	die("wrong amount");
}

if($_POST['currency'] !== $currency) {
	die("wrong currency");
}

function getIP() {
	$ip = $_SERVER['REMOTE_ADDR'];
		
	if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	}
		
	if(isset($_SERVER['HTTP_X_REAL_IP'])) {
		$ip = $_SERVER['HTTP_X_REAL_IP'];
	}
	
	if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
		$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
	}

	$explode = explode(',', $ip);
		
	if(count($explode) > 1) {
		$ip = $explode[0];
	}
	
	return trim($ip);
}
	
// Проверка на IP адрес сервиса (по желанию)
$ctx = stream_context_create([
	'http' => [
        	'timeout' => 10
    	]
]);

$ips = json_decode(file_get_contents('https://aaio.io/api/public/ips', false, $ctx));
if (isset($ips->list) && !in_array(getIP(), $ips->list)) {
	die("hacking attempt");
}
// Конец проверки на IP адрес сервиса

$sign = hash('sha256', implode(':', [$_POST['merchant_id'], $_POST['amount'], $_POST['currency'], $secret, $_POST['order_id']]));

if (!hash_equals($_POST['sign'], $sign)) {
	die("wrong sign");
}

//Так же, рекомендуется проверять не был ли этот заказ уже оплачен или отменен
//Оплата прошла успешно, можно проводить операцию.

die('OK');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.aaio.so/priem-platezhei/opoveshenie-ob-oplate-zakaza/primer-obrabotchika-na-php.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
