Example #1
0
func (c Client) Get(id string, params *stripe.CardParams) (*stripe.Card, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

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

	card := &stripe.Card{}
	var err error

	if len(params.Account) > 0 {
		err = c.B.Call("GET", fmt.Sprintf("/accounts/%v/external_accounts/%v", params.Account, id), c.Key, body, commonParams, card)
	} else if len(params.Customer) > 0 {
		err = c.B.Call("GET", fmt.Sprintf("/customers/%v/cards/%v", params.Customer, id), c.Key, body, commonParams, card)
	} else if len(params.Recipient) > 0 {
		err = c.B.Call("GET", fmt.Sprintf("/recipients/%v/cards/%v", params.Recipient, id), c.Key, body, commonParams, card)
	} else {
		err = errors.New("Invalid card params: either account, customer or recipient need to be set")
	}

	return card, err
}
Example #2
0
func (c Client) Update(id string, params *stripe.CardParams) (*stripe.Card, error) {
	body := &url.Values{}
	params.AppendDetails(body, false)
	params.AppendTo(body)

	card := &stripe.Card{}
	var err error

	if len(params.Customer) > 0 {
		err = c.B.Call("POST", fmt.Sprintf("/customers/%v/cards/%v", params.Customer, id), c.Key, body, &params.Params, card)
	} else if len(params.Recipient) > 0 {
		err = c.B.Call("POST", fmt.Sprintf("/recipients/%v/cards/%v", params.Recipient, id), c.Key, body, &params.Params, card)
	} else {
		err = errors.New("Invalid card params: either customer or recipient need to be set")
	}

	return card, err
}
Example #3
0
func (c Client) New(params *stripe.CardParams) (*stripe.Card, error) {
	body := &stripe.RequestValues{}
	params.AppendDetails(body, true)
	params.AppendTo(body)

	card := &stripe.Card{}
	var err error

	if len(params.Account) > 0 {
		if params.Default {
			body.Add("default_for_currency", strconv.FormatBool(params.Default))
		}
		err = c.B.Call("POST", fmt.Sprintf("/accounts/%v/external_accounts", params.Account), c.Key, body, &params.Params, card)
	} else if len(params.Customer) > 0 {
		err = c.B.Call("POST", fmt.Sprintf("/customers/%v/cards", params.Customer), c.Key, body, &params.Params, card)
	} else if len(params.Recipient) > 0 {
		err = c.B.Call("POST", fmt.Sprintf("/recipients/%v/cards", params.Recipient), c.Key, body, &params.Params, card)
	} else {
		err = errors.New("Invalid card params: either account, customer or recipient need to be set")
	}

	return card, err
}