diff --git a/bot.go b/bot.go index 9301953..b11559f 100644 --- a/bot.go +++ b/bot.go @@ -229,6 +229,16 @@ func (b *Bot) ProcessUpdate(upd Update) { return } + if m.Invoice != nil { + b.handle(OnInvoice, m) + return + } + + if m.Payment != nil { + b.handle(OnPayment, m) + return + } + wasAdded := (m.UserJoined != nil && m.UserJoined.ID == b.Me.ID) || (m.UsersJoined != nil && isUserInList(b.Me, m.UsersJoined)) if m.GroupCreated || m.SuperGroupCreated || wasAdded { diff --git a/message.go b/message.go index 91072a4..8877642 100644 --- a/message.go +++ b/message.go @@ -192,6 +192,12 @@ type Message struct { // if it is itself a reply. PinnedMessage *Message `json:"pinned_message"` + // Message is an invoice for a payment. + Invoice *Invoice `json:"invoice"` + + // Message is a service message about a successful payment. + Payment *Payment `json:"successful_payment"` + // The domain name of the website on which the user has logged in. ConnectedWebsite string `json:"connected_website,omitempty"` diff --git a/payments.go b/payments.go index ca88296..8a012a5 100644 --- a/payments.go +++ b/payments.go @@ -30,6 +30,17 @@ type ShippingOption struct { Prices []Price `json:"prices"` } +// Payment contains basic information about a successful payment. +type Payment struct { + Currency Currency `json:"currency"` + Total int `json:"total_amount"` + Payload string `json:"invoice_payload"` + OptionID string `json:"shipping_option_id"` + Order Order `json:"order_info"` + TelegramChargeID string `json:"telegram_payment_charge_id"` + ProviderChargeID string `json:"provider_payment_charge_id"` +} + // PreCheckoutQuery contains information about an incoming pre-checkout query. type PreCheckoutQuery struct { Sender *User `json:"from"` @@ -51,22 +62,22 @@ type Order struct { // Invoice contains basic information about an invoice. type Invoice struct { - Title string `json:"title"` - Description string `json:"description"` - Payload string `json:"payload"` - Token string `json:"provider_token"` - Currency string `json:"currency"` - Prices []Price `json:"prices"` - ProviderData string `json:"provider_data"` + Title string `json:"title"` + Description string `json:"description"` + Payload string `json:"payload"` + Currency string `json:"currency"` + Prices []Price `json:"prices"` + Token string `json:"provider_token"` + Data string `json:"provider_data"` Photo *Photo `json:"photo"` PhotoSize int `json:"photo_size"` - // Start is a unique deep-linking parameter that can be used to + // Unique deep-linking parameter that can be used to // generate this invoice when used as a start parameter. Start string `json:"start_parameter"` - // Total shows the total price in the smallest units of the currency. + // Shows the total price in the smallest units of the currency. // For example, for a price of US$ 1.45 pass amount = 145. Total int `json:"total_amount"` @@ -76,7 +87,7 @@ type Invoice struct { NeedShippingAddress bool `json:"need_shipping_address"` SendPhoneNumber bool `json:"send_phone_number_to_provider"` SendEmail bool `json:"send_email_to_provider"` - IsFlexible bool `json:"is_flexible"` + Flexible bool `json:"is_flexible"` } // Price represents a portion of the price for goods or services. diff --git a/sendable.go b/sendable.go index 7dff1b8..5816d72 100644 --- a/sendable.go +++ b/sendable.go @@ -295,8 +295,6 @@ func (v *Venue) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) { // Send delivers invoice through bot b to recipient. func (i *Invoice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) { - prices, _ := json.Marshal(i.Prices) - params := map[string]string{ "chat_id": to.Recipient(), "title": i.Title, @@ -305,14 +303,13 @@ func (i *Invoice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) "payload": i.Payload, "provider_token": i.Token, "currency": i.Currency, - "prices": string(prices), "need_name": strconv.FormatBool(i.NeedName), "need_phone_number": strconv.FormatBool(i.NeedPhoneNumber), "need_email": strconv.FormatBool(i.NeedEmail), "need_shipping_address": strconv.FormatBool(i.NeedShippingAddress), "send_phone_number_to_provider": strconv.FormatBool(i.SendPhoneNumber), "send_email_to_provider": strconv.FormatBool(i.SendEmail), - "is_flexible": strconv.FormatBool(i.IsFlexible), + "is_flexible": strconv.FormatBool(i.Flexible), } if i.Photo != nil { if i.Photo.FileURL != "" { @@ -328,6 +325,10 @@ func (i *Invoice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) params["photo_height"] = strconv.Itoa(i.Photo.Height) } } + if len(i.Prices) > 0 { + data, _ := json.Marshal(i.Prices) + params["prices"] = string(data) + } embedSendOptions(params, opt) data, err := b.Raw("sendInvoice", params) diff --git a/telebot.go b/telebot.go index 7e1f790..be4c864 100644 --- a/telebot.go +++ b/telebot.go @@ -64,6 +64,8 @@ const ( OnChannelPost = "\achan_post" OnEditedChannelPost = "\achan_edited_post" OnDice = "\adice" + OnInvoice = "\ainvoice" + OnPayment = "\apayment" // Will fire when bot is added to a group. OnAddedToGroup = "\aadded_to_group"