~evanj/cms

ref: 9d7fbcbdf7e7332ea56493092efe5cffbadccdd6 cms/vendor/github.com/stripe/stripe-go/v71/creditnote.go -rw-r--r-- 9.6 KiB
9d7fbcbdEvan M Jones Fix(go.mod/vendor): Attempting to fix vendoring for deploys. 10 months ago
                                                                                
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
package stripe

import "encoding/json"

// CreditNoteReason is the reason why a given credit note was created.
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"
)

// CreditNoteStatus is the list of allowed values for the credit note's status.
type CreditNoteStatus string

// List of values that CreditNoteStatus can take.
const (
	CreditNoteStatusIssued CreditNoteStatus = "issued"
	CreditNoteStatusVoid   CreditNoteStatus = "void"
)

// CreditNoteType is the list of allowed values for the credit note's type.
type CreditNoteType string

// List of values that CreditNoteType can take.
const (
	CreditNoteTypePostPayment CreditNoteType = "post_payment"
	CreditNoteTypePrePayment  CreditNoteType = "pre_payment"
)

// CreditNoteLineItemType is the list of allowed values for the credit note line item's type.
type CreditNoteLineItemType string

// List of values that CreditNoteType can take.
const (
	CreditNoteLineItemTypeCustomLineItem  CreditNoteLineItemType = "custom_line_item"
	CreditNoteLineItemTypeInvoiceLineItem CreditNoteLineItemType = "invoice_line_item"
)

// CreditNoteParams is the set of parameters that can be used when creating or updating a credit note.
// For more details see https://stripe.com/docs/api/credit_notes/create, https://stripe.com/docs/api/credit_notes/update.
type CreditNoteParams struct {
	Params          `form:"*"`
	Amount          *int64                  `form:"amount"`
	CreditAmount    *int64                  `form:"credit_amount"`
	Invoice         *string                 `form:"invoice"`
	Lines           []*CreditNoteLineParams `form:"lines"`
	Memo            *string                 `form:"memo"`
	OutOfBandAmount *int64                  `form:"out_of_band_amount"`
	Reason          *string                 `form:"reason"`
	Refund          *string                 `form:"refund"`
	RefundAmount    *int64                  `form:"refund_amount"`
}

// CreditNoteListParams is the set of parameters that can be used when listing credit notes.
// For more details see https://stripe.com/docs/api/credit_notes/list.
type CreditNoteListParams struct {
	ListParams `form:"*"`
	Customer   *string `form:"customer"`
	Invoice    *string `form:"invoice"`
}

// CreditNoteLineItemListParams is the set of parameters that can be used when listing credit note line items.
type CreditNoteLineItemListParams struct {
	ListParams `form:"*"`

	// ID is the credit note ID to list line items for.
	ID *string `form:"-"` // Goes in the URL
}

// CreditNoteLineItemListPreviewParams is the set of parameters that can be used when previewing a credit note's line items
type CreditNoteLineItemListPreviewParams struct {
	ListParams      `form:"*"`
	Amount          *int64                  `form:"amount"`
	CreditAmount    *int64                  `form:"credit_amount"`
	Invoice         *string                 `form:"invoice"`
	Lines           []*CreditNoteLineParams `form:"lines"`
	Memo            *string                 `form:"memo"`
	OutOfBandAmount *int64                  `form:"out_of_band_amount"`
	Reason          *string                 `form:"reason"`
	Refund          *string                 `form:"refund"`
	RefundAmount    *int64                  `form:"refund_amount"`
}

// CreditNoteLineParams is the set of parameters that can be used for a line item when creating
// or previewing a credit note.
type CreditNoteLineParams struct {
	Amount            *int64    `form:"amount"`
	Description       *string   `form:"description"`
	InvoiceLineItem   *string   `form:"invoice_line_item"`
	Quantity          *int64    `form:"quantity"`
	TaxRates          []*string `form:"tax_rates"`
	UnitAmount        *int64    `form:"unit_amount"`
	UnitAmountDecimal *float64  `form:"unit_amount_decimal,high_precision"`
	Type              *string   `form:"type"`
}

// CreditNotePreviewParams is the set of parameters that can be used when previewing a credit note.
// For more details see https://stripe.com/docs/api/credit_notes/preview.
type CreditNotePreviewParams struct {
	Params          `form:"*"`
	Amount          *int64                  `form:"amount"`
	CreditAmount    *int64                  `form:"credit_amount"`
	Invoice         *string                 `form:"invoice"`
	Lines           []*CreditNoteLineParams `form:"lines"`
	Memo            *string                 `form:"memo"`
	OutOfBandAmount *int64                  `form:"out_of_band_amount"`
	Reason          *string                 `form:"reason"`
	Refund          *string                 `form:"refund"`
	RefundAmount    *int64                  `form:"refund_amount"`
}

// CreditNoteVoidParams is the set of parameters that can be used when voiding invoices.
type CreditNoteVoidParams struct {
	Params `form:"*"`
}

// CreditNoteDiscountAmount represents the aggregate amounts calculated per discount for all line items.
type CreditNoteDiscountAmount struct {
	Amount   int64     `json:"amount"`
	Discount *Discount `json:"discount"`
}

// CreditNoteTaxAmount represent the tax amount applied to a credit note.
type CreditNoteTaxAmount struct {
	Amount    int64    `json:"amount"`
	Inclusive bool     `json:"inclusive"`
	TaxRate   *TaxRate `json:"tax_rate"`
}

// CreditNote is the resource representing a Stripe credit note.
// For more details see https://stripe.com/docs/api/credit_notes/object.
type CreditNote struct {
	APIResource
	Amount                     int64                       `json:"amount"`
	Created                    int64                       `json:"created"`
	Currency                   Currency                    `json:"currency"`
	Customer                   *Customer                   `json:"customer"`
	CustomerBalanceTransaction *CustomerBalanceTransaction `json:"customer_balance_transaction"`
	DiscountAmount             int64                       `json:"discount_amount"`
	DiscountAmounts            []*CreditNoteDiscountAmount `json:"discount_amounts"`
	Invoice                    *Invoice                    `json:"invoice"`
	ID                         string                      `json:"id"`
	Lines                      *CreditNoteLineItemList     `json:"lines"`
	Livemode                   bool                        `json:"livemode"`
	Memo                       string                      `json:"memo"`
	Metadata                   map[string]string           `json:"metadata"`
	Number                     string                      `json:"number"`
	Object                     string                      `json:"object"`
	OutOfBandAmount            int64                       `json:"out_of_band_amount"`
	PDF                        string                      `json:"pdf"`
	Reason                     CreditNoteReason            `json:"reason"`
	Refund                     *Refund                     `json:"refund"`
	Status                     CreditNoteStatus            `json:"status"`
	Subtotal                   int64                       `json:"subtotal"`
	TaxAmounts                 []*CreditNoteTaxAmount      `json:"tax_amounts"`
	Total                      int64                       `json:"total"`
	Type                       CreditNoteType              `json:"type"`
	VoidedAt                   int64                       `json:"voided_at"`
}

// CreditNoteLineItemDiscountAmount represents the amount of discount calculated per discount for this line item.
type CreditNoteLineItemDiscountAmount struct {
	Amount   int64     `json:"amount"`
	Discount *Discount `json:"discount"`
}

// CreditNoteLineItem is the resource representing a Stripe credit note line item.
// For more details see https://stripe.com/docs/api/credit_notes/line_item
type CreditNoteLineItem struct {
	Amount            int64                               `json:"amount"`
	Description       string                              `json:"description"`
	DiscountAmount    int64                               `json:"discount_amount"`
	DiscountAmounts   []*CreditNoteLineItemDiscountAmount `json:"discount_amounts"`
	ID                string                              `json:"id"`
	InvoiceLineItem   string                              `json:"invoice_line_item"`
	Livemode          bool                                `json:"livemode"`
	Object            string                              `json:"object"`
	Quantity          int64                               `json:"quantity"`
	TaxAmounts        []*CreditNoteTaxAmount              `json:"tax_amounts"`
	TaxRates          []*TaxRate                          `json:"tax_rates"`
	Type              CreditNoteLineItemType              `json:"type"`
	UnitAmount        int64                               `json:"unit_amount"`
	UnitAmountDecimal float64                             `json:"unit_amount_decimal,string"`
}

// CreditNoteList is a list of credit notes as retrieved from a list endpoint.
type CreditNoteList struct {
	APIResource
	ListMeta
	Data []*CreditNote `json:"data"`
}

// CreditNoteLineItemList is a list of credit note line items as retrieved from a list endpoint.
type CreditNoteLineItemList struct {
	APIResource
	ListMeta
	Data []*CreditNoteLineItem `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 (i *CreditNote) UnmarshalJSON(data []byte) error {
	if id, ok := ParseID(data); ok {
		i.ID = id
		return nil
	}

	type note CreditNote
	var v note
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}

	*i = CreditNote(v)
	return nil
}