예제 #1
0
func (c Client) New(params *stripe.RefundParams) (*stripe.Refund, error) {
	body := &url.Values{}

	if params.Amount > 0 {
		body.Add("amount", strconv.FormatUint(params.Amount, 10))
	}

	if params.Fee {
		body.Add("refund_application_fee", strconv.FormatBool(params.Fee))
	}

	if params.Transfer {
		body.Add("refund_transfer", strconv.FormatBool(params.Transfer))
	}

	if len(params.Reason) > 0 {
		body.Add("reason", string(params.Reason))
	}

	params.AppendTo(body)

	refund := &stripe.Refund{}
	err := c.B.Call("POST", fmt.Sprintf("/charges/%v/refunds", params.Charge), c.Key, body, &params.Params, refund)

	return refund, err
}
예제 #2
0
func (c Client) Update(id string, params *stripe.RefundParams) (*stripe.Refund, error) {
	body := &url.Values{}

	params.AppendTo(body)

	refund := &stripe.Refund{}
	err := c.B.Call("POST", fmt.Sprintf("/charges/%v/refunds/%v", params.Charge, id), c.Key, body, &params.Params, refund)

	return refund, err
}
예제 #3
0
func (c Client) Get(id string, params *stripe.RefundParams) (*stripe.Refund, error) {
	if params == nil {
		return nil, fmt.Errorf("params cannot be nil, and params.Charge must be set")
	}

	body := &url.Values{}
	params.AppendTo(body)

	refund := &stripe.Refund{}
	err := c.B.Call("GET", fmt.Sprintf("/charges/%v/refunds/%v", params.Charge, id), c.Key, body, &params.Params, refund)

	return refund, err
}