-
Notifications
You must be signed in to change notification settings - Fork 467
/
stars.go
73 lines (56 loc) · 2.19 KB
/
stars.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package telebot
import "time"
type TransactionType = string
const (
TransactionTypeUser TransactionType = "user"
TransactionTypeFragment TransactionType = "fragment"
TransactionPartnerTelegramAds TransactionType = "telegram_ads"
TransactionTypeOther TransactionType = "other"
)
type RevenueState = string
const (
RevenueStatePending RevenueState = "pending"
RevenueStateSucceeded RevenueState = "succeeded"
RevenueStateFailed RevenueState = "failed"
)
type StarTransaction struct {
// Unique identifier of the transaction. Coincides with the identifier of the
// original transaction for refund transactions. Coincides with
// SuccessfulPayment.telegram_payment_charge_id for successful incoming
// payments from users.
ID string `json:"id"`
// Number of Telegram Stars transferred by the transaction
Amount int `json:"amount"`
// Date the transaction was created in Unix time
Unixtime int64 `json:"date"`
// (Optional) Source of an incoming transaction (e.g., a user purchasing goods
// or services, Fragment refunding a failed withdrawal). Only for incoming transactions
Source TransactionPartner `json:"source"`
// (Optional) Receiver of an outgoing transaction (e.g., a user for a purchase
// refund, Fragment for a withdrawal). Only for outgoing transactions
Receiver TransactionPartner `json:"receiver"`
}
type TransactionPartner struct {
// Type of the state
Type TransactionType `json:"type"`
User *User `json:"user,omitempty"`
Payload string `json:"invoice_payload"`
// (Optional) State of the transaction if the transaction is outgoing$$
Withdrawal RevenueWithdrawal `json:"withdrawal_state,omitempty"`
}
type RevenueWithdrawal struct {
// Type of the state
Type RevenueState `json:"type"`
// Date the withdrawal was completed in Unix time
Unixtime int `json:"date,omitempty"`
// An HTTPS URL that can be used to see transaction details
URL string `json:"url,omitempty"`
}
// Time returns the date of the transaction.
func (c *StarTransaction) Time() time.Time {
return time.Unix(c.Unixtime, 0)
}
// Time returns the date of the withdrawal.
func (s *RevenueWithdrawal) Time() time.Time {
return time.Unix(int64(s.Unixtime), 0)
}