|
|
|
@ -5,48 +5,87 @@ import (
|
|
|
|
|
"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"`
|
|
|
|
|
// ShippingQuery contains information about an incoming shipping query.
|
|
|
|
|
type ShippingQuery struct {
|
|
|
|
|
Sender *User `json:"from"`
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Payload string `json:"invoice_payload"`
|
|
|
|
|
Address ShippingAddress `json:"shipping_address"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Unique deep-linking parameter that can be used to
|
|
|
|
|
// generate this invoice when used as a start parameter.
|
|
|
|
|
Start string `json:"start_parameter"`
|
|
|
|
|
// ShippingAddress represents a shipping address.
|
|
|
|
|
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"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Provider token to use.
|
|
|
|
|
Token string `json:"provider_token"`
|
|
|
|
|
// ShippingOption represents one shipping option.
|
|
|
|
|
type ShippingOption struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Prices []Price `json:"prices"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PreCheckoutQuery contains information about an incoming pre-checkout query.
|
|
|
|
|
type PreCheckoutQuery struct {
|
|
|
|
|
Sender *User `json:"from"`
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
|
Payload string `json:"invoice_payload"`
|
|
|
|
|
Total int `json:"total_amount"`
|
|
|
|
|
OptionID string `json:"shipping_option_id"`
|
|
|
|
|
Order Order `json:"order_info"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Prices []Price `json:"prices"`
|
|
|
|
|
// Order represents information about an order.
|
|
|
|
|
type Order struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
PhoneNumber string `json:"phone_number"`
|
|
|
|
|
Email string `json:"email"`
|
|
|
|
|
Address ShippingAddress `json:"shipping_address"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProviderData string `json:"provider_data"`
|
|
|
|
|
// Invoice contains basic information about an invoice.
|
|
|
|
|
type Invoice struct {
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
Payload string `json:"payload"`
|
|
|
|
|
Token string `json:"provider_token"`
|
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
|
Prices []Price `json:"prices"`
|
|
|
|
|
ProviderData string `json:"provider_data"`
|
|
|
|
|
|
|
|
|
|
Photo *Photo `json:"photo"`
|
|
|
|
|
PhotoSize int `json:"photo_size"`
|
|
|
|
|
|
|
|
|
|
// Start is a unique deep-linking parameter that can be used to
|
|
|
|
|
// generate this invoice when used as a start parameter.
|
|
|
|
|
Start string `json:"start_parameter"`
|
|
|
|
|
|
|
|
|
|
// Processing photo_url, photo_size, photo_width, photo_height fields.
|
|
|
|
|
Photo *Photo
|
|
|
|
|
// Total shows the total price in the smallest units of the currency.
|
|
|
|
|
// For example, for a price of US$ 1.45 pass amount = 145.
|
|
|
|
|
Total int `json:"total_amount"`
|
|
|
|
|
|
|
|
|
|
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"`
|
|
|
|
|
SendPhoneNumber bool `json:"send_phone_number_to_provider"`
|
|
|
|
|
SendEmail bool `json:"send_email_to_provider"`
|
|
|
|
|
IsFlexible bool `json:"is_flexible"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Price represents a portion of the price for goods or services.
|
|
|
|
|
type Price struct {
|
|
|
|
|
Label string `json:"label"`
|
|
|
|
|
Amount int `json:"amount"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Currency contains information about supported currency for payments.
|
|
|
|
|
type Currency struct {
|
|
|
|
|
Code string `json:"code"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
@ -72,7 +111,7 @@ func (c Currency) ToTotal(total float64) int {
|
|
|
|
|
var SupportedCurrencies = map[string]Currency{}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
err := json.Unmarshal([]byte(dataSupportedCurrenciesJSON), &SupportedCurrencies)
|
|
|
|
|
err := json.Unmarshal([]byte(dataCurrencies), &SupportedCurrencies)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|