func (c Client) Cancel(id string, params *stripe.SubParams) error { body := &url.Values{} if params.EndCancel { body.Add("at_period_end", strconv.FormatBool(true)) } params.AppendTo(body) return c.B.Call("DELETE", fmt.Sprintf("/customers/%v/subscriptions/%v", params.Customer, id), c.Key, body, ¶ms.Params, nil) }
func (c Client) Update(id string, params *stripe.SubParams) (*stripe.Sub, error) { body := &url.Values{} if len(params.Plan) > 0 { body.Add("plan", params.Plan) } if params.NoProrate { body.Add("prorate", strconv.FormatBool(false)) } if len(params.Token) > 0 { body.Add("card", params.Token) } else if params.Card != nil { if len(params.Card.Token) > 0 { body.Add("card", params.Card.Token) } else { params.Card.AppendDetails(body, true) } } if len(params.Coupon) > 0 { body.Add("coupon", params.Coupon) } if params.TrialEnd > 0 { body.Add("trial_end", strconv.FormatInt(params.TrialEnd, 10)) } if params.Quantity > 0 { body.Add("quantity", strconv.FormatUint(params.Quantity, 10)) } token := c.Key if params.FeePercent > 0 { body.Add("application_fee_percent", strconv.FormatFloat(params.FeePercent, 'f', 2, 64)) } if params.TaxPercent > 0 { body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64)) } if params.ProrationDate > 0 { body.Add("proration_date", strconv.FormatInt(params.ProrationDate, 10)) } params.AppendTo(body) sub := &stripe.Sub{} err := c.B.Call("POST", fmt.Sprintf("/customers/%v/subscriptions/%v", params.Customer, id), token, body, ¶ms.Params, sub) return sub, err }
func (c Client) Get(id string, params *stripe.SubParams) (*stripe.Sub, error) { if params == nil { return nil, fmt.Errorf("params cannot be nil, and params.Customer must be set") } body := &url.Values{} params.AppendTo(body) sub := &stripe.Sub{} err := c.B.Call("GET", fmt.Sprintf("/customers/%v/subscriptions/%v", params.Customer, id), c.Key, body, ¶ms.Params, sub) return sub, err }
func (c Client) New(params *stripe.SubParams) (*stripe.Sub, error) { body := &url.Values{ "plan": {params.Plan}, } if len(params.Token) > 0 { body.Add("card", params.Token) } else if params.Card != nil { params.Card.AppendDetails(body, true) } if len(params.Coupon) > 0 { body.Add("coupon", params.Coupon) } if params.TrialEndNow { body.Add("trial_end", "now") } else if params.TrialEnd > 0 { body.Add("trial_end", strconv.FormatInt(params.TrialEnd, 10)) } if params.Quantity > 0 { body.Add("quantity", strconv.FormatUint(params.Quantity, 10)) } else if params.QuantityZero { body.Add("quantity", "0") } token := c.Key if params.FeePercent > 0 { body.Add("application_fee_percent", strconv.FormatFloat(params.FeePercent, 'f', 2, 64)) } if params.TaxPercent > 0 { body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64)) } if params.BillingCycleAnchorNow { body.Add("billing_cycle_anchor", "now") } else if params.BillingCycleAnchor > 0 { body.Add("billing_cycle_anchor", strconv.FormatInt(params.BillingCycleAnchor, 10)) } params.AppendTo(body) sub := &stripe.Sub{} err := c.B.Call("POST", fmt.Sprintf("/customers/%v/subscriptions", params.Customer), token, body, ¶ms.Params, sub) return sub, err }