R
R
r4gn4r0k2019-04-16 10:19:40
API
r4gn4r0k, 2019-04-16 10:19:40

How to issue an invoice in QIWI API and not catch Error 400?

Hello. I tried to bill on my test site, but the server returned the code 400.
I sent a cUrl request, Bill id was generated by myself.

<?php


//АВТОРИЗАЦИЯ
$qiwi_secret = 'eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6ImF6YXYtMDAiLCJ1c2VyX2lkIjoiNzkwNjQ1Nzg4OTUiLCJzZWNyZXQiOiIwNWVhZmUwNzNjMTFlMmQzMmM5ZDNmYjcwZDU1Y2ExY***********************************';

$billid = time() + 10 * 5; // '893794793973'
$fields = [
  'amount' => 1.00,
  'currency' => 'RUB',
  'comment' => 'test',
  'expirationDateTime' => '2019-04-17T21:45:00+03:00',
  'phone' => '79064578895'
];
#Формируем ссылку для запроса
$link='https://api.qiwi.com/partner/bill/v1/bills/' . $billid;
$curl=curl_init(); #Сохраняем дескриптор сеанса cURL
#Устанавливаем необходимые опции для сеанса cURL
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_PUT,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($fields));
curl_setopt($curl, CURLOPT_HTTPHEADER, [
            'Accept: application/json',
            'Content-Type: application/json',
            'Authorization: Bearer ' . $qiwi_secret
        ]); 
$out=curl_exec($curl); #Инициируем запрос к API и сохраняем ответ в переменную
$code=curl_getinfo($curl,CURLINFO_HTTP_CODE); #Получим HTTP-код ответа сервера
curl_close($curl);  #Завершаем сеанс cURL
$Response=json_decode($out,true);
$code_answer=json_decode($code,true);
print_r($code_answer); 
echo '<br>';
print_r($Response); 
?>

Here is the response from the service:
[serviceName] => invoicing-api 
[errorCode] => http.message.conversion.failed 
[description] => Bad request 
[userMessage] => Bad request 
[dateTime] => 2019-04-16T10:05:35.188+03:00 
[traceId] => 958285f456ea5b95

What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ArchiKu, 2020-04-14
@ArchiKu

I write in C# and got the same error because the request was sent in Win1251 encoding, but it was necessary in UTF8 encoding
PS implemented interaction with the same service https://api.qiwi.com/partner/bill/v1/bills/ (creation invoice, invoice payment)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question