|
| 1 | +package tgbotapi |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/pquerna/ffjson/ffjson" |
| 5 | + "net/url" |
| 6 | +) |
| 7 | + |
| 8 | +type LabeledPrice struct { |
| 9 | + Label string `json:"label"` // Portion label |
| 10 | + Amount int64 `json:"amount"` // Price of the product in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). |
| 11 | +} |
| 12 | + |
| 13 | +var _ Chattable = (*InvoiceConfig)(nil) |
| 14 | + |
| 15 | +type InvoiceConfig struct { |
| 16 | + BaseChat |
| 17 | + Title string `json:"title"` // Product name, 1-32 characters |
| 18 | + Description string `json:"description"` // Product description, 1-255 characters |
| 19 | + Payload string `json:"payload"` // Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use it for your internal processes. |
| 20 | + ProviderToken string `json:"provider_token,omitempty"` // Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. |
| 21 | + Currency string `json:"currency"` // Three-letter ISO 4217 currency code, see more on currencies. Pass “XTR” for payments in Telegram Stars. |
| 22 | + Prices []LabeledPrice `json:"prices"` // Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in Telegram Stars. |
| 23 | + MaxTipAmount int64 `json:"max_tip_amount,omitempty"` // The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in Telegram Stars. |
| 24 | + SuggestedTipAmounts []int64 `json:"suggested_tip_amounts,omitempty"` //A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. |
| 25 | + StartParameter string `json:"start_parameter,omitempty"` // Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter |
| 26 | + ProviderData string `json:"provider_data,omitempty"` // JSON-serialized 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. |
| 27 | + PhotoURL string `json:"photo_url,omitempty"` // 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. |
| 28 | + PhotoSize int `json:"photo_size,omitempty"` // Photo size in bytes |
| 29 | + PhotoWidth int `json:"photo_width,omitempty"` // Photo width |
| 30 | + PhotoHeight int `json:"photo_height,omitempty"` // Photo height |
| 31 | + NeedName bool `json:"need_name,omitempty"` // Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars. |
| 32 | + NeedPhoneNumber bool `json:"need_phone_number,omitempty"` // Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars. |
| 33 | + NeedEmail bool `json:"need_email,omitempty"` // Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars. |
| 34 | + NeedShippingAddress bool `json:"need_shipping_address,omitempty"` // Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars. |
| 35 | + |
| 36 | + SendPhoneNumberToProvider bool `json:"send_phone_number_to_provider,omitempty"` // Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars. |
| 37 | + SendEmailToProvider bool `json:"send_email_to_provider,omitempty"` // Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars. |
| 38 | + IsFlexible bool `json:"is_flexible,omitempty"` // Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars. |
| 39 | +} |
| 40 | + |
| 41 | +func (v InvoiceConfig) method() string { |
| 42 | + return "sendInvoice" |
| 43 | +} |
| 44 | + |
| 45 | +// Values returns url.Values representation of InvoiceConfig. |
| 46 | +// |
| 47 | +//goland:noinspection GoMixedReceiverTypes |
| 48 | +func (v InvoiceConfig) Values() (url.Values, error) { |
| 49 | + values, _ := v.BaseChat.Values() |
| 50 | + values.Add("title", v.Title) |
| 51 | + values.Add("description", v.Description) |
| 52 | + values.Add("payload", v.Payload) |
| 53 | + values.Add("currency", v.Currency) |
| 54 | + if v.ProviderToken != "" { |
| 55 | + values.Add("provider_token", v.ProviderToken) |
| 56 | + } |
| 57 | + if len(v.Prices) > 0 { |
| 58 | + if b, err := ffjson.MarshalFast(v.Prices); err != nil { |
| 59 | + return nil, err |
| 60 | + } else { |
| 61 | + values.Add("prices", string(b)) |
| 62 | + } |
| 63 | + } |
| 64 | + return values, nil |
| 65 | +} |
0 commit comments