1
0
telegram/answer_pre_checkout_query.go

56 lines
1.9 KiB
Go
Raw Normal View History

package telegram
import json "github.com/pquerna/ffjson/ffjson"
2018-04-19 13:02:15 +00:00
// AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery
// method.
type AnswerPreCheckoutQueryParameters struct {
// Unique identifier for the query to be answered
2017-10-06 07:55:54 +00:00
PreCheckoutQueryID string `json:"pre_checkout_query_id"`
2017-10-06 07:55:54 +00:00
// Required if ok is False. Error message in human readable form that
// explains the reason for failure to proceed with the checkout (e.g. "Sorry,
// somebody just bought the last of our amazing black T-shirts while you were
// busy filling out your payment details. Please choose a different color or
// garment!"). Telegram will display this message to the user.
ErrorMessage string `json:"error_message,omitempty"`
// Specify True if everything is alright (goods are available, etc.) and the
// bot is ready to proceed with the order. Use False if there are any
// problems.
Ok bool `json:"ok"`
}
2018-04-19 13:02:15 +00:00
// NewAnswerPreCheckoutQuery creates AnswerPreCheckoutQueryParameters only with
// required parameters.
2017-10-17 11:08:09 +00:00
func NewAnswerPreCheckoutQuery(preCheckoutQueryID string, ok bool) *AnswerPreCheckoutQueryParameters {
return &AnswerPreCheckoutQueryParameters{
PreCheckoutQueryID: preCheckoutQueryID,
Ok: ok,
}
}
// AnswerPreCheckoutQuery respond to such pre-checkout queries.
//
2017-10-06 07:55:54 +00:00
// Once the user has confirmed their payment and shipping details, the Bot API
// sends the final confirmation in the form of an Update with the field
// pre_checkout_query. Use this method to respond to such pre-checkout queries.
// On success, True is returned.
//
2017-10-06 07:55:54 +00:00
// Note: The Bot API must receive an answer within 10 seconds after the
// pre-checkout query was sent.
2018-08-21 11:05:04 +00:00
func (bot *Bot) AnswerPreCheckoutQuery(params *AnswerShippingQueryParameters) (ok bool, err error) {
dst, err := json.Marshal(params)
if err != nil {
2018-08-21 11:05:04 +00:00
return
}
2018-04-12 11:58:05 +00:00
resp, err := bot.request(dst, MethodAnswerPreCheckoutQuery)
if err != nil {
2018-08-21 11:05:04 +00:00
return
}
2018-08-21 11:05:04 +00:00
err = json.Unmarshal(*resp.Result, &ok)
return
}