go-telegram-bot-api / telegram-bot-api

Golang bindings for the Telegram Bot API
https://go-telegram-bot-api.dev
MIT License
5.62k stars 868 forks source link

Bad Request with NewInvoice #593

Open cruzluna opened 1 year ago

cruzluna commented 1 year ago
                title := "Test invoice"
                description := "test description"
                payload := "200"
                currency := "USD"
                provider_token := os.Getenv("TBOTAPI_PAYMENT_TOKEN")
                prices := []tgbotapi.LabeledPrice{{Label: "USD", Amount: 200}} 
                new_invoice := tgbotapi.NewInvoice(update.Message.Chat.ID, title, description, payload, provider_token, "start_param", currency, prices)

                if _, err := bot.Send(new_invoice); err != nil{
                    log.Panic(err)
                }

I am attempting to send a test invoice with Strip and the invoice returns the following error:

Endpoint: sendInvoice, params: map[chat_id:1000494526 currency:USD description:test description payload:200
 prices:[{"label":"USD","amount":200}] 
provider_token:XXXXXX start_parameter:start_param 
suggested_tip_amounts:null 
title:Test invoice]

Endpoint: sendInvoice, response: {"ok":false,"error_code":400,"description":"Bad Request: expected an Array of suggested tip amounts"}

Bad Request: expected an Array of suggested tip amounts
panic: Bad Request: expected an Array of suggested tip amounts

I have tried using Request() and Send(), I get the same error. According to the Telegram API documentation the suggest tip is an optional parameter. How can I resolve this?

sSimuSs commented 1 year ago

You can set SuggestedTipAmounts as an empty int array

new_invoice := tgbotapi.NewInvoice(update.Message.Chat.ID, title, description, payload, provider_token, "start_param", currency, prices)
new_invoice.SuggestedTipAmounts = []int{}
if _, err := bot.Send(new_invoice); err != nil{
    log.Panic(err)
}
vladsaraykin commented 1 year ago

may be make it by default in method NewInvoice ? new_invoice.SuggestedTipAmounts = []int{}