forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoice.go
113 lines (102 loc) · 4.08 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
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
// 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
TaxPercent float64
}
// 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"`
Tax int64 `json:"tax"`
TaxPercent float64 `json:"tax_percent"`
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_descriptor"`
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"`
}
// UnmarshalJSON handles deserialization of an Invoice.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
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 "\" characters, so strip them
i.ID = string(data[1 : len(data)-1])
}
return nil
}