forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refund.go
60 lines (52 loc) · 1.73 KB
/
refund.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
package stripe
import "encoding/json"
// RefundReason, if set, is the reason the refund is being made--allowed values
// are "fraudulent", "duplicate", and "requested_by_customer".
type RefundReason string
// RefundParams is the set of parameters that can be used when refunding a charge.
// For more details see https://stripe.com/docs/api#refund.
type RefundParams struct {
Params
Charge string
Amount uint64
Fee, Transfer bool
Reason RefundReason
}
// RefundListParams is the set of parameters that can be used when listing refunds.
// For more details see https://stripe.com/docs/api#list_refunds.
type RefundListParams struct {
ListParams
Charge string
}
// Refund is the resource representing a Stripe refund.
// For more details see https://stripe.com/docs/api#refunds.
type Refund struct {
ID string `json:"id"`
Amount uint64 `json:"amount"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Tx *Transaction `json:"balance_transaction"`
Charge string `json:"charge"`
Meta map[string]string `json:"metadata"`
Reason RefundReason `json:"reason"`
}
// RefundList is a list object for refunds.
type RefundList struct {
ListMeta
Values []*Refund `json:"data"`
}
// UnmarshalJSON handles deserialization of a Refund.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (r *Refund) UnmarshalJSON(data []byte) error {
type refund Refund
var rr refund
err := json.Unmarshal(data, &rr)
if err == nil {
*r = Refund(rr)
} else {
// the id is surrounded by "\" characters, so strip them
r.ID = string(data[1 : len(data)-1])
}
return nil
}