forked from blacklightcms/recurly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredemptions.go
56 lines (52 loc) · 1.89 KB
/
redemptions.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
package recurly
import "encoding/xml"
const (
RedemptionStateActive = "active"
RedemptionStateInactive = "inactive"
)
// Redemption holds redeemed coupons for an account or invoice.
type Redemption struct {
UUID string
SubscriptionUUID string
AccountCode string
CouponCode string
SingleUse bool
TotalDiscountedInCents int
Currency string
State string
CreatedAt NullTime
UpdatedAt NullTime
}
// UnmarshalXML unmarshal a coupon redemption object. Minaly converts href links
// for coupons and accounts to CouponCode and AccountCodes.
func (r *Redemption) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var v struct {
XMLName xml.Name `xml:"redemption"`
AccountCode hrefString `xml:"account"`
SubscriptionUUID hrefString `xml:"subscription"`
UUID string `xml:"uuid"`
SingleUse bool `xml:"single_use"`
CouponCode string `xml:"coupon_code"`
TotalDiscountedInCents int `xml:"total_discounted_in_cents"`
Currency string `xml:"currency,omitempty"`
State string `xml:"state,omitempty"`
CreatedAt NullTime `xml:"created_at,omitempty"`
UpdatedAt NullTime `xml:"updated_at,omitempty"`
}
if err := d.DecodeElement(&v, &start); err != nil {
return err
}
*r = Redemption{
UUID: v.UUID,
SubscriptionUUID: string(v.SubscriptionUUID),
AccountCode: string(v.AccountCode),
CouponCode: v.CouponCode,
SingleUse: v.SingleUse,
TotalDiscountedInCents: v.TotalDiscountedInCents,
Currency: v.Currency,
State: v.State,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
return nil
}