-
Notifications
You must be signed in to change notification settings - Fork 448
/
topup.go
103 lines (90 loc) · 3.57 KB
/
topup.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
//
// File generated from our OpenAPI spec
//
//
package stripe
import "encoding/json"
// TopupStatus is a status of a Topup.
type TopupStatus string
// List of values that TopupStatus can take.
const (
TopupStatusCanceled TopupStatus = "canceled"
TopupStatusFailed TopupStatus = "failed"
TopupStatusPending TopupStatus = "pending"
TopupStatusReversed TopupStatus = "reversed"
TopupStatusSucceeded TopupStatus = "succeeded"
)
// TopupParams is the set of parameters that can be used when creating or updating a top-up.
// For more details see https://stripe.com/docs/api#create_topup and https://stripe.com/docs/api#update_topup.
type TopupParams struct {
Params `form:"*"`
Amount *int64 `form:"amount"`
Currency *string `form:"currency"`
Description *string `form:"description"`
Source *SourceParams `form:"*"` // SourceParams has custom encoding so brought to top level with "*"
StatementDescriptor *string `form:"statement_descriptor"`
TransferGroup *string `form:"transfer_group"`
}
// SetSource adds valid sources to a TopupParams object,
// returning an error for unsupported sources.
func (p *TopupParams) SetSource(sp interface{}) error {
source, err := SourceParamsFor(sp)
p.Source = source
return err
}
// TopupListParams is the set of parameters that can be used when listing top-ups.
// For more details see https://stripe.com/docs/api#list_topups.
type TopupListParams struct {
ListParams `form:"*"`
Amount *int64 `form:"amount"`
AmountRange *RangeQueryParams `form:"amount"`
Created *int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
Status *string `form:"status"`
}
// Topup is the resource representing a Stripe top-up.
// For more details see https://stripe.com/docs/api#topups.
type Topup struct {
APIResource
Amount int64 `json:"amount"`
BalanceTransaction *BalanceTransaction `json:"balance_transaction"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Description string `json:"description"`
ExpectedAvailabilityDate int64 `json:"expected_availability_date"`
FailureCode string `json:"failure_code"`
FailureMessage string `json:"failure_message"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Object string `json:"object"`
Source *PaymentSource `json:"source"`
StatementDescriptor string `json:"statement_descriptor"`
Status TopupStatus `json:"status"`
TransferGroup string `json:"transfer_group"`
// The following property is deprecated
ArrivalDate int64 `json:"arrival_date"`
}
// TopupList is a list of top-ups as retrieved from a list endpoint.
type TopupList struct {
APIResource
ListMeta
Data []*Topup `json:"data"`
}
// UnmarshalJSON handles deserialization of a Topup.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (t *Topup) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
t.ID = id
return nil
}
type topup Topup
var v topup
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*t = Topup(v)
return nil
}