本文整理汇总了Golang中github.com/stripe/stripe-go.CouponParams.AppendTo方法的典型用法代码示例。如果您正苦于以下问题:Golang CouponParams.AppendTo方法的具体用法?Golang CouponParams.AppendTo怎么用?Golang CouponParams.AppendTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/stripe/stripe-go.CouponParams
的用法示例。
在下文中一共展示了CouponParams.AppendTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Update
func (c Client) Update(id string, params *stripe.CouponParams) (*stripe.Coupon, error) {
body := &stripe.RequestValues{}
params.AppendTo(body)
coupon := &stripe.Coupon{}
err := c.B.Call("POST", "/coupons/"+url.QueryEscape(id), c.Key, body, ¶ms.Params, coupon)
return coupon, err
}
示例2: Get
func (c Client) Get(id string, params *stripe.CouponParams) (*stripe.Coupon, error) {
var body *stripe.RequestValues
var commonParams *stripe.Params
if params != nil {
commonParams = ¶ms.Params
body = &stripe.RequestValues{}
params.AppendTo(body)
}
coupon := &stripe.Coupon{}
err := c.B.Call("GET", "/coupons/"+url.QueryEscape(id), c.Key, body, commonParams, coupon)
return coupon, err
}
示例3: New
func (c Client) New(params *stripe.CouponParams) (*stripe.Coupon, error) {
// TODO: this doesn't check that the params are not nil.
body := &url.Values{
"duration": {string(params.Duration)},
}
if len(params.ID) > 0 {
body.Add("id", params.ID)
}
if params.Percent > 0 {
body.Add("percent_off", strconv.FormatUint(params.Percent, 10))
} else if params.Amount > 0 {
body.Add("amount_off", strconv.FormatUint(params.Amount, 10))
body.Add("currency", string(params.Currency))
} else {
err := errors.New("Invalid coupon params: either amount and currency or percent need to be set")
return nil, err
}
if params.Duration == Repeating {
body.Add("duration_in_months", strconv.FormatUint(params.DurationPeriod, 10))
}
if params.Redemptions > 0 {
body.Add("max_redemptions", strconv.FormatUint(params.Redemptions, 10))
}
if params.RedeemBy > 0 {
body.Add("redeem_by", strconv.FormatInt(params.RedeemBy, 10))
}
params.AppendTo(body)
coupon := &stripe.Coupon{}
err := c.B.Call("POST", "/coupons", c.Key, body, ¶ms.Params, coupon)
return coupon, err
}