Payments API
parent
5869b2f7f9
commit
42d132b90a
34
bot.go
34
bot.go
|
@ -704,3 +704,37 @@ func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHigh
|
||||||
|
|
||||||
return highScores, err
|
return highScores, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, error) {
|
||||||
|
v := url.Values{}
|
||||||
|
|
||||||
|
v.Add("shipping_query_id", config.ShippingQueryID)
|
||||||
|
v.Add("ok", strconv.FormatBool(config.Ok))
|
||||||
|
if config.Ok == true {
|
||||||
|
data, err := json.Marshal(config.ShippingOptions)
|
||||||
|
if err != nil {
|
||||||
|
return APIResponse{}, err
|
||||||
|
}
|
||||||
|
v.Add("shipping_options", string(data))
|
||||||
|
} else {
|
||||||
|
v.Add("error_message", config.ErrorMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.debugLog("answerShippingQuery", v, nil)
|
||||||
|
|
||||||
|
return bot.MakeRequest("answerShippingQuery", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error) {
|
||||||
|
v := url.Values{}
|
||||||
|
|
||||||
|
v.Add("pre_checkout_query_id", config.PreCheckoutQueryID)
|
||||||
|
v.Add("ok", strconv.FormatBool(config.Ok))
|
||||||
|
if config.Ok != true {
|
||||||
|
v.Add("error", config.ErrorMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.debugLog("answerPreCheckoutQuery", v, nil)
|
||||||
|
|
||||||
|
return bot.MakeRequest("answerPreCheckoutQuery", v)
|
||||||
|
}
|
||||||
|
|
84
configs.go
84
configs.go
|
@ -899,3 +899,87 @@ type ChatConfigWithUser struct {
|
||||||
SuperGroupUsername string
|
SuperGroupUsername string
|
||||||
UserID int
|
UserID int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InvoiceConfig struct {
|
||||||
|
BaseChat
|
||||||
|
Title string // required
|
||||||
|
Description string // required
|
||||||
|
Payload string // required
|
||||||
|
ProviderToken string // required
|
||||||
|
StartParameter string // required
|
||||||
|
Currency string // required
|
||||||
|
Prices *[]LabeledPrice // required
|
||||||
|
PhotoUrl string
|
||||||
|
PhotoSize int
|
||||||
|
PhotoWidth int
|
||||||
|
PhotoHeight int
|
||||||
|
NeedName bool
|
||||||
|
NeedPhoneNumber bool
|
||||||
|
NeedEmail bool
|
||||||
|
NeedShippingAddress bool
|
||||||
|
IsFlexible bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config InvoiceConfig) values() (url.Values, error) {
|
||||||
|
v, err := config.BaseChat.values()
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
v.Add("title", config.Title)
|
||||||
|
v.Add("description", config.Description)
|
||||||
|
v.Add("payload", config.Payload)
|
||||||
|
v.Add("provider_token", config.ProviderToken)
|
||||||
|
v.Add("start_parameter", config.StartParameter)
|
||||||
|
v.Add("currency", config.Currency)
|
||||||
|
data, err := json.Marshal(config.Prices)
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
v.Add("prices", string(data))
|
||||||
|
if config.PhotoUrl != "" {
|
||||||
|
v.Add("photo_url", config.PhotoUrl)
|
||||||
|
}
|
||||||
|
if config.PhotoSize != 0 {
|
||||||
|
v.Add("photo_size", strconv.Itoa(config.PhotoSize))
|
||||||
|
}
|
||||||
|
if config.PhotoWidth != 0 {
|
||||||
|
v.Add("photo_width", strconv.Itoa(config.PhotoWidth))
|
||||||
|
}
|
||||||
|
if config.PhotoHeight != 0 {
|
||||||
|
v.Add("photo_height", strconv.Itoa(config.PhotoHeight))
|
||||||
|
}
|
||||||
|
if config.NeedName != false {
|
||||||
|
v.Add("need_name", strconv.FormatBool(config.NeedName))
|
||||||
|
}
|
||||||
|
if config.NeedPhoneNumber != false {
|
||||||
|
v.Add("need_phone_number", strconv.FormatBool(config.NeedPhoneNumber))
|
||||||
|
}
|
||||||
|
if config.NeedEmail != false {
|
||||||
|
v.Add("need_email", strconv.FormatBool(config.NeedEmail))
|
||||||
|
}
|
||||||
|
if config.NeedShippingAddress != false {
|
||||||
|
v.Add("need_shipping_address", strconv.FormatBool(config.NeedShippingAddress))
|
||||||
|
}
|
||||||
|
if config.IsFlexible != false {
|
||||||
|
v.Add("is_flexible", strconv.FormatBool(config.IsFlexible))
|
||||||
|
}
|
||||||
|
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config InvoiceConfig) method() string {
|
||||||
|
return "sendInvoice"
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShippingConfig struct {
|
||||||
|
ShippingQueryID string // required
|
||||||
|
Ok bool // required
|
||||||
|
ShippingOptions *[]ShippingOption
|
||||||
|
ErrorMessage string
|
||||||
|
}
|
||||||
|
|
||||||
|
type PreCheckoutConfig struct {
|
||||||
|
PreCheckoutQueryID string // required
|
||||||
|
Ok bool // required
|
||||||
|
ErrorMessage string
|
||||||
|
}
|
||||||
|
|
BIN
debug.test
BIN
debug.test
Binary file not shown.
21
helpers.go
21
helpers.go
|
@ -640,3 +640,24 @@ func NewCallbackWithAlert(id, text string) CallbackConfig {
|
||||||
ShowAlert: true,
|
ShowAlert: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices *[]LabeledPrice, photoUrl string, photoSize, photoWidth, photoHeight int, needName, needPhoneNumber, needEmail, needShippingAddress, isFlexible bool) InvoiceConfig {
|
||||||
|
return InvoiceConfig{
|
||||||
|
BaseChat: BaseChat{ChatID: chatID},
|
||||||
|
Title: title,
|
||||||
|
Description: description,
|
||||||
|
Payload: payload,
|
||||||
|
ProviderToken: providerToken,
|
||||||
|
StartParameter: startParameter,
|
||||||
|
Currency: currency,
|
||||||
|
Prices: prices,
|
||||||
|
PhotoUrl: photoUrl,
|
||||||
|
PhotoSize: photoSize,
|
||||||
|
PhotoWidth: photoWidth,
|
||||||
|
PhotoHeight: photoHeight,
|
||||||
|
NeedName: needName,
|
||||||
|
NeedPhoneNumber: needPhoneNumber,
|
||||||
|
NeedEmail: needEmail,
|
||||||
|
NeedShippingAddress: needShippingAddress,
|
||||||
|
IsFlexible: isFlexible}
|
||||||
|
}
|
||||||
|
|
138
types.go
138
types.go
|
@ -35,6 +35,8 @@ type Update struct {
|
||||||
InlineQuery *InlineQuery `json:"inline_query"`
|
InlineQuery *InlineQuery `json:"inline_query"`
|
||||||
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
|
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
|
||||||
CallbackQuery *CallbackQuery `json:"callback_query"`
|
CallbackQuery *CallbackQuery `json:"callback_query"`
|
||||||
|
ShippingQuery *ShippingQuery `json:"shipping_query"`
|
||||||
|
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatesChannel is the channel for getting updates.
|
// UpdatesChannel is the channel for getting updates.
|
||||||
|
@ -118,41 +120,43 @@ func (c Chat) ChatConfig() ChatConfig {
|
||||||
// Message is returned by almost every request, and contains data about
|
// Message is returned by almost every request, and contains data about
|
||||||
// almost anything.
|
// almost anything.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
MessageID int `json:"message_id"`
|
MessageID int `json:"message_id"`
|
||||||
From *User `json:"from"` // optional
|
From *User `json:"from"` // optional
|
||||||
Date int `json:"date"`
|
Date int `json:"date"`
|
||||||
Chat *Chat `json:"chat"`
|
Chat *Chat `json:"chat"`
|
||||||
ForwardFrom *User `json:"forward_from"` // optional
|
ForwardFrom *User `json:"forward_from"` // optional
|
||||||
ForwardFromChat *Chat `json:"forward_from_chat"` // optional
|
ForwardFromChat *Chat `json:"forward_from_chat"` // optional
|
||||||
ForwardFromMessageID int `json:"forward_from_message_id"` // optional
|
ForwardFromMessageID int `json:"forward_from_message_id"` // optional
|
||||||
ForwardDate int `json:"forward_date"` // optional
|
ForwardDate int `json:"forward_date"` // optional
|
||||||
ReplyToMessage *Message `json:"reply_to_message"` // optional
|
ReplyToMessage *Message `json:"reply_to_message"` // optional
|
||||||
EditDate int `json:"edit_date"` // optional
|
EditDate int `json:"edit_date"` // optional
|
||||||
Text string `json:"text"` // optional
|
Text string `json:"text"` // optional
|
||||||
Entities *[]MessageEntity `json:"entities"` // optional
|
Entities *[]MessageEntity `json:"entities"` // optional
|
||||||
Audio *Audio `json:"audio"` // optional
|
Audio *Audio `json:"audio"` // optional
|
||||||
Document *Document `json:"document"` // optional
|
Document *Document `json:"document"` // optional
|
||||||
Game *Game `json:"game"` // optional
|
Game *Game `json:"game"` // optional
|
||||||
Photo *[]PhotoSize `json:"photo"` // optional
|
Photo *[]PhotoSize `json:"photo"` // optional
|
||||||
Sticker *Sticker `json:"sticker"` // optional
|
Sticker *Sticker `json:"sticker"` // optional
|
||||||
Video *Video `json:"video"` // optional
|
Video *Video `json:"video"` // optional
|
||||||
VideoNote *VideoNote `json:"video_note"` // optional
|
VideoNote *VideoNote `json:"video_note"` // optional
|
||||||
Voice *Voice `json:"voice"` // optional
|
Voice *Voice `json:"voice"` // optional
|
||||||
Caption string `json:"caption"` // optional
|
Caption string `json:"caption"` // optional
|
||||||
Contact *Contact `json:"contact"` // optional
|
Contact *Contact `json:"contact"` // optional
|
||||||
Location *Location `json:"location"` // optional
|
Location *Location `json:"location"` // optional
|
||||||
Venue *Venue `json:"venue"` // optional
|
Venue *Venue `json:"venue"` // optional
|
||||||
NewChatMember *User `json:"new_chat_member"` // optional
|
NewChatMember *User `json:"new_chat_member"` // optional
|
||||||
LeftChatMember *User `json:"left_chat_member"` // optional
|
LeftChatMember *User `json:"left_chat_member"` // optional
|
||||||
NewChatTitle string `json:"new_chat_title"` // optional
|
NewChatTitle string `json:"new_chat_title"` // optional
|
||||||
NewChatPhoto *[]PhotoSize `json:"new_chat_photo"` // optional
|
NewChatPhoto *[]PhotoSize `json:"new_chat_photo"` // optional
|
||||||
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
|
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
|
||||||
GroupChatCreated bool `json:"group_chat_created"` // optional
|
GroupChatCreated bool `json:"group_chat_created"` // optional
|
||||||
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
|
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
|
||||||
ChannelChatCreated bool `json:"channel_chat_created"` // optional
|
ChannelChatCreated bool `json:"channel_chat_created"` // optional
|
||||||
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
|
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
|
||||||
MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional
|
MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional
|
||||||
PinnedMessage *Message `json:"pinned_message"` // optional
|
PinnedMessage *Message `json:"pinned_message"` // optional
|
||||||
|
Invoice *Invoice `json:"invoice"` // optional
|
||||||
|
SuccessfulPayment *SuccessfulPayment `json:"successful_payment"` // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time converts the message timestamp into a Time.
|
// Time converts the message timestamp into a Time.
|
||||||
|
@ -372,6 +376,7 @@ type InlineKeyboardButton struct {
|
||||||
SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional
|
SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional
|
||||||
SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional
|
SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional
|
||||||
CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional
|
CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional
|
||||||
|
Pay bool `json:"pay"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CallbackQuery is data sent when a keyboard button with callback data
|
// CallbackQuery is data sent when a keyboard button with callback data
|
||||||
|
@ -646,3 +651,66 @@ type InputContactMessageContent struct {
|
||||||
FirstName string `json:"first_name"`
|
FirstName string `json:"first_name"`
|
||||||
LastName string `json:"last_name"`
|
LastName string `json:"last_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoice contains information about invoice
|
||||||
|
type Invoice struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
StartParameter string `json:"start_parameter"`
|
||||||
|
Currency string `json:"currency"`
|
||||||
|
TotalAmount int `json:"total_amount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LabeledPrice struct {
|
||||||
|
Label string `json:"label"`
|
||||||
|
Amount int `json:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShippingAddress struct {
|
||||||
|
CountryCode string `json:"country_code"`
|
||||||
|
State string `json:"state"`
|
||||||
|
City string `json:"city"`
|
||||||
|
StreetLine1 string `json:"street_line1"`
|
||||||
|
StreetLine2 string `json:"street_line2"`
|
||||||
|
PostCode string `json:"post_code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderInfo struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
PhoneNumber string `json:"phone_number,omitempty"`
|
||||||
|
Email string `json:"email,omitempty"`
|
||||||
|
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShippingOption struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Prices *[]LabeledPrice `json:"prices"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SuccessfulPayment struct {
|
||||||
|
Currency string `json:"currency"`
|
||||||
|
TotalAmount int `json:"total_amount"`
|
||||||
|
InvoicePayload string `json:"invoice_payload"`
|
||||||
|
ShippingOptionID string `json:"shipping_option_id,omitempty"`
|
||||||
|
OrderInfo *OrderInfo `json:"order_info,omitempty"`
|
||||||
|
TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
|
||||||
|
ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShippingQuery struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
From *User `json:"from"`
|
||||||
|
InvoicePayload string `json:"invoice_payload"`
|
||||||
|
ShippingAddress *ShippingAddress `json:"shipping_address"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PreCheckoutQuery struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
From *User `json:"from"`
|
||||||
|
Currency string `json:"currency"`
|
||||||
|
TotalAmount int `json:"total_amount"`
|
||||||
|
InvoicePayload string `json:"invoice_payload"`
|
||||||
|
ShippingOptionID string `json:"shipping_option_id,omitempty"`
|
||||||
|
OrderInfo *OrderInfo `json:"order_info,omitempty"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue