Exemple #1
0
func (c Client) Update(id string, params *stripe.RecipientParams) (*stripe.Recipient, error) {
	var body *url.Values
	var commonParams *stripe.Params

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

		if len(params.Name) > 0 {
			body.Add("name", params.Name)
		}

		if params.Bank != nil {
			if len(params.Bank.Token) > 0 {
				body.Add("bank_account", params.Bank.Token)
			} else {
				params.Bank.AppendDetails(body)
			}
		}

		if len(params.Token) > 0 {
			body.Add("card", params.Token)
		} else if params.Card != nil {
			params.Card.AppendDetails(body, true)
		}

		if len(params.TaxID) > 0 {
			body.Add("tax_id", params.TaxID)
		}

		if len(params.DefaultCard) > 0 {
			body.Add("default_card", params.DefaultCard)
		}

		if len(params.Email) > 0 {
			body.Add("email", params.Email)
		}

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

		params.AppendTo(body)
	}

	recipient := &stripe.Recipient{}
	err := c.B.Call("POST", "/recipients/"+id, c.Key, body, commonParams, recipient)

	return recipient, err
}
Exemple #2
0
func (c Client) Get(id string, params *stripe.RecipientParams) (*stripe.Recipient, error) {
	var body *url.Values
	var commonParams *stripe.Params

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

	recipient := &stripe.Recipient{}
	err := c.B.Call("GET", "/recipients/"+id, c.Key, body, commonParams, recipient)

	return recipient, err
}
Exemple #3
0
func (c Client) New(params *stripe.RecipientParams) (*stripe.Recipient, error) {
	body := &url.Values{
		"name": {params.Name},
		"type": {string(params.Type)},
	}

	if params.Bank != nil {
		if len(params.Bank.Token) > 0 {
			body.Add("bank_account", params.Bank.Token)
		} else {
			params.Bank.AppendDetails(body)
		}
	}

	if len(params.Token) > 0 {
		body.Add("card", params.Token)
	} else if params.Card != nil {
		params.Card.AppendDetails(body, true)
	}

	if len(params.TaxID) > 0 {
		body.Add("tax_id", params.TaxID)
	}

	if len(params.Email) > 0 {
		body.Add("email", params.Email)
	}

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

	recipient := &stripe.Recipient{}
	err := c.B.Call("POST", "/recipients", c.Key, body, &params.Params, recipient)

	return recipient, err
}