Exemplo n.º 1
0
func (c Client) Update(id string, params *stripe.SubItemParams) (*stripe.SubItem, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params
	token := c.Key

	if params != nil {
		body = &stripe.RequestValues{}

		if len(params.Plan) > 0 {
			body.Add("plan", params.Plan)
		}

		if params.NoProrate {
			body.Add("prorate", strconv.FormatBool(false))
		}

		if params.Quantity > 0 {
			body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
		} else if params.QuantityZero {
			body.Add("quantity", "0")
		}

		if params.ProrationDate > 0 {
			body.Add("proration_date", strconv.FormatInt(params.ProrationDate, 10))
		}

		commonParams = &params.Params
		params.AppendTo(body)
	}

	subi := &stripe.SubItem{}
	err := c.B.Call("POST", fmt.Sprintf("/subscription_items/%v", id), token, body, commonParams, subi)

	return subi, err
}
Exemplo n.º 2
0
func (c Client) New(params *stripe.SubItemParams) (*stripe.SubItem, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params
	token := c.Key

	if params != nil {
		body = &stripe.RequestValues{}
		body.Add("subscription", params.Sub)

		if len(params.Plan) > 0 {
			body.Add("plan", params.Plan)
		}
		if params.Quantity > 0 {
			body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
		} else if params.QuantityZero {
			body.Add("quantity", "0")
		}

		commonParams = &params.Params
		params.AppendTo(body)
	}

	item := &stripe.SubItem{}
	err := c.B.Call("POST", "/subscription_items", token, body, commonParams, item)
	return item, err
}
Exemplo n.º 3
0
func (c Client) Get(id string, params *stripe.SubItemParams) (*stripe.SubItem, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}
		params.AppendTo(body)
		commonParams = &params.Params
	}

	item := &stripe.SubItem{}
	err := c.B.Call("GET", fmt.Sprintf("/subscription_items/%v", id), c.Key, body, commonParams, item)

	return item, err
}