Payments API

bot-api-6.1
MrYadro 2017-06-03 03:18:42 +07:00
parent 5869b2f7f9
commit 42d132b90a
No known key found for this signature in database
GPG Key ID: F46CD4085B2F9482
5 changed files with 242 additions and 35 deletions

34
bot.go
View File

@ -704,3 +704,37 @@ func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHigh
return highScores, err return highScores, err
} }
func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, error) {
v := url.Values{}
v.Add("shipping_query_id", config.ShippingQueryID)
v.Add("ok", strconv.FormatBool(config.Ok))
if config.Ok == true {
data, err := json.Marshal(config.ShippingOptions)
if err != nil {
return APIResponse{}, err
}
v.Add("shipping_options", string(data))
} else {
v.Add("error_message", config.ErrorMessage)
}
bot.debugLog("answerShippingQuery", v, nil)
return bot.MakeRequest("answerShippingQuery", v)
}
func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error) {
v := url.Values{}
v.Add("pre_checkout_query_id", config.PreCheckoutQueryID)
v.Add("ok", strconv.FormatBool(config.Ok))
if config.Ok != true {
v.Add("error", config.ErrorMessage)
}
bot.debugLog("answerPreCheckoutQuery", v, nil)
return bot.MakeRequest("answerPreCheckoutQuery", v)
}

View File

@ -899,3 +899,87 @@ type ChatConfigWithUser struct {
SuperGroupUsername string SuperGroupUsername string
UserID int UserID int
} }
type InvoiceConfig struct {
BaseChat
Title string // required
Description string // required
Payload string // required
ProviderToken string // required
StartParameter string // required
Currency string // required
Prices *[]LabeledPrice // required
PhotoUrl string
PhotoSize int
PhotoWidth int
PhotoHeight int
NeedName bool
NeedPhoneNumber bool
NeedEmail bool
NeedShippingAddress bool
IsFlexible bool
}
func (config InvoiceConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("title", config.Title)
v.Add("description", config.Description)
v.Add("payload", config.Payload)
v.Add("provider_token", config.ProviderToken)
v.Add("start_parameter", config.StartParameter)
v.Add("currency", config.Currency)
data, err := json.Marshal(config.Prices)
if err != nil {
return v, err
}
v.Add("prices", string(data))
if config.PhotoUrl != "" {
v.Add("photo_url", config.PhotoUrl)
}
if config.PhotoSize != 0 {
v.Add("photo_size", strconv.Itoa(config.PhotoSize))
}
if config.PhotoWidth != 0 {
v.Add("photo_width", strconv.Itoa(config.PhotoWidth))
}
if config.PhotoHeight != 0 {
v.Add("photo_height", strconv.Itoa(config.PhotoHeight))
}
if config.NeedName != false {
v.Add("need_name", strconv.FormatBool(config.NeedName))
}
if config.NeedPhoneNumber != false {
v.Add("need_phone_number", strconv.FormatBool(config.NeedPhoneNumber))
}
if config.NeedEmail != false {
v.Add("need_email", strconv.FormatBool(config.NeedEmail))
}
if config.NeedShippingAddress != false {
v.Add("need_shipping_address", strconv.FormatBool(config.NeedShippingAddress))
}
if config.IsFlexible != false {
v.Add("is_flexible", strconv.FormatBool(config.IsFlexible))
}
return v, nil
}
func (config InvoiceConfig) method() string {
return "sendInvoice"
}
type ShippingConfig struct {
ShippingQueryID string // required
Ok bool // required
ShippingOptions *[]ShippingOption
ErrorMessage string
}
type PreCheckoutConfig struct {
PreCheckoutQueryID string // required
Ok bool // required
ErrorMessage string
}

Binary file not shown.

View File

@ -640,3 +640,24 @@ func NewCallbackWithAlert(id, text string) CallbackConfig {
ShowAlert: true, ShowAlert: true,
} }
} }
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices *[]LabeledPrice, photoUrl string, photoSize, photoWidth, photoHeight int, needName, needPhoneNumber, needEmail, needShippingAddress, isFlexible bool) InvoiceConfig {
return InvoiceConfig{
BaseChat: BaseChat{ChatID: chatID},
Title: title,
Description: description,
Payload: payload,
ProviderToken: providerToken,
StartParameter: startParameter,
Currency: currency,
Prices: prices,
PhotoUrl: photoUrl,
PhotoSize: photoSize,
PhotoWidth: photoWidth,
PhotoHeight: photoHeight,
NeedName: needName,
NeedPhoneNumber: needPhoneNumber,
NeedEmail: needEmail,
NeedShippingAddress: needShippingAddress,
IsFlexible: isFlexible}
}

View File

@ -35,6 +35,8 @@ type Update struct {
InlineQuery *InlineQuery `json:"inline_query"` InlineQuery *InlineQuery `json:"inline_query"`
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"` ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
CallbackQuery *CallbackQuery `json:"callback_query"` CallbackQuery *CallbackQuery `json:"callback_query"`
ShippingQuery *ShippingQuery `json:"shipping_query"`
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query"`
} }
// UpdatesChannel is the channel for getting updates. // UpdatesChannel is the channel for getting updates.
@ -153,6 +155,8 @@ type Message struct {
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional
PinnedMessage *Message `json:"pinned_message"` // optional PinnedMessage *Message `json:"pinned_message"` // optional
Invoice *Invoice `json:"invoice"` // optional
SuccessfulPayment *SuccessfulPayment `json:"successful_payment"` // optional
} }
// Time converts the message timestamp into a Time. // Time converts the message timestamp into a Time.
@ -372,6 +376,7 @@ type InlineKeyboardButton struct {
SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional
SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional
CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional
Pay bool `json:"pay"`
} }
// CallbackQuery is data sent when a keyboard button with callback data // CallbackQuery is data sent when a keyboard button with callback data
@ -646,3 +651,66 @@ type InputContactMessageContent struct {
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` LastName string `json:"last_name"`
} }
// Invoice contains information about invoice
type Invoice struct {
Title string `json:"title"`
Description string `json:"description"`
StartParameter string `json:"start_parameter"`
Currency string `json:"currency"`
TotalAmount int `json:"total_amount"`
}
type LabeledPrice struct {
Label string `json:"label"`
Amount int `json:"amount"`
}
type ShippingAddress struct {
CountryCode string `json:"country_code"`
State string `json:"state"`
City string `json:"city"`
StreetLine1 string `json:"street_line1"`
StreetLine2 string `json:"street_line2"`
PostCode string `json:"post_code"`
}
type OrderInfo struct {
Name string `json:"name,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"`
Email string `json:"email,omitempty"`
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
}
type ShippingOption struct {
ID string `json:"id"`
Title string `json:"title"`
Prices *[]LabeledPrice `json:"prices"`
}
type SuccessfulPayment struct {
Currency string `json:"currency"`
TotalAmount int `json:"total_amount"`
InvoicePayload string `json:"invoice_payload"`
ShippingOptionID string `json:"shipping_option_id,omitempty"`
OrderInfo *OrderInfo `json:"order_info,omitempty"`
TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
}
type ShippingQuery struct {
ID string `json:"id"`
From *User `json:"from"`
InvoicePayload string `json:"invoice_payload"`
ShippingAddress *ShippingAddress `json:"shipping_address"`
}
type PreCheckoutQuery struct {
ID string `json:"id"`
From *User `json:"from"`
Currency string `json:"currency"`
TotalAmount int `json:"total_amount"`
InvoicePayload string `json:"invoice_payload"`
ShippingOptionID string `json:"shipping_option_id,omitempty"`
OrderInfo *OrderInfo `json:"order_info,omitempty"`
}