1
0
telegram/send_invoice.go

110 lines
3.5 KiB
Go
Raw Normal View History

2017-09-05 08:51:43 +00:00
package telegram
import json "github.com/pquerna/ffjson/ffjson"
type SendInvoiceParameters struct {
// Unique identifier for the target private chat
2017-10-06 07:55:54 +00:00
ChatID int64 `json:"chat_id"`
2017-09-05 08:51:43 +00:00
// Product name, 1-32 characters
2017-10-06 07:55:54 +00:00
Title string `json:"title"`
2017-09-05 08:51:43 +00:00
// Product description, 1-255 characters
2017-10-06 07:55:54 +00:00
Description string `json:"description"`
2017-09-05 08:51:43 +00:00
2017-10-06 07:55:54 +00:00
// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
// the user, use for your internal processes.
Payload string `json:"payload"`
2017-09-05 08:51:43 +00:00
// Payments provider token, obtained via Botfather
2017-10-06 07:55:54 +00:00
ProviderToken string `json:"provider_token"`
2017-09-05 08:51:43 +00:00
2017-10-06 07:55:54 +00:00
// Unique deep-linking parameter that can be used to generate this invoice
// when used as a start parameter
StartParameter string `json:"start_parameter"`
2017-09-05 08:51:43 +00:00
// Three-letter ISO 4217 currency code, see more on currencies
2017-10-06 07:55:54 +00:00
Currency string `json:"currency"`
2017-09-05 08:51:43 +00:00
// JSON-encoded data about the invoice, which will be shared with the payment
// provider. A detailed description of required fields should be provided by
// the payment provider.
ProviderData string `json:"provider_data,omitempty"`
2017-10-06 07:55:54 +00:00
// URL of the product photo for the invoice. Can be a photo of the goods or a
// marketing image for a service. People like it better when they see what
// they are paying for.
PhotoURL string `json:"photo_url,omitempty"`
2017-09-05 08:51:43 +00:00
// Price breakdown, a list of components (e.g. product price, tax, discount,
// delivery cost, delivery tax, bonus, etc.)
Prices []LabeledPrice `json:"prices"`
2017-09-05 08:51:43 +00:00
// Photo size
2017-10-06 07:55:54 +00:00
PhotoSize int `json:"photo_size,omitempty"`
2017-09-05 08:51:43 +00:00
// Photo width
2017-10-06 07:55:54 +00:00
PhotoWidth int `json:"photo_width,omitempty"`
2017-09-05 08:51:43 +00:00
// Photo height
2017-10-06 07:55:54 +00:00
PhotoHeight int `json:"photo_height,omitempty"`
2017-09-05 08:51:43 +00:00
// If the message is a reply, ID of the original message
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
2017-09-05 08:51:43 +00:00
// Pass True, if you require the user's full name to complete the order
2017-10-06 07:55:54 +00:00
NeedName bool `json:"need_name,omitempty"`
2017-09-05 08:51:43 +00:00
// Pass True, if you require the user's phone number to complete the order
2017-10-06 07:55:54 +00:00
NeedPhoneNumber bool `json:"need_phone_number,omitempty"`
2017-09-05 08:51:43 +00:00
// Pass True, if you require the user's email to complete the order
2017-10-06 07:55:54 +00:00
NeedEmail bool `json:"need_email,omitempty"`
2017-09-05 08:51:43 +00:00
2017-10-06 07:55:54 +00:00
// Pass True, if you require the user's shipping address to complete the
// order
NeedShippingAddress bool `json:"need_shipping_address,omitempty"`
2017-09-05 08:51:43 +00:00
// Pass True, if the final price depends on the shipping method
2017-10-06 07:55:54 +00:00
IsFlexible bool `json:"is_flexible,omitempty"`
2017-09-05 08:51:43 +00:00
2017-10-06 07:55:54 +00:00
// Sends the message silently. Users will receive a notification with no
// sound.
DisableNotification bool `json:"disable_notification,omitempty"`
2017-09-05 08:51:43 +00:00
2017-10-06 07:55:54 +00:00
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
// price' button will be shown. If not empty, the first button must be a Pay
// button.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2017-09-05 08:51:43 +00:00
}
2017-10-17 11:08:09 +00:00
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices ...LabeledPrice) *SendInvoiceParameters {
return &SendInvoiceParameters{
ChatID: chatID,
Title: title,
Description: description,
Payload: payload,
ProviderToken: providerToken,
StartParameter: startParameter,
Currency: currency,
Prices: prices,
}
}
2017-09-05 08:51:43 +00:00
// SendInvoice send invoices. On success, the sent Message is returned.
func (bot *Bot) SendInvoice(params *SendInvoiceParameters) (*Message, error) {
dst, err := json.Marshal(params)
2017-09-05 08:51:43 +00:00
if err != nil {
return nil, err
}
2018-04-12 11:58:05 +00:00
resp, err := bot.request(dst, MethodSendInvoice)
2017-09-05 08:51:43 +00:00
if err != nil {
2017-09-05 09:20:10 +00:00
return nil, err
2017-09-05 08:51:43 +00:00
}
var data Message
err = json.Unmarshal(*resp.Result, &data)
return &data, err
}