← Вернуться к списку тем

Ошибка sendInvoice

что не правильно?

Лог ошибки:

Array
(
    [ok] => 
    [error_code] => 400
    [description] => Bad Request: parameter "prices" is required
)
function sendInvoice($chat_id)
    {
	$data = [ 
		'chat_id' => $chat_id, 
		'title' => 'Invoice', 
		'description' => 'Test invoice', 
		'payload' => 'invoice', 
		'provider_token' => "284685063:TEST:Zjg3ZTE2YmIzZTZ3j", 
		'start_parameter' => 'payment-request', 
		'currency' => 'RUB', 
		'prices' => [[ 'label' => 'Test invoice', 'amount' => 10000]], 
	];
 
		
       return $send = requestToTelegram($data, "sendInvoice");
}

function requestToTelegram($data, $type)
    {
        $result = null;
		
        if (is_array($data)) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot'. TG_TOKEN . '/' . $type);
            curl_setopt($ch, CURLOPT_POST, count($data));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            $result = curl_exec($ch);
            curl_close($ch);
        }
        return $result1 = json_decode($result, true);
    }

Авторизуйтесь через Telegram, чтобы оставить комментарий.
Откройте по ссылке или QR бот @iMakeBot, нажмите кнопку Старт/Start.
Следуйте инструкциям бота.

  • iMakeBots [4 месяца назад]

    попробуй  так

    ...
    'prices' => ['label' => 'Test invoice', 'amount' => 10000],
    ...

    или так

    ...
    'prices' => json_encode(['label' => 'Test invoice', 'amount' => 10000]),
    ...
  • Андрей Разработчик [4 месяца назад → iMakeBots]

    1 вариант, ошибка такая же.
    2 вариант, ошибка:


    Array
    (
        [ok] => 
        [error_code] => 400
        [description] => Bad Request: expected an Array of labeled prices
    )