payments: update API

pull/293/head
Nikita Bikmaev 4 years ago
parent d7c155f97e
commit 76c2cedf6f

@ -24,6 +24,7 @@ type Photo struct {
Width int `json:"width"`
Height int `json:"height"`
Size int `json:"photo_size"`
// (Optional)
Caption string `json:"caption,omitempty"`

@ -25,6 +25,21 @@ type Invoice struct {
Currency string `json:"currency"`
Prices []Price `json:"prices"`
ProviderData string `json:"provider_data"`
// Processing photo_url, photo_size, photo_width, photo_height fields.
Photo *Photo
NeedName bool `json:"need_name"`
NeedPhoneNumber bool `json:"need_phone_number"`
NeedEmail bool `json:"need_email"`
NeedShippingAddress bool `json:"need_shipping_address"`
SendPhone bool `json:"send_phone_number_to_provider"`
SendEmail bool `json:"send_email_to_provider"`
IsFlexible bool `json:"is_flexible"`
}
type Price struct {

@ -293,19 +293,40 @@ func (v *Venue) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
return extractMessage(data)
}
// Send delivers media through bot b to recipient.
// 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,
"description": i.Description,
"start_parameter": i.Start,
"payload": i.Payload,
"provider_token": i.Token,
"currency": i.Currency,
"prices": string(prices),
"chat_id": to.Recipient(),
"title": i.Title,
"description": i.Description,
"start_parameter": i.Start,
"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.SendPhone),
"send_email_to_provider": strconv.FormatBool(i.SendEmail),
"is_flexible": strconv.FormatBool(i.IsFlexible),
}
if i.Photo != nil {
if i.Photo.FileURL != "" {
params["photo_url"] = i.Photo.FileURL
}
if i.Photo.Size > 0 {
params["photo_size"] = strconv.Itoa(i.Photo.Size)
}
if i.Photo.Width > 0 {
params["photo_width"] = strconv.Itoa(i.Photo.Width)
}
if i.Photo.Height > 0 {
params["photo_height"] = strconv.Itoa(i.Photo.Height)
}
}
embedSendOptions(params, opt)

Loading…
Cancel
Save