Exemple #1
0
func (c Client) New(params *stripe.InvoiceParams) (*stripe.Invoice, error) {
	body := &url.Values{
		"customer": {params.Customer},
	}

	if len(params.Desc) > 0 {
		body.Add("description", params.Desc)
	}

	if len(params.Statement) > 0 {
		body.Add("statement_descriptor", params.Statement)
	}

	if len(params.Sub) > 0 {
		body.Add("subscription", params.Sub)
	}

	params.AppendTo(body)

	token := c.Key
	if params.Fee > 0 {
		body.Add("application_fee", strconv.FormatUint(params.Fee, 10))
	}

	if params.TaxPercent > 0 {
		body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64))
	}

	invoice := &stripe.Invoice{}
	err := c.B.Call("POST", "/invoices", token, body, &params.Params, invoice)

	return invoice, err
}
Exemple #2
0
func (c Client) Pay(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) {
	var body *url.Values
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &url.Values{}
		params.AppendTo(body)
	}

	invoice := &stripe.Invoice{}
	err := c.B.Call("POST", fmt.Sprintf("/invoices/%v/pay", id), c.Key, body, commonParams, invoice)

	return invoice, err
}
Exemple #3
0
func (c Client) Get(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) {
	var body *url.Values
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &url.Values{}
		params.AppendTo(body)
	}

	invoice := &stripe.Invoice{}
	err := c.B.Call("GET", "/invoices/"+id, c.Key, body, commonParams, invoice)

	return invoice, err
}
Exemple #4
0
func (c Client) GetNext(params *stripe.InvoiceParams) (*stripe.Invoice, error) {
	body := &url.Values{
		"customer": {params.Customer},
	}

	if len(params.Sub) > 0 {
		body.Add("subscription", params.Sub)
	}

	params.AppendTo(body)

	invoice := &stripe.Invoice{}
	err := c.B.Call("GET", "/invoices/upcoming", c.Key, body, &params.Params, invoice)

	return invoice, err
}
Exemple #5
0
func (c Client) Update(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) {
	var body *url.Values
	token := c.Key
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &url.Values{}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if len(params.Statement) > 0 {
			body.Add("statement_descriptor", params.Statement)
		}

		if len(params.Sub) > 0 {
			body.Add("subscription", params.Sub)
		}

		if params.Closed {
			body.Add("closed", strconv.FormatBool(true))
		}

		if params.Forgive {
			body.Add("forgiven", strconv.FormatBool(true))
		}

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

		if params.TaxPercent > 0 {
			body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64))
		}

		params.AppendTo(body)
	}

	invoice := &stripe.Invoice{}
	err := c.B.Call("POST", "/invoices/"+id, token, body, commonParams, invoice)

	return invoice, err
}