Answer the question
In order to leave comments, you need to log in
Why is there no response from the api of Alfa-bank?
Good evening, there is such a code from the documentation of Alfa-Bank
define('USERNAME', '');
define('PASSWORD', '');
define('GATEWAY_URL', 'https://server/payment/rest/');
define('RETURN_URL', '');
/**
* ФУНКЦИЯ ДЛЯ ВЗАИМОДЕЙСТВИЯ С ПЛАТЕЖНЫМ ШЛЮЗОМ
*
* Для отправки POST запросов на платежный шлюз используется
* стандартная библиотека cURL.
*
* ПАРАМЕТРЫ
* method Метод из API.
* data Массив данных.
*
* ОТВЕТ
* response Ответ.
*/
function gateway($method, $data) {
$curl = curl_init(); // Инициализируем запрос
curl_setopt_array($curl, array(
CURLOPT_URL => GATEWAY_URL.$method, // Полный адрес метода
CURLOPT_RETURNTRANSFER => true, // Возвращать ответ
CURLOPT_POST => true, // Метод POST
CURLOPT_POSTFIELDS => http_build_query($data) // Данные в запросе
));
$response = curl_exec($curl); // Выполняем запрос
$response = json_decode($response, true); // Декодируем из JSON в массив
curl_close($curl); // Закрываем соединение
return $response; // Возвращаем ответ
}
/**
* ВЫВОД ФОРМЫ НА ЭКРАН
*/
if ($_SERVER['REQUEST_METHOD'] == 'GET' && !isset($_GET['orderId'])) {
echo '
<form method="post" action="/rest">
<label>Order number</label><br />
<input type="text" name="orderNumber" /><br />
<label>Amount</label><br />
<input type="text" name="amount" /><br />
<button type="submit">Submit</button>
</form>
';
}
/**
* ОБРАБОТКА ДАННЫХ ИЗ ФОРМЫ
*/
else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = array(
'userName' => USERNAME,
'password' => PASSWORD,
'orderNumber' => urlencode($_POST['orderNumber']),
'amount' => urlencode($_POST['amount']),
'returnUrl' => RETURN_URL
);
$response = gateway('register.do', $data);
if (isset($response['errorCode'])) { // В случае ошибки вывести ее
echo 'Ошибка #' . $response['errorCode'] . ': ' . $response['errorMessage'];
} else { // В случае успеха перенаправить пользователя на платежную форму
header('Location: ' . $response['formUrl']);
die();
}
}
/**
* ОБРАБОТКА ДАННЫХ ПОСЛЕ ПЛАТЕЖНОЙ ФОРМЫ
*/
else if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['orderId'])){
$data = array(
'userName' => USERNAME,
'password' => PASSWORD,
'orderId' => $_GET['orderId']
);
$response = gateway('getOrderStatus.do', $data);
// Вывод кода ошибки и статус заказа
echo '
<b>Error code:</b> ' . $response['ErrorCode'] . '<br />
<b>Order status:</b> ' . $response['OrderStatus'] . '<br />
';
}
Answer the question
In order to leave comments, you need to log in
Firstly, the form here is for demo purposes only.
Secondly, here is a typical scheme of the merchant's work with pre-registration of payment.
1. A request is made from the server side to the api.
2. Api returns a link to which you need to send the user.
3. The user on the site of the payment system entered all the data and clicked pay
4. Your site may be asked if you are ready to accept the fact of payment.
5. To which you answer "Yes. Send money to me"
6. The merchant starts the procedure for debiting funds.
7. An advice note arrives - a request to your site that you have received a payment.
7a If you didn't answer in the affirmative "I know everything is correct about the receipt of money", then the api
will try to repeat the advice note with a certain periodicity.
8. The user is sent via a link back to your site.
Well, on the side there can still be a reverse transition if the payment fails.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question