Пример #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 params.PII != nil {
		params.PII.AppendDetails(body)
	} else if len(params.Customer) == 0 {
		err := errors.New("Invalid Token params: either Card, Bank, or PII 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
}
Пример #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
}