func (c Client) New(params *stripe.BankAccountParams) (*stripe.BankAccount, error) { body := &url.Values{} // Use token (if exists) or a dictionary containing a user’s bank account details. if len(params.Token) > 0 { body.Add("external_account", params.Token) } else { body.Add("external_account[object]", "bank_account") body.Add("external_account[country]", params.Country) body.Add("external_account[account_number]", params.Account) body.Add("external_account[routing_number]", params.Routing) body.Add("external_account[currency]", params.Currency) if params.Default { body.Add("external_account[default_for_currency]", strconv.FormatBool(params.Default)) } } params.AppendTo(body) ba := &stripe.BankAccount{} err := c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts", params.AccountID), c.Key, body, ¶ms.Params, ba) return ba, err }
func (c Client) Update(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { var body *stripe.RequestValues var commonParams *stripe.Params if params != nil { commonParams = ¶ms.Params body = &stripe.RequestValues{} if params.Default { body.Add("default_for_currency", strconv.FormatBool(params.Default)) } params.AppendTo(body) } ba := &stripe.BankAccount{} var err error if len(params.Customer) > 0 { err = c.B.Call("POST", fmt.Sprintf("/customers/%v/bank_accounts/%v", params.Customer, id), c.Key, body, commonParams, ba) } else if len(params.AccountID) > 0 { err = c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba) } else { err = errors.New("Invalid bank account params: either Customer or AccountID need to be set") } return ba, err }
func (c Client) New(params *stripe.BankAccountParams) (*stripe.BankAccount, error) { body := &stripe.RequestValues{} isCustomer := len(params.Customer) > 0 var sourceType string if isCustomer { sourceType = "source" } else { sourceType = "external_account" } // Use token (if exists) or a dictionary containing a user’s bank account details. if len(params.Token) > 0 { body.Add(sourceType, params.Token) if params.Default { body.Add("default_for_currency", strconv.FormatBool(params.Default)) } } else { body.Add(sourceType+"[object]", "bank_account") body.Add(sourceType+"[country]", params.Country) body.Add(sourceType+"[account_number]", params.Account) body.Add(sourceType+"[currency]", params.Currency) if isCustomer { body.Add(sourceType+"[account_holder_name]", params.AccountHolderName) body.Add(sourceType+"[account_holder_type]", params.AccountHolderType) } if len(params.Routing) > 0 { body.Add(sourceType+"[routing_number]", params.Routing) } if params.Default { body.Add(sourceType+"[default_for_currency]", strconv.FormatBool(params.Default)) } } params.AppendTo(body) ba := &stripe.BankAccount{} var err error if isCustomer { err = c.B.Call("POST", fmt.Sprintf("/customers/%v/sources", params.Customer), c.Key, body, ¶ms.Params, ba) } else { err = c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts", params.AccountID), c.Key, body, ¶ms.Params, ba) } return ba, err }
func (c Client) Get(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { var body *url.Values var commonParams *stripe.Params if params != nil { commonParams = ¶ms.Params body = &url.Values{} params.AppendTo(body) } ba := &stripe.BankAccount{} err := c.B.Call("GET", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba) return ba, err }
func (c Client) Update(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { var body *url.Values var commonParams *stripe.Params if params != nil { commonParams = ¶ms.Params body = &url.Values{} if params.Default { body.Add("default_for_currency", strconv.FormatBool(params.Default)) } params.AppendTo(body) } ba := &stripe.BankAccount{} err := c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba) return ba, err }
func (c Client) Get(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { var body *stripe.RequestValues var commonParams *stripe.Params if params != nil { commonParams = ¶ms.Params body = &stripe.RequestValues{} params.AppendTo(body) } ba := &stripe.BankAccount{} var err error if len(params.Customer) > 0 { err = c.B.Call("GET", fmt.Sprintf("/customers/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba) } else if len(params.AccountID) > 0 { err = c.B.Call("GET", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba) } else { err = errors.New("Invalid bank account params: either Customer or AccountID need to be set") } return ba, err }