-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error early when params not specified for card functions #484
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,10 @@ func New(params *stripe.CardParams) (*stripe.Card, error) { | |
} | ||
|
||
func (c Client) New(params *stripe.CardParams) (*stripe.Card, error) { | ||
if params == nil { | ||
return nil, errors.New("params should not be nil") | ||
} | ||
|
||
body := &form.Values{} | ||
|
||
// Note that we call this special append method instead of the standard one | ||
|
@@ -71,6 +75,10 @@ func Get(id string, params *stripe.CardParams) (*stripe.Card, error) { | |
} | ||
|
||
func (c Client) Get(id string, params *stripe.CardParams) (*stripe.Card, error) { | ||
if params == nil { | ||
return nil, errors.New("params should not be nil") | ||
} | ||
|
||
var body *form.Values | ||
var commonParams *stripe.Params | ||
|
||
|
@@ -103,6 +111,10 @@ func Update(id string, params *stripe.CardParams) (*stripe.Card, error) { | |
} | ||
|
||
func (c Client) Update(id string, params *stripe.CardParams) (*stripe.Card, error) { | ||
if params == nil { | ||
return nil, errors.New("params should not be nil") | ||
} | ||
|
||
body := &form.Values{} | ||
form.AppendTo(body, params) | ||
|
||
|
@@ -129,15 +141,16 @@ func Del(id string, params *stripe.CardParams) (*stripe.Card, error) { | |
} | ||
|
||
func (c Client) Del(id string, params *stripe.CardParams) (*stripe.Card, error) { | ||
if params == nil { | ||
return nil, errors.New("params should not be nil") | ||
} | ||
|
||
var body *form.Values | ||
var commonParams *stripe.Params | ||
|
||
if params != nil { | ||
body = &form.Values{} | ||
|
||
form.AppendTo(body, params) | ||
commonParams = ¶ms.Params | ||
} | ||
body = &form.Values{} | ||
form.AppendTo(body, params) | ||
commonParams = ¶ms.Params | ||
|
||
card := &stripe.Card{} | ||
var err error | ||
|
@@ -166,14 +179,20 @@ func (c Client) List(params *stripe.CardListParams) *Iter { | |
var lp *stripe.ListParams | ||
var p *stripe.Params | ||
|
||
form.AppendTo(body, params) | ||
lp = ¶ms.ListParams | ||
p = params.ToParams() | ||
if params != nil { | ||
form.AppendTo(body, params) | ||
lp = ¶ms.ListParams | ||
p = params.ToParams() | ||
} | ||
|
||
return &Iter{stripe.GetIter(lp, body, func(b *form.Values) ([]interface{}, stripe.ListMeta, error) { | ||
list := &stripe.CardList{} | ||
var err error | ||
|
||
if params == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just error above like you do in the other functions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, basically because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah gotcha, that makes sense, thanks for clarifying! |
||
return nil, list.ListMeta, errors.New("params should not be nil") | ||
} | ||
|
||
if len(params.Account) > 0 { | ||
err = c.B.Call("GET", fmt.Sprintf("/accounts/%v/external_accounts", params.Account), c.Key, b, p, list) | ||
} else if len(params.Customer) > 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're already doing
if params != nil {
below (not visible) so it's redundant. Should you fix the one below in that case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point. Unfortunately the other one would still result in a panic because of the check on
params.Account
immediately afterwards, so I've taken that one out in favor of my addition.