forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice.go
162 lines (140 loc) · 4.91 KB
/
invoice.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package stripe
import "encoding/json"
// InvoiceLineType is the list of allowed values for the invoice line's type.
// Allowed values are "invoiceitem", "subscription".
type InvoiceLineType string
const (
TypeInvoiceItem InvoiceLineType = "invoiceitem"
TypeSubscription InvoiceLineType = "subscription"
)
// InvoiceParams is the set of parameters that can be used when creating or updating an invoice.
// For more details see https://stripe.com/docs/api#create_invoice, https://stripe.com/docs/api#update_invoice.
type InvoiceParams struct {
Params
Customer string
Desc, Statement, Sub string
Fee uint64
Closed, Forgive bool
}
// InvoiceListParams is the set of parameters that can be used when listing invoices.
// For more details see https://stripe.com/docs/api#list_customer_invoices.
type InvoiceListParams struct {
ListParams
Date int64
Customer string
}
// InvoiceLineListParams is the set of parameters that can be used when listing invoice line items.
// For more details see https://stripe.com/docs/api#invoice_lines.
type InvoiceLineListParams struct {
ListParams
Id string
Customer, Sub string
}
// Invoice is the resource representing a Stripe invoice.
// For more details see https://stripe.com/docs/api#invoice_object.
type Invoice struct {
Id string `json:"id"`
Live bool `json:"livemode"`
Amount int64 `json:"amount_due"`
Attempts uint64 `json:"attempt_count"`
Attempted bool `json:"attempted"`
Closed bool `json:"closed"`
Currency Currency `json:"currency"`
Customer *Customer `json:"customer"`
Date int64 `json:"date"`
Forgive bool `json:"forgiven"`
Lines *InvoiceLineList `json:"lines"`
Paid bool `json:"paid"`
End int64 `json:"period_end"`
Start int64 `json:"period_start"`
StartBalance int64 `json:"starting_balance"`
Subtotal int64 `json:"subtotal"`
Total int64 `json:"total"`
Fee uint64 `json:"application_fee"`
Charge *Charge `json:"charge"`
Desc string `json:"description"`
Discount *Discount `json:"discount"`
EndBalance int64 `json:"ending_balance"`
NextAttempt int64 `json:"next_payment_attempt"`
Statement string `json:"statement_description"`
Sub string `json:"subscription"`
Webhook int64 `json:"webhooks_delivered_at"`
Meta map[string]string `json:"metadata"`
}
// InvoiceLine is the resource representing a Stripe invoice line item.
// For more details see https://stripe.com/docs/api#invoice_line_item_object.
type InvoiceLine struct {
Id string `json:"id"`
Live bool `json:"live_mode"`
Amount int64 `json:"amount"`
Currency Currency `json:"currency"`
Period *Period `json:"period"`
Proration bool `json:"proration"`
Type InvoiceLineType `json:"type"`
Desc string `json:"description"`
Meta map[string]string `json:"metadata"`
Plan *Plan `json:"plan"`
Quantity int64 `json:"quantity"`
}
// Period is a structure representing a start and end dates.
type Period struct {
Start int64 `json:"start"`
End int64 `json:"end"`
}
// InvoiceLineList is a list object for invoice line items.
type InvoiceLineList struct {
ListMeta
Values []*InvoiceLine `json:"data"`
}
// InvoiceIter is a iterator for list responses.
type InvoiceIter struct {
Iter *Iter
}
// Next returns the next value in the list.
func (i *InvoiceIter) Next() (*Invoice, error) {
ii, err := i.Iter.Next()
if err != nil {
return nil, err
}
return ii.(*Invoice), err
}
// Stop returns true if there are no more iterations to be performed.
func (i *InvoiceIter) Stop() bool {
return i.Iter.Stop()
}
// Meta returns the list metadata.
func (i *InvoiceIter) Meta() *ListMeta {
return i.Iter.Meta()
}
// InvoiceLineIter is a iterator for list responses.
type InvoiceLineIter struct {
Iter *Iter
}
// Next returns the next value in the list.
func (i *InvoiceLineIter) Next() (*InvoiceLine, error) {
ii, err := i.Iter.Next()
if err != nil {
return nil, err
}
return ii.(*InvoiceLine), err
}
// Stop returns true if there are no more iterations to be performed.
func (i *InvoiceLineIter) Stop() bool {
return i.Iter.Stop()
}
// Meta returns the list metadata.
func (i *InvoiceLineIter) Meta() *ListMeta {
return i.Iter.Meta()
}
func (i *Invoice) UnmarshalJSON(data []byte) error {
type invoice Invoice
var ii invoice
err := json.Unmarshal(data, &ii)
if err == nil {
*i = Invoice(ii)
} else {
// the id is surrounded by escaped \, so ignore those
i.Id = string(data[1 : len(data)-1])
}
return nil
}