telebot/payments.go

65 lines
1.5 KiB
Go
Raw Normal View History

2019-01-27 19:00:48 +00:00
package telebot
2019-01-28 00:11:10 +00:00
import (
"encoding/json"
"math"
)
type Invoice struct {
// Product name, 1-32 characters.
Title string `json:"title"`
// Product description, 1-255 characters.
Description string `json:"description"`
// Custom payload, required, 1-128 bytes.
Payload string `json:"payload"`
// Unique deep-linking parameter that can be used to
// generate this invoice when used as a start parameter.
Start string `json:"start_parameter"`
// Provider token to use.
Token string `json:"provider_token"`
Currency string `json:"currency"`
Prices []Price `json:"prices"`
}
type Price struct {
Label string `json:"label"`
Amount int `json:"amount"`
}
2019-01-27 19:00:48 +00:00
type Currency struct {
2019-01-28 00:11:10 +00:00
Code string `json:"code"`
Title string `json:"title"`
Symbol string `json:"symbol"`
Native string `json:"native"`
ThousandsSep string `json:"thousands_sep"`
DecimalSep string `json:"decimal_sep"`
SymbolLeft bool `json:"symbol_left"`
SpaceBetween bool `json:"space_between"`
Exp int `json:"exp"`
MinAmount interface{} `json:"min_amount"`
MaxAmount interface{} `json:"max_amount"`
2019-01-27 19:00:48 +00:00
}
2019-01-28 00:11:10 +00:00
func (c Currency) FromTotal(total int) float64 {
return float64(total) / math.Pow(10, float64(c.Exp))
}
func (c Currency) ToTotal(total float64) int {
return int(total) * int(math.Pow(10, float64(c.Exp)))
}
2019-01-27 19:00:48 +00:00
var SupportedCurrencies = map[string]Currency{}
func init() {
err := json.Unmarshal([]byte(dataSupportedCurrenciesJSON), &SupportedCurrencies)
if err != nil {
panic(err)
}
2019-01-27 19:00:48 +00:00
}