-
Notifications
You must be signed in to change notification settings - Fork 455
/
creditnote.go
106 lines (91 loc) · 4.04 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
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"
)
// 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"`
Memo *string `form:"memo"`
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"`
}
// CreditNoteVoidParams is the set of parameters that can be used when voiding invoices.
type CreditNoteVoidParams struct {
Params `form:"*"`
}
// CreditNote is the resource representing a Stripe credit note.
// For more details see https://stripe.com/docs/api/credit_notes/object.
type CreditNote struct {
Amount int64 `json:"amount"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Customer *Customer `json:"customer"`
CustomerBalanceTransaction *CustomerBalanceTransaction `json:"customer_balance_transaction"`
Invoice *Invoice `json:"invoice"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Memo string `json:"memo"`
Metadata map[string]string `json:"metadata"`
Number string `json:"number"`
Object string `json:"object"`
PDF string `json:"pdf"`
Reason CreditNoteReason `json:"reason"`
Refund *Refund `json:"refund"`
Status CreditNoteStatus `json:"status"`
Type CreditNoteType `json:"type"`
VoidedAt int64 `json:"voided_at"`
}
// CreditNoteList is a list of credit notes as retrieved from a list endpoint.
type CreditNoteList struct {
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 (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
}