Skip to content

Commit

Permalink
Mega-commit to move everything over to new parameter system
Browse files Browse the repository at this point in the history
  • Loading branch information
brandur committed May 24, 2016
1 parent 30b2a40 commit 9896155
Show file tree
Hide file tree
Showing 41 changed files with 314 additions and 357 deletions.
7 changes: 3 additions & 4 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package stripe
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
)

Expand Down Expand Up @@ -274,7 +273,7 @@ type AccountRejectParams struct {
}

// AppendDetails adds the legal entity to the query string.
func (l *LegalEntity) AppendDetails(values *url.Values) {
func (l *LegalEntity) AppendDetails(values *RequestValues) {
values.Add("legal_entity[type]", string(l.Type))

if len(l.BusinessName) > 0 {
Expand Down Expand Up @@ -397,7 +396,7 @@ func (l *LegalEntity) AppendDetails(values *url.Values) {
}

// AppendDetails adds the transfer schedule to the query string.
func (t *TransferScheduleParams) AppendDetails(values *url.Values) {
func (t *TransferScheduleParams) AppendDetails(values *RequestValues) {
if t.Delay > 0 {
values.Add("transfer_schedule[delay_days]", strconv.FormatUint(t.Delay, 10))
} else if t.MinimumDelay {
Expand All @@ -413,7 +412,7 @@ func (t *TransferScheduleParams) AppendDetails(values *url.Values) {
}

// AppendDetails adds the terms of service acceptance to the query string.
func (t *TOSAcceptanceParams) AppendDetails(values *url.Values) {
func (t *TOSAcceptanceParams) AppendDetails(values *RequestValues) {
if t.Date > 0 {
values.Add("tos_acceptance[date]", strconv.FormatInt(t.Date, 10))
}
Expand Down
28 changes: 13 additions & 15 deletions account/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package account

import (
"net/url"
"strconv"

stripe "github.com/stripe/stripe-go"
Expand All @@ -20,7 +19,7 @@ func New(params *stripe.AccountParams) (*stripe.Account, error) {
}

func writeAccountParams(
params *stripe.AccountParams, body *url.Values,
params *stripe.AccountParams, body *stripe.RequestValues,
) {
if len(params.Country) > 0 {
body.Add("country", params.Country)
Expand Down Expand Up @@ -96,10 +95,9 @@ func writeAccountParams(
}

func (c Client) New(params *stripe.AccountParams) (*stripe.Account, error) {
body := &url.Values{
"managed": {strconv.FormatBool(params.Managed)},
"debit_negative_balances": {strconv.FormatBool(params.DebitNegativeBal)},
}
body := &stripe.RequestValues{}
body.Add("managed", strconv.FormatBool(params.Managed))
body.Add("debit_negative_balances", strconv.FormatBool(params.DebitNegativeBal))

writeAccountParams(params, body)

Expand Down Expand Up @@ -133,12 +131,12 @@ func GetByID(id string, params *stripe.AccountParams) (*stripe.Account, error) {
}

func (c Client) GetByID(id string, params *stripe.AccountParams) (*stripe.Account, error) {
var body *url.Values
var body *stripe.RequestValues
var commonParams *stripe.Params

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

Expand All @@ -154,12 +152,12 @@ func Update(id string, params *stripe.AccountParams) (*stripe.Account, error) {
}

func (c Client) Update(id string, params *stripe.AccountParams) (*stripe.Account, error) {
var body *url.Values
var body *stripe.RequestValues
var commonParams *stripe.Params

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

writeAccountParams(params, body)

Expand Down Expand Up @@ -194,7 +192,7 @@ func Reject(id string, params *stripe.AccountRejectParams) (*stripe.Account, err
}

func (c Client) Reject(id string, params *stripe.AccountRejectParams) (*stripe.Account, error) {
body := &url.Values{}
body := &stripe.RequestValues{}
if len(params.Reason) > 0 {
body.Add("reason", params.Reason)
}
Expand All @@ -210,21 +208,21 @@ func List(params *stripe.AccountListParams) *Iter {
}

func (c Client) List(params *stripe.AccountListParams) *Iter {
var body *url.Values
var body *stripe.RequestValues
var lp *stripe.ListParams
var p *stripe.Params

if params != nil {
body = &url.Values{}
body = &stripe.RequestValues{}

params.AppendTo(body)
lp = &params.ListParams
p = params.ToParams()
}

return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) {
return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.AccountList{}
err := c.B.Call("GET", "/accounts", c.Key, &b, p, list)
err := c.B.Call("GET", "/accounts", c.Key, b, p, list)

ret := make([]interface{}, len(list.Values))
for i, v := range list.Values {
Expand Down
17 changes: 8 additions & 9 deletions balance/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package balance

import (
"net/url"
"strconv"

stripe "github.com/stripe/stripe-go"
Expand Down Expand Up @@ -35,12 +34,12 @@ func Get(params *stripe.BalanceParams) (*stripe.Balance, error) {
}

func (c Client) Get(params *stripe.BalanceParams) (*stripe.Balance, error) {
var body *url.Values
var body *stripe.RequestValues
var commonParams *stripe.Params

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

Expand All @@ -57,12 +56,12 @@ func GetTx(id string, params *stripe.TxParams) (*stripe.Transaction, error) {
}

func (c Client) GetTx(id string, params *stripe.TxParams) (*stripe.Transaction, error) {
var body *url.Values
var body *stripe.RequestValues
var commonParams *stripe.Params

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

Expand All @@ -79,12 +78,12 @@ func List(params *stripe.TxListParams) *Iter {
}

func (c Client) List(params *stripe.TxListParams) *Iter {
var body *url.Values
var body *stripe.RequestValues
var lp *stripe.ListParams
var p *stripe.Params

if params != nil {
body = &url.Values{}
body = &stripe.RequestValues{}

if params.Created > 0 {
body.Add("created", strconv.FormatInt(params.Created, 10))
Expand Down Expand Up @@ -115,9 +114,9 @@ func (c Client) List(params *stripe.TxListParams) *Iter {
p = params.ToParams()
}

return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) {
return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.TransactionList{}
err := c.B.Call("GET", "/balance/history", c.Key, &b, p, list)
err := c.B.Call("GET", "/balance/history", c.Key, b, p, list)

ret := make([]interface{}, len(list.Values))
for i, v := range list.Values {
Expand Down
3 changes: 1 addition & 2 deletions bankaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package stripe
import (
"encoding/json"
"fmt"
"net/url"
)

// BankAccountStatus is the list of allowed values for the bank account's status.
Expand Down Expand Up @@ -66,7 +65,7 @@ func (b *BankAccount) Display() string {
}

// AppendDetails adds the bank account's details to the query string values.
func (b *BankAccountParams) AppendDetails(values *url.Values) {
func (b *BankAccountParams) AppendDetails(values *RequestValues) {
values.Add("bank_account[country]", b.Country)
if len(b.Routing) > 0 {
values.Add("bank_account[routing_number]", b.Routing)
Expand Down
17 changes: 8 additions & 9 deletions bankaccount/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package bankaccount
import (
"errors"
"fmt"
"net/url"
"strconv"

stripe "github.com/stripe/stripe-go"
Expand All @@ -30,7 +29,7 @@ func New(params *stripe.BankAccountParams) (*stripe.BankAccount, error) {

func (c Client) New(params *stripe.BankAccountParams) (*stripe.BankAccount, error) {

body := &url.Values{}
body := &stripe.RequestValues{}

// Use token (if exists) or a dictionary containing a user’s bank account details.
if len(params.Token) > 0 {
Expand Down Expand Up @@ -67,12 +66,12 @@ func Get(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, erro
}

func (c Client) Get(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) {
var body *url.Values
var body *stripe.RequestValues
var commonParams *stripe.Params

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

Expand All @@ -88,12 +87,12 @@ func Update(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, e
}

func (c Client) Update(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) {
var body *url.Values
var body *stripe.RequestValues
var commonParams *stripe.Params

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

if params.Default {
body.Add("default_for_currency", strconv.FormatBool(params.Default))
Expand Down Expand Up @@ -134,17 +133,17 @@ func List(params *stripe.BankAccountListParams) *Iter {
}

func (c Client) List(params *stripe.BankAccountListParams) *Iter {
body := &url.Values{}
body := &stripe.RequestValues{}
var lp *stripe.ListParams
var p *stripe.Params

params.AppendTo(body)
lp = &params.ListParams
p = params.ToParams()

return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) {
return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.BankAccountList{}
err := c.B.Call("GET", fmt.Sprintf("/accounts/%v/bank_accounts", params.AccountID), c.Key, &b, p, list)
err := c.B.Call("GET", fmt.Sprintf("/accounts/%v/bank_accounts", params.AccountID), c.Key, b, p, list)

ret := make([]interface{}, len(list.Values))
for i, v := range list.Values {
Expand Down
18 changes: 8 additions & 10 deletions bitcoinreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bitcoinreceiver

import (
"fmt"
"net/url"
"strconv"

stripe "github.com/stripe/stripe-go"
Expand All @@ -22,10 +21,9 @@ func New(params *stripe.BitcoinReceiverParams) (*stripe.BitcoinReceiver, error)
}

func (c Client) New(params *stripe.BitcoinReceiverParams) (*stripe.BitcoinReceiver, error) {
body := &url.Values{
"amount": {strconv.FormatUint(params.Amount, 10)},
"currency": {string(params.Currency)},
}
body := &stripe.RequestValues{}
body.Add("amount", strconv.FormatUint(params.Amount, 10))
body.Add("currency", string(params.Currency))

if len(params.Desc) > 0 {
body.Add("description", params.Desc)
Expand Down Expand Up @@ -71,7 +69,7 @@ func Update(id string, params *stripe.BitcoinReceiverUpdateParams) (*stripe.Bitc
}

func (c Client) Update(id string, params *stripe.BitcoinReceiverUpdateParams) (*stripe.BitcoinReceiver, error) {
body := &url.Values{}
body := &stripe.RequestValues{}

if len(params.Desc) > 0 {
body.Add("description", params.Desc)
Expand Down Expand Up @@ -100,12 +98,12 @@ func List(params *stripe.BitcoinReceiverListParams) *Iter {
}

func (c Client) List(params *stripe.BitcoinReceiverListParams) *Iter {
var body *url.Values
var body *stripe.RequestValues
var lp *stripe.ListParams
var p *stripe.Params

if params != nil {
body = &url.Values{}
body = &stripe.RequestValues{}

body.Add("filled", strconv.FormatBool(!params.NotFilled))
body.Add("active", strconv.FormatBool(!params.NotActive))
Expand All @@ -116,9 +114,9 @@ func (c Client) List(params *stripe.BitcoinReceiverListParams) *Iter {
p = params.ToParams()
}

return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) {
return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.BitcoinReceiverList{}
err := c.B.Call("GET", "/bitcoin/receivers", c.Key, &b, p, list)
err := c.B.Call("GET", "/bitcoin/receivers", c.Key, b, p, list)

ret := make([]interface{}, len(list.Values))
for i, v := range list.Values {
Expand Down
9 changes: 4 additions & 5 deletions bitcointransaction/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bitcointransaction

import (
"fmt"
"net/url"

stripe "github.com/stripe/stripe-go"
)
Expand All @@ -21,12 +20,12 @@ func List(params *stripe.BitcoinTransactionListParams) *Iter {
}

func (c Client) List(params *stripe.BitcoinTransactionListParams) *Iter {
var body *url.Values
var body *stripe.RequestValues
var lp *stripe.ListParams
var p *stripe.Params

if params != nil {
body = &url.Values{}
body = &stripe.RequestValues{}

if len(params.Customer) > 0 {
body.Add("customer", params.Customer)
Expand All @@ -37,9 +36,9 @@ func (c Client) List(params *stripe.BitcoinTransactionListParams) *Iter {
p = params.ToParams()
}

return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) {
return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.BitcoinTransactionList{}
err := c.B.Call("GET", fmt.Sprintf("/bitcoin/receivers/%v/transactions", params.Receiver), c.Key, &b, p, list)
err := c.B.Call("GET", fmt.Sprintf("/bitcoin/receivers/%v/transactions", params.Receiver), c.Key, b, p, list)

ret := make([]interface{}, len(list.Values))
for i, v := range list.Values {
Expand Down
3 changes: 1 addition & 2 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"

"fmt"
"net/url"
)

// CardBrand is the list of allowed values for the card's brand.
Expand Down Expand Up @@ -95,7 +94,7 @@ type CardList struct {
// AppendDetails adds the card's details to the query string values.
// When creating a new card, the parameters are passed as a dictionary, but
// on updates they are simply the parameter name.
func (c *CardParams) AppendDetails(values *url.Values, creating bool) {
func (c *CardParams) AppendDetails(values *RequestValues, creating bool) {
if creating {
if len(c.Token) > 0 && len(c.Account) > 0 {
values.Add("external_account", c.Token)
Expand Down
Loading

0 comments on commit 9896155

Please sign in to comment.