Example #1
0
func (c Client) New(params *stripe.TokenParams) (*stripe.Token, error) {
	body := &url.Values{}
	token := c.Key

	if len(params.Customer) > 0 {
		body.Add("customer", params.Customer)
	}

	if params.Card != nil {
		params.Card.AppendDetails(body, true)
	} else if params.Bank != nil {
		params.Bank.AppendDetails(body)
	} else if len(params.Customer) == 0 {
		err := errors.New("Invalid Token params: either Card or Bank need to be set")
		return nil, err
	}

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

	params.AppendTo(body)

	tok := &stripe.Token{}
	err := c.B.Call("POST", "/tokens", token, body, &params.Params, tok)

	return tok, err
}
Example #2
0
func (c Client) Get(id string, params *stripe.TokenParams) (*stripe.Token, error) {
	var body *url.Values
	var commonParams *stripe.Params

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

	token := &stripe.Token{}
	err := c.B.Call("GET", "/tokens/"+id, c.Key, body, commonParams, token)

	return token, err
}