-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathcreditnote.go
266 lines (244 loc) · 13.4 KB
/
creditnote.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//
//
// File generated from our OpenAPI spec
//
//
package stripe
import "encoding/json"
// Reason for issuing this credit note, one of `duplicate`, `fraudulent`, `order_change`, or `product_unsatisfactory`
type CreditNoteReason string
// List of values that CreditNoteReason can take
const (
CreditNoteReasonDuplicate CreditNoteReason = "duplicate"
CreditNoteReasonFraudulent CreditNoteReason = "fraudulent"
CreditNoteReasonOrderChange CreditNoteReason = "order_change"
CreditNoteReasonProductUnsatisfactory CreditNoteReason = "product_unsatisfactory"
)
// Status of this credit note, one of `issued` or `void`. Learn more about [voiding credit notes](https://stripe.com/docs/billing/invoices/credit-notes#voiding).
type CreditNoteStatus string
// List of values that CreditNoteStatus can take
const (
CreditNoteStatusIssued CreditNoteStatus = "issued"
CreditNoteStatusVoid CreditNoteStatus = "void"
)
// Type of this credit note, one of `pre_payment` or `post_payment`. A `pre_payment` credit note means it was issued when the invoice was open. A `post_payment` credit note means it was issued when the invoice was paid.
type CreditNoteType string
// List of values that CreditNoteType can take
const (
CreditNoteTypePostPayment CreditNoteType = "post_payment"
CreditNoteTypePrePayment CreditNoteType = "pre_payment"
)
// Line items that make up the credit note.
type CreditNoteLineParams struct {
// The line item amount to credit. Only valid when `type` is `invoice_line_item`.
Amount *int64 `form:"amount"`
// The description of the credit note line item. Only valid when the `type` is `custom_line_item`.
Description *string `form:"description"`
// The invoice line item to credit. Only valid when the `type` is `invoice_line_item`.
InvoiceLineItem *string `form:"invoice_line_item"`
// The line item quantity to credit.
Quantity *int64 `form:"quantity"`
// The tax rates which apply to the credit note line item. Only valid when the `type` is `custom_line_item`.
TaxRates []*string `form:"tax_rates"`
// Type of the credit note line item, one of `invoice_line_item` or `custom_line_item`
Type *string `form:"type"`
// The integer unit amount in cents (or local equivalent) of the credit note line item. This `unit_amount` will be multiplied by the quantity to get the full amount to credit for this line item. Only valid when `type` is `custom_line_item`.
UnitAmount *int64 `form:"unit_amount"`
// Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
}
// Issue a credit note to adjust the amount of a finalized invoice. For a status=open invoice, a credit note reduces
// its amount_due. For a status=paid invoice, a credit note does not affect its amount_due. Instead, it can result
// in any combination of the following:
//
//
// Refund: create a new refund (using refund_amount) or link an existing refund (using refund).
// Customer balance credit: credit the customer's balance (using credit_amount) which will be automatically applied to their next invoice when it's finalized.
// Outside of Stripe credit: record the amount that is or will be credited outside of Stripe (using out_of_band_amount).
//
//
// For post-payment credit notes the sum of the refund, credit and outside of Stripe amounts must equal the credit note total.
//
// You may issue multiple credit notes for an invoice. Each credit note will increment the invoice's pre_payment_credit_notes_amount
// or post_payment_credit_notes_amount depending on its status at the time of credit note creation.
type CreditNoteParams struct {
Params `form:"*"`
// The integer amount in cents (or local equivalent) representing the total amount of the credit note.
Amount *int64 `form:"amount"`
// The integer amount in cents (or local equivalent) representing the amount to credit the customer's balance, which will be automatically applied to their next invoice.
CreditAmount *int64 `form:"credit_amount"`
// ID of the invoice.
Invoice *string `form:"invoice"`
// Line items that make up the credit note.
Lines []*CreditNoteLineParams `form:"lines"`
// Credit note memo.
Memo *string `form:"memo"`
// The integer amount in cents (or local equivalent) representing the amount that is credited outside of Stripe.
OutOfBandAmount *int64 `form:"out_of_band_amount"`
// Reason for issuing this credit note, one of `duplicate`, `fraudulent`, `order_change`, or `product_unsatisfactory`
Reason *string `form:"reason"`
// ID of an existing refund to link this credit note to.
Refund *string `form:"refund"`
// The integer amount in cents (or local equivalent) representing the amount to refund. If set, a refund will be created for the charge associated with the invoice.
RefundAmount *int64 `form:"refund_amount"`
}
// Returns a list of credit notes.
type CreditNoteListParams struct {
ListParams `form:"*"`
// Only return credit notes for the customer specified by this customer ID.
Customer *string `form:"customer"`
// Only return credit notes for the invoice specified by this invoice ID.
Invoice *string `form:"invoice"`
}
// Get a preview of a credit note without creating it.
type CreditNotePreviewParams struct {
Params `form:"*"`
// The integer amount in cents (or local equivalent) representing the total amount of the credit note.
Amount *int64 `form:"amount"`
// The integer amount in cents (or local equivalent) representing the amount to credit the customer's balance, which will be automatically applied to their next invoice.
CreditAmount *int64 `form:"credit_amount"`
// ID of the invoice.
Invoice *string `form:"invoice"`
// Line items that make up the credit note.
Lines []*CreditNoteLineParams `form:"lines"`
// The credit note's memo appears on the credit note PDF.
Memo *string `form:"memo"`
// The integer amount in cents (or local equivalent) representing the amount that is credited outside of Stripe.
OutOfBandAmount *int64 `form:"out_of_band_amount"`
// Reason for issuing this credit note, one of `duplicate`, `fraudulent`, `order_change`, or `product_unsatisfactory`
Reason *string `form:"reason"`
// ID of an existing refund to link this credit note to.
Refund *string `form:"refund"`
// The integer amount in cents (or local equivalent) representing the amount to refund. If set, a refund will be created for the charge associated with the invoice.
RefundAmount *int64 `form:"refund_amount"`
}
// Marks a credit note as void. Learn more about [voiding credit notes](https://stripe.com/docs/billing/invoices/credit-notes#voiding).
type CreditNoteVoidParams struct {
Params `form:"*"`
}
// When retrieving a credit note preview, you'll get a lines property containing the first handful of those items. This URL you can retrieve the full (paginated) list of line items.
type CreditNoteLineItemListPreviewParams struct {
ListParams `form:"*"`
// The integer amount in cents (or local equivalent) representing the total amount of the credit note.
Amount *int64 `form:"amount"`
// The integer amount in cents (or local equivalent) representing the amount to credit the customer's balance, which will be automatically applied to their next invoice.
CreditAmount *int64 `form:"credit_amount"`
// ID of the invoice.
Invoice *string `form:"invoice"`
// Line items that make up the credit note.
Lines []*CreditNoteLineParams `form:"lines"`
// The credit note's memo appears on the credit note PDF.
Memo *string `form:"memo"`
// The integer amount in cents (or local equivalent) representing the amount that is credited outside of Stripe.
OutOfBandAmount *int64 `form:"out_of_band_amount"`
// Reason for issuing this credit note, one of `duplicate`, `fraudulent`, `order_change`, or `product_unsatisfactory`
Reason *string `form:"reason"`
// ID of an existing refund to link this credit note to.
Refund *string `form:"refund"`
// The integer amount in cents (or local equivalent) representing the amount to refund. If set, a refund will be created for the charge associated with the invoice.
RefundAmount *int64 `form:"refund_amount"`
}
// When retrieving a credit note, you'll get a lines property containing the the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items.
type CreditNoteLineItemListParams struct {
ListParams `form:"*"`
// ID is the credit note ID to list line items for.
ID *string `form:"-"` // Included in URL
}
// The integer amount in %s representing the total amount of discount that was credited.
type CreditNoteDiscountAmount struct {
// The amount, in %s, of the discount.
Amount int64 `json:"amount"`
// The discount that was applied to get this discount amount.
Discount *Discount `json:"discount"`
}
// The aggregate amounts calculated per tax rate for all line items.
type CreditNoteTaxAmount struct {
// The amount, in %s, of the tax.
Amount int64 `json:"amount"`
// Whether this tax amount is inclusive or exclusive.
Inclusive bool `json:"inclusive"`
// The tax rate that was applied to get this tax amount.
TaxRate *TaxRate `json:"tax_rate"`
}
// Issue a credit note to adjust an invoice's amount after the invoice is finalized.
//
// Related guide: [Credit Notes](https://stripe.com/docs/billing/invoices/credit-notes).
type CreditNote struct {
APIResource
// The integer amount in %s representing the total amount of the credit note, including tax.
Amount int64 `json:"amount"`
// Time at which the object was created. Measured in seconds since the Unix epoch.
Created int64 `json:"created"`
// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
Currency Currency `json:"currency"`
// ID of the customer.
Customer *Customer `json:"customer"`
// Customer balance transaction related to this credit note.
CustomerBalanceTransaction *CustomerBalanceTransaction `json:"customer_balance_transaction"`
// The integer amount in %s representing the total amount of discount that was credited.
DiscountAmount int64 `json:"discount_amount"`
// The aggregate amounts calculated per discount for all line items.
DiscountAmounts []*CreditNoteDiscountAmount `json:"discount_amounts"`
// Unique identifier for the object.
ID string `json:"id"`
// ID of the invoice.
Invoice *Invoice `json:"invoice"`
// Line items that make up the credit note
Lines *CreditNoteLineItemList `json:"lines"`
// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
Livemode bool `json:"livemode"`
// Customer-facing text that appears on the credit note PDF.
Memo string `json:"memo"`
// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
Metadata map[string]string `json:"metadata"`
// A unique number that identifies this particular credit note and appears on the PDF of the credit note and its associated invoice.
Number string `json:"number"`
// String representing the object's type. Objects of the same type share the same value.
Object string `json:"object"`
// Amount that was credited outside of Stripe.
OutOfBandAmount int64 `json:"out_of_band_amount"`
// The link to download the PDF of the credit note.
PDF string `json:"pdf"`
// Reason for issuing this credit note, one of `duplicate`, `fraudulent`, `order_change`, or `product_unsatisfactory`
Reason CreditNoteReason `json:"reason"`
// Refund related to this credit note.
Refund *Refund `json:"refund"`
// Status of this credit note, one of `issued` or `void`. Learn more about [voiding credit notes](https://stripe.com/docs/billing/invoices/credit-notes#voiding).
Status CreditNoteStatus `json:"status"`
// The integer amount in %s representing the amount of the credit note, excluding exclusive tax and invoice level discounts.
Subtotal int64 `json:"subtotal"`
// The integer amount in %s representing the amount of the credit note, excluding all tax and invoice level discounts.
SubtotalExcludingTax int64 `json:"subtotal_excluding_tax"`
// The aggregate amounts calculated per tax rate for all line items.
TaxAmounts []*CreditNoteTaxAmount `json:"tax_amounts"`
// The integer amount in %s representing the total amount of the credit note, including tax and all discount.
Total int64 `json:"total"`
// The integer amount in %s representing the total amount of the credit note, excluding tax, but including discounts.
TotalExcludingTax int64 `json:"total_excluding_tax"`
// Type of this credit note, one of `pre_payment` or `post_payment`. A `pre_payment` credit note means it was issued when the invoice was open. A `post_payment` credit note means it was issued when the invoice was paid.
Type CreditNoteType `json:"type"`
// The time that the credit note was voided.
VoidedAt int64 `json:"voided_at"`
}
// CreditNoteList is a list of CreditNotes as retrieved from a list endpoint.
type CreditNoteList struct {
APIResource
ListMeta
Data []*CreditNote `json:"data"`
}
// UnmarshalJSON handles deserialization of a CreditNote.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (c *CreditNote) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
c.ID = id
return nil
}
type creditNote CreditNote
var v creditNote
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*c = CreditNote(v)
return nil
}