-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinvoice.go
204 lines (180 loc) · 6.7 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package chargebee
import (
"fmt"
"net/url"
"strconv"
)
type InvoiceStatus string
const (
Paid InvoiceStatus = "paid"
PaymentDue InvoiceStatus = "payment_due"
NotPaid InvoiceStatus = "not_paid"
Voided InvoiceStatus = "voided"
Pending InvoiceStatus = "pending"
)
type PriceType string
const (
TaxExclusive PriceType = "tax_exclusive"
TaxInclusive PriceType = "tax_inclusive"
)
type Refund struct {
Invoice Invoice `json:"invoice"`
Transaction Transaction `json:"transaction"`
CreditNote CreditNote `json:"credit_note"`
}
type InvoiceParams struct {
CustomerID string
Charges []*ChargeDetail
}
type ChargeDetail struct {
Amount uint64
Description string
}
func (c *ChargeDetail) AppendDetails(i int, values *url.Values) {
if c.Amount >= 1 {
values.Add(fmt.Sprintf("charges[amount][%d]", i), strconv.FormatUint(c.Amount, 10))
}
if len(c.Description) > 0 {
values.Add(fmt.Sprintf("charges[description][%d]", i), c.Description)
}
}
type ReasonCode string
const (
ProductUnsatisfactory ReasonCode = "product_unsatisfactory"
ServiceUnsatisfactory ReasonCode = "service_unsatisfactory"
OrderChange ReasonCode = "order_change"
OrderCancellation ReasonCode = "order_cancellation"
Waiver ReasonCode = "waiver"
Other ReasonCode = "other"
)
type RefundParams struct {
InvoiceID string
RefundAmount uint64
Comment string
CustomerNotes string
ReasonCode ReasonCode
}
//https://apidocs.chargebee.com/docs/api/invoices
type Invoice struct {
ID string `json:"id"`
PONumber string `json:"po_number"`
CustomerID string `json:"customer_id"`
SubscriptionID string `json:"subscription_id"`
Recurring bool `json:"recurring"`
Status InvoiceStatus `json:"status"`
VatNumber string `json:"vat_number"`
PriceType PriceType `json:"price_type"`
Date int64 `json:"date"`
Total uint64 `json:"total"`
AmountPaid uint64 `json:"amount_paid"`
AmountAdjusted uint64 `json:"amount_adjusted"`
WriteOffAmount uint64 `json:"write_off_amount"`
CreditsApplied uint64 `json:"credits_applied"`
AmountDue uint64 `json:"amount_due"`
PaidAt int64 `json:"paid_at"`
DunningStatus string `json:"dunning_status"`
NextRetryAt int64 `json:"next_retry_at"`
SubTotal uint64 `json:"sub_total"`
Tax uint64 `json:"tax"`
FirstInvoice bool `json:"first_invoice"`
CurrencyCode string `json:"currency_code"`
ShippingAddress Address `json:"shipping_address"`
BillingAddress Address `json:"billing_address"`
LineItems []LineItem `json:"line_items"`
LinkedPayments []LinkedPayment `json:"linked_payments"`
AppliedCredits []AppliedCredit `json:"applied_credits"`
AdjustmentCreditNotes []InvoiceCreditNote `json:"adjustment_credit_notes"`
IssuedCreditNotes []InvoiceCreditNote `json:"issued_credit_notes"`
LinkedOrders []LinkedOrder `json:"linked_orders"`
Discounts []Discount `json:"discounts"`
Taxes []Tax `json:"taxes"`
LineItemTaxes []LineItemTax `json:"line_item_taxes"`
Notes []Note `json:"notes"`
}
type LineItem struct {
ID string `json:"id"`
DateFrom int64 `json:"date_from"`
DateTo int64 `json:"date_to"`
UnitMmount uint64 `json:"unit_amount"`
Quantity int64 `json:quantity`
IsTaxed bool `json:"is_taxed"`
TaxAmount uint64 `json:"tax_amount"`
TaxRate float32 `json:"tax_rate"`
Amount uint64 `json:"amount"`
DiscountAmount uint64 `json:"discount_amount"`
ItemLevelDiscountAmount uint64 `json:"item_level_discount_amount"`
Description string `json:"description"`
EntityType string `json:"entity_type"`
EntityID string `json:"entity_id"`
}
type Discount struct {
Amount uint64 `json:"amount"`
Description string `json:"description"`
EntityType string `json:"entity_type"`
EntityID string `json:"entity_id"`
}
type Tax struct {
Name string `json:"name"`
Amount uint64 `json:"amount"`
Description string `json:"description"`
}
type LineItemTax struct {
LineItemID string `json:"line_item_id"`
TaxName string `json:"tax_name"`
TaxRate float32 `json:"tax_rate"`
TaxAmount uint64 `json:"tax_amount"`
TaxJurisType string `json:"tax_juris_type"`
TaxJurisName string `json:"tax_juris_name"`
TaxJurisCode string `json:"tax_juris_code"`
}
type LinkedPayment struct {
TxnID string `json:"txn_id"`
AppliedAmount uint64 `json:"applied_amount"`
AppliedAt int64 `json:"applied_at"`
TxnStatus string `json:"txn_status"`
TxnDate int64 `json:"txn_date"`
TxnAmount uint64 `json:"txn_amount"`
}
type AppliedCredit struct {
CNID string `json:"cn_id"`
AppliedAmount uint64 `json:"applied_amount"`
AppliedAt int64 `json:"applied_at"`
CNReasonCode string `json:"cn_reason_code"`
CNDate int64 `json:"cn_date"`
CNStatus string `json:"cn_status"`
}
type InvoiceCreditNote struct {
CNID string `json:"cn_id"`
CNReasonCode string `json:"cn_reason_code"`
CNDate int64 `json:"cn_date"`
CNTotal uint64 `json:"cn_total"`
CNStatus string `json:"cn_status"`
}
type LinkedOrder struct {
ID string `json:"id"`
Status string `json:"status"`
ReferenceID string `json:"reference_id"`
FulfillmentStatus string `json:"fulfillment_status"`
BatchID string `json:"batch_id"`
CreatedAt int64 `json:"created_at"`
}
type Note struct {
EntityType string `json:"entity_type"`
Note string `json:"note"`
EntityID string `json:"entity_id"`
}
type Address struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
Company string `json:"company"`
Phone string `json:"phone"`
Line1 string `json:"line1"`
Line2 string `json:"line2"`
Line3 string `json:"line3"`
City string `json:"city"`
StateCode string `json:"state_code"`
State string `json:"state"`
Country string `json:"country"`
Zip string `json:"zip"`
}