Ai
2 Star 0 Fork 0

mirrors_sourcegraph/stripe-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
coupon.go 2.69 KB
一键复制 编辑 原始数据 按行查看 历史
Remi Jannel 提交于 2018-06-17 05:07 +08:00 . Add name to the Coupon resource
package stripe
import "encoding/json"
// CouponDuration is the list of allowed values for the coupon's duration.
type CouponDuration string
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 *int64 `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 int64 `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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_sourcegraph/stripe-go.git
git@gitee.com:mirrors_sourcegraph/stripe-go.git
mirrors_sourcegraph
stripe-go
stripe-go
master

搜索帮助