diff --git a/card/client.go b/card/client.go index 5320a0ff4e..2472b52700 100644 --- a/card/client.go +++ b/card/client.go @@ -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 { + 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 { diff --git a/card/client_test.go b/card/client_test.go index aa03985adb..ec0b936ac7 100644 --- a/card/client_test.go +++ b/card/client_test.go @@ -16,6 +16,11 @@ func TestCardDel(t *testing.T) { assert.NotNil(t, card) } +func TestCardDel_RequiresParams(t *testing.T) { + _, err := Del("card_123", nil) + assert.Error(t, err, "params should not be nil") +} + func TestCardGet(t *testing.T) { card, err := Get("card_123", &stripe.CardParams{ Customer: "cus_123", @@ -24,7 +29,12 @@ func TestCardGet(t *testing.T) { assert.NotNil(t, card) } -func TestCardListByCustomer(t *testing.T) { +func TestCardGet_RequiresParams(t *testing.T) { + _, err := Get("card_123", nil) + assert.Error(t, err, "params should not be nil") +} + +func TestCardList_ByCustomer(t *testing.T) { i := List(&stripe.CardListParams{Customer: "cus_123"}) // Verify that we can get at least one card @@ -33,6 +43,12 @@ func TestCardListByCustomer(t *testing.T) { assert.NotNil(t, i.Card()) } +func TestCardList_RequiresParams(t *testing.T) { + i := List(nil) + assert.False(t, i.Next()) + assert.Error(t, i.Err(), "params should not be nil") +} + func TestCardNew(t *testing.T) { card, err := New(&stripe.CardParams{ Customer: "cus_123", @@ -42,6 +58,11 @@ func TestCardNew(t *testing.T) { assert.NotNil(t, card) } +func TestCardNew_RequiresParams(t *testing.T) { + _, err := New(nil) + assert.Error(t, err, "params should not be nil") +} + func TestCardUpdate(t *testing.T) { card, err := Update("card_123", &stripe.CardParams{ Customer: "cus_123", @@ -50,3 +71,8 @@ func TestCardUpdate(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, card) } + +func TestCardUpdate_RequiresParams(t *testing.T) { + _, err := Update("card_123", nil) + assert.Error(t, err, "params should not be nil") +}