-
Notifications
You must be signed in to change notification settings - Fork 461
/
refund.go
77 lines (66 loc) · 2.51 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package stripe
import "encoding/json"
// RefundReason is, if set, the reason the refund is being made
type RefundReason string
const (
RefundReasonDuplicate RefundReason = "duplicate"
RefundReasonFraudulent RefundReason = "fraudulent"
RefundReasonRequestedByCustomer RefundReason = "requested_by_customer"
)
// RefundStatus is the status of the refund.
type RefundStatus string
const (
RefundStatusCanceled RefundStatus = "canceled"
RefundStatusFailed RefundStatus = "failed"
RefundStatusPending RefundStatus = "pending"
RefundStatusSucceeded RefundStatus = "succeeded"
)
// 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 `form:"*"`
Amount *int64 `form:"amount"`
Charge *string `form:"charge"`
Reason *string `form:"reason"`
RefundApplicationFee *bool `form:"refund_application_fee"`
ReverseTransfer *bool `form:"reverse_transfer"`
}
// 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 `form:"*"`
}
// Refund is the resource representing a Stripe refund.
// For more details see https://stripe.com/docs/api#refunds.
type Refund struct {
Amount int64 `json:"amount"`
BalanceTransaction *BalanceTransaction `json:"balance_transaction"`
Charge *Charge `json:"charge"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
ID string `json:"id"`
Metadata map[string]string `json:"metadata"`
Reason RefundReason `json:"reason"`
ReceiptNumber string `json:"receipt_number"`
Status RefundStatus `json:"status"`
}
// RefundList is a list object for refunds.
type RefundList struct {
ListMeta
Data []*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
}