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) GetNext(params *stripe.InvoiceParams) (*stripe.Invoice, error) {
	body := &stripe.RequestValues{}
	body.Add("customer", params.Customer)

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

	if len(params.SubPlan) > 0 {
		body.Add("subscription_plan", params.SubPlan)
	}

	if params.SubNoProrate {
		body.Add("subscription_prorate", strconv.FormatBool(false))
	}

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

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

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

	params.AppendTo(body)

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

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

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

		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))
		} else if params.NoClosed {
			body.Add("closed", strconv.FormatBool(false))
		}

		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))
		} else if params.TaxPercentZero {
			body.Add("tax_percent", "0")
		}

		params.AppendTo(body)
	}

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

	return invoice, err
}
Exemple #4
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 #5
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 #6
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
}