payments: SuccessfulPayment and minor changes

pull/300/head
Demian 4 years ago
parent 1a558989dc
commit 7a1d59c7d9

@ -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 {

@ -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"`

@ -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.

@ -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)

@ -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"

Loading…
Cancel
Save