-
Notifications
You must be signed in to change notification settings - Fork 460
/
coupon.go
81 lines (71 loc) · 2.75 KB
/
coupon.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
package stripe
import "encoding/json"
// CouponDuration is the list of allowed values for the coupon's duration.
type CouponDuration string
// List of values that CouponDuration can take.
const (
CouponDurationForever CouponDuration = "forever"
CouponDurationOnce CouponDuration = "once"
CouponDurationRepeating CouponDuration = "repeating"
)
// CouponParams is the set of parameters that can be used when creating a coupon.
// For more details see https://stripe.com/docs/api#create_coupon.
type CouponParams struct {
Params `form:"*"`
AmountOff *int64 `form:"amount_off"`
Currency *string `form:"currency"`
Duration *string `form:"duration"`
DurationInMonths *int64 `form:"duration_in_months"`
ID *string `form:"id"`
MaxRedemptions *int64 `form:"max_redemptions"`
Name *string `form:"name"`
PercentOff *float64 `form:"percent_off"`
RedeemBy *int64 `form:"redeem_by"`
}
// CouponListParams is the set of parameters that can be used when listing coupons.
// For more detail see https://stripe.com/docs/api#list_coupons.
type CouponListParams struct {
ListParams `form:"*"`
Created *int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
}
// Coupon is the resource representing a Stripe coupon.
// For more details see https://stripe.com/docs/api#coupons.
type Coupon struct {
AmountOff int64 `json:"amount_off"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Deleted bool `json:"deleted"`
Duration CouponDuration `json:"duration"`
DurationInMonths int64 `json:"duration_in_months"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
MaxRedemptions int64 `json:"max_redemptions"`
Metadata map[string]string `json:"metadata"`
Name string `json:"name"`
PercentOff float64 `json:"percent_off"`
RedeemBy int64 `json:"redeem_by"`
TimesRedeemed int64 `json:"times_redeemed"`
Valid bool `json:"valid"`
}
// CouponList is a list of coupons as retrieved from a list endpoint.
type CouponList struct {
ListMeta
Data []*Coupon `json:"data"`
}
// UnmarshalJSON handles deserialization of a Coupon.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (c *Coupon) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
c.ID = id
return nil
}
type coupon Coupon
var v coupon
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*c = Coupon(v)
return nil
}