From 4ce5af6510edf0832659b978394aa026bf8fda80 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 8 Oct 2019 15:13:49 -0400 Subject: [PATCH 1/8] orderreturn.Get --- orderreturn.go | 6 ++++++ orderreturn/client.go | 12 ++++++++++++ orderreturn/client_test.go | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/orderreturn.go b/orderreturn.go index 61aba4510d..da8a12292e 100644 --- a/orderreturn.go +++ b/orderreturn.go @@ -2,6 +2,12 @@ package stripe import "encoding/json" +// OrderReturnResourceParams is the set of parameters that can be used when retrieving a transaction. +// It is not to be confused with OrderReturnParams, which is used to return an order. +type OrderReturnResourceParams struct { + Params `form:"*"` +} + // OrderReturn is the resource representing an order return. // For more details see https://stripe.com/docs/api#order_returns. type OrderReturn struct { diff --git a/orderreturn/client.go b/orderreturn/client.go index b6c13f852a..bac85a8fa0 100644 --- a/orderreturn/client.go +++ b/orderreturn/client.go @@ -13,6 +13,18 @@ type Client struct { Key string } +// Get returns the details of an order return +func Get(id string, params *stripe.OrderReturnResourceParams) (*stripe.OrderReturn, error) { + return getC().Get(id, params) +} + +func (c Client) Get(id string, params *stripe.OrderReturnResourceParams) (*stripe.OrderReturn, error) { + path := stripe.FormatURLPath("/v1/order_returns/%s", id) + orderreturn := &stripe.OrderReturn{} + err := c.B.Call(http.MethodGet, path, c.Key, params, orderreturn) + return orderreturn, err +} + // List returns a list of order returns. func List(params *stripe.OrderReturnListParams) *Iter { return getC().List(params) diff --git a/orderreturn/client_test.go b/orderreturn/client_test.go index 7ef8151f32..ba3cf40a6b 100644 --- a/orderreturn/client_test.go +++ b/orderreturn/client_test.go @@ -8,6 +8,14 @@ import ( _ "github.com/stripe/stripe-go/testing" ) +func TestOrderReturnGet(t *testing.T) { + orret, err := Get("orret_123", &stripe.OrderReturnResourceParams{}) + + // Verify that we can get at least one order return + assert.Nil(t, err) + assert.NotNil(t, orret) +} + func TestOrderReturnList(t *testing.T) { i := List(&stripe.OrderReturnListParams{}) From 5ff96528c841bc7adf54e90bdfb804574da0234a Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 8 Oct 2019 15:25:00 -0400 Subject: [PATCH 2/8] Missing comment --- orderreturn/client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/orderreturn/client.go b/orderreturn/client.go index bac85a8fa0..268f3d752a 100644 --- a/orderreturn/client.go +++ b/orderreturn/client.go @@ -18,6 +18,7 @@ func Get(id string, params *stripe.OrderReturnResourceParams) (*stripe.OrderRetu return getC().Get(id, params) } +// Get returns the details of an order return func (c Client) Get(id string, params *stripe.OrderReturnResourceParams) (*stripe.OrderReturn, error) { path := stripe.FormatURLPath("/v1/order_returns/%s", id) orderreturn := &stripe.OrderReturn{} From 4bd80d5acc1c7ada82ce72b5af0e5da4b693a663 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 8 Oct 2019 16:47:24 -0400 Subject: [PATCH 3/8] OrderReturnParams pkg, order -> orderreturn --- order.go | 6 ------ order/client.go | 11 +++++++---- orderreturn.go | 9 +++++---- orderreturn/client.go | 33 ++++++++++++++++++++++++++------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/order.go b/order.go index e0a62c963d..b4cddc80bb 100644 --- a/order.go +++ b/order.go @@ -91,12 +91,6 @@ type OrderUpdateShippingParams struct { TrackingNumber *string `form:"tracking_number"` } -// OrderReturnParams is the set of parameters that can be used when returning orders. -type OrderReturnParams struct { - Params `form:"*"` - Items []*OrderItemParams `form:"items"` -} - // Shipping describes the shipping hash on an order. type Shipping struct { Address *Address `json:"address"` diff --git a/order/client.go b/order/client.go index 12d8224173..a0f9f6cf96 100644 --- a/order/client.go +++ b/order/client.go @@ -5,6 +5,7 @@ import ( stripe "github.com/stripe/stripe-go" "github.com/stripe/stripe-go/form" + orderreturn "github.com/stripe/stripe-go/orderreturn" ) // Client is used to invoke /orders APIs. @@ -91,10 +92,12 @@ func Return(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, e // Return returns all or part of an order. func (c Client) Return(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { - path := stripe.FormatURLPath("/v1/orders/%s/returns", id) - ret := &stripe.OrderReturn{} - err := c.B.Call(http.MethodPost, path, c.Key, params, ret) - return ret, err + if params == nil { + params = &stripe.OrderReturnParams{ + Order: &id, + } + } + return orderreturn.New(params) } // Iter is an iterator for orders. diff --git a/orderreturn.go b/orderreturn.go index da8a12292e..ee35cd98b9 100644 --- a/orderreturn.go +++ b/orderreturn.go @@ -2,10 +2,11 @@ package stripe import "encoding/json" -// OrderReturnResourceParams is the set of parameters that can be used when retrieving a transaction. -// It is not to be confused with OrderReturnParams, which is used to return an order. -type OrderReturnResourceParams struct { - Params `form:"*"` +// OrderReturnParams is the set of parameters that can be used when returning orders. +type OrderReturnParams struct { + Params `form:"*"` + Items []*OrderItemParams `form:"items"` + Order *string `form:"-"` // Included in the URL } // OrderReturn is the resource representing an order return. diff --git a/orderreturn/client.go b/orderreturn/client.go index 268f3d752a..5c54349490 100644 --- a/orderreturn/client.go +++ b/orderreturn/client.go @@ -1,6 +1,7 @@ package orderreturn import ( + "fmt" "net/http" stripe "github.com/stripe/stripe-go" @@ -13,17 +14,35 @@ type Client struct { Key string } +// New creates a new order return. +func New(params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { + return getC().New(params) +} + +// New creates a new order return. +func (c Client) New(params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { + if params == nil { + return nil, fmt.Errorf("params cannot be nil") + } + if params.Order == nil { + return nil, fmt.Errorf("params.Order must be set") + } + p := &stripe.OrderReturn{} + err := c.B.Call(http.MethodPost, "/v1/order_returns", c.Key, params, p) + return p, err +} + // Get returns the details of an order return -func Get(id string, params *stripe.OrderReturnResourceParams) (*stripe.OrderReturn, error) { - return getC().Get(id, params) +func Get(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { + return getC().Get(id, params) } // Get returns the details of an order return -func (c Client) Get(id string, params *stripe.OrderReturnResourceParams) (*stripe.OrderReturn, error) { - path := stripe.FormatURLPath("/v1/order_returns/%s", id) - orderreturn := &stripe.OrderReturn{} - err := c.B.Call(http.MethodGet, path, c.Key, params, orderreturn) - return orderreturn, err +func (c Client) Get(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { + path := stripe.FormatURLPath("/v1/order_returns/%s", id) + orderreturn := &stripe.OrderReturn{} + err := c.B.Call(http.MethodGet, path, c.Key, params, orderreturn) + return orderreturn, err } // List returns a list of order returns. From 5fdea6e6f01e011385e43b29daab2a87c6e63cf0 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 8 Oct 2019 17:10:48 -0400 Subject: [PATCH 4/8] <3 golang --- order/client.go | 11 ++++++----- order/client_test.go | 2 +- orderreturn/client.go | 3 ++- orderreturn/client_test.go | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/order/client.go b/order/client.go index a0f9f6cf96..71abd0b234 100644 --- a/order/client.go +++ b/order/client.go @@ -92,12 +92,13 @@ func Return(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, e // Return returns all or part of an order. func (c Client) Return(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { - if params == nil { - params = &stripe.OrderReturnParams{ - Order: &id, - } + returnParams := params + if returnParams == nil { + returnParams = &stripe.OrderReturnParams{} } - return orderreturn.New(params) + returnParams.Order = &id + + return orderreturn.Client{B: c.B, Key: c.Key}.New(returnParams) } // Iter is an iterator for orders. diff --git a/order/client_test.go b/order/client_test.go index 78e4567114..617e85873d 100644 --- a/order/client_test.go +++ b/order/client_test.go @@ -74,7 +74,7 @@ func TestOrderReturn_RequestParams(t *testing.T) { order, err := orderClient.Return("or_123", p) assert.Nil(t, err) assert.NotNil(t, order) - + fmt.Print(lastRequest) assert.Equal(t, lastRequest.Header.Get("Stripe-Account"), "acct_123") } diff --git a/orderreturn/client.go b/orderreturn/client.go index 5c54349490..fd9639b977 100644 --- a/orderreturn/client.go +++ b/orderreturn/client.go @@ -28,7 +28,8 @@ func (c Client) New(params *stripe.OrderReturnParams) (*stripe.OrderReturn, erro return nil, fmt.Errorf("params.Order must be set") } p := &stripe.OrderReturn{} - err := c.B.Call(http.MethodPost, "/v1/order_returns", c.Key, params, p) + path := stripe.FormatURLPath("/v1/orders/%s/returns", stripe.StringValue(params.Order)) + err := c.B.Call(http.MethodPost, path, c.Key, params, p) return p, err } diff --git a/orderreturn/client_test.go b/orderreturn/client_test.go index ba3cf40a6b..71a957c798 100644 --- a/orderreturn/client_test.go +++ b/orderreturn/client_test.go @@ -8,12 +8,22 @@ import ( _ "github.com/stripe/stripe-go/testing" ) +func TestOrderReturnNew(t *testing.T) { + orret, err := New(&stripe.OrderReturnParams{ + Order: stripe.String("or_123"), + }) + + // Verify that we can create an order return + assert.Nil(t, err) + assert.NotNil(t, orret) +} + func TestOrderReturnGet(t *testing.T) { - orret, err := Get("orret_123", &stripe.OrderReturnResourceParams{}) + orret, err := Get("orret_123", &stripe.OrderReturnParams{}) - // Verify that we can get at least one order return - assert.Nil(t, err) - assert.NotNil(t, orret) + // Verify that we can get an order return + assert.Nil(t, err) + assert.NotNil(t, orret) } func TestOrderReturnList(t *testing.T) { From 95390d67d045c4e005af13277fce92ef79b53c3b Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 8 Oct 2019 17:11:47 -0400 Subject: [PATCH 5/8] gofmt --- order/client.go | 2 +- order/client_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/order/client.go b/order/client.go index 71abd0b234..b445cd731f 100644 --- a/order/client.go +++ b/order/client.go @@ -98,7 +98,7 @@ func (c Client) Return(id string, params *stripe.OrderReturnParams) (*stripe.Ord } returnParams.Order = &id - return orderreturn.Client{B: c.B, Key: c.Key}.New(returnParams) + return orderreturn.Client{B: c.B, Key: c.Key}.New(returnParams) } // Iter is an iterator for orders. diff --git a/order/client_test.go b/order/client_test.go index 617e85873d..59cd7de674 100644 --- a/order/client_test.go +++ b/order/client_test.go @@ -74,7 +74,7 @@ func TestOrderReturn_RequestParams(t *testing.T) { order, err := orderClient.Return("or_123", p) assert.Nil(t, err) assert.NotNil(t, order) - fmt.Print(lastRequest) + fmt.Print(lastRequest) assert.Equal(t, lastRequest.Header.Get("Stripe-Account"), "acct_123") } From 694a76306f81bce97c6b8a0b8d8a41f5bbd33eb1 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 8 Oct 2019 17:12:20 -0400 Subject: [PATCH 6/8] Remove extraneous print --- order/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/order/client_test.go b/order/client_test.go index 59cd7de674..78e4567114 100644 --- a/order/client_test.go +++ b/order/client_test.go @@ -74,7 +74,7 @@ func TestOrderReturn_RequestParams(t *testing.T) { order, err := orderClient.Return("or_123", p) assert.Nil(t, err) assert.NotNil(t, order) - fmt.Print(lastRequest) + assert.Equal(t, lastRequest.Header.Get("Stripe-Account"), "acct_123") } From 266bd05048dba46a2d307e5ac867ae7640e41ff4 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 8 Oct 2019 17:14:57 -0400 Subject: [PATCH 7/8] CamelCase is HorseCase designed by committee --- orderreturn/client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/orderreturn/client.go b/orderreturn/client.go index fd9639b977..8467b34a2e 100644 --- a/orderreturn/client.go +++ b/orderreturn/client.go @@ -41,9 +41,9 @@ func Get(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, erro // Get returns the details of an order return func (c Client) Get(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { path := stripe.FormatURLPath("/v1/order_returns/%s", id) - orderreturn := &stripe.OrderReturn{} - err := c.B.Call(http.MethodGet, path, c.Key, params, orderreturn) - return orderreturn, err + orderReturn := &stripe.OrderReturn{} + err := c.B.Call(http.MethodGet, path, c.Key, params, orderReturn) + return orderReturn, err } // List returns a list of order returns. From 5e1bc004d9bc6c99850e3a6965fffe7e4c8ba723 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 8 Oct 2019 17:37:53 -0400 Subject: [PATCH 8/8] Don't add a .New method --- order/client.go | 12 ++++-------- orderreturn/client.go | 20 -------------------- orderreturn/client_test.go | 10 ---------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/order/client.go b/order/client.go index b445cd731f..12d8224173 100644 --- a/order/client.go +++ b/order/client.go @@ -5,7 +5,6 @@ import ( stripe "github.com/stripe/stripe-go" "github.com/stripe/stripe-go/form" - orderreturn "github.com/stripe/stripe-go/orderreturn" ) // Client is used to invoke /orders APIs. @@ -92,13 +91,10 @@ func Return(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, e // Return returns all or part of an order. func (c Client) Return(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { - returnParams := params - if returnParams == nil { - returnParams = &stripe.OrderReturnParams{} - } - returnParams.Order = &id - - return orderreturn.Client{B: c.B, Key: c.Key}.New(returnParams) + path := stripe.FormatURLPath("/v1/orders/%s/returns", id) + ret := &stripe.OrderReturn{} + err := c.B.Call(http.MethodPost, path, c.Key, params, ret) + return ret, err } // Iter is an iterator for orders. diff --git a/orderreturn/client.go b/orderreturn/client.go index 8467b34a2e..e57bf69723 100644 --- a/orderreturn/client.go +++ b/orderreturn/client.go @@ -1,7 +1,6 @@ package orderreturn import ( - "fmt" "net/http" stripe "github.com/stripe/stripe-go" @@ -14,25 +13,6 @@ type Client struct { Key string } -// New creates a new order return. -func New(params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { - return getC().New(params) -} - -// New creates a new order return. -func (c Client) New(params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { - if params == nil { - return nil, fmt.Errorf("params cannot be nil") - } - if params.Order == nil { - return nil, fmt.Errorf("params.Order must be set") - } - p := &stripe.OrderReturn{} - path := stripe.FormatURLPath("/v1/orders/%s/returns", stripe.StringValue(params.Order)) - err := c.B.Call(http.MethodPost, path, c.Key, params, p) - return p, err -} - // Get returns the details of an order return func Get(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) { return getC().Get(id, params) diff --git a/orderreturn/client_test.go b/orderreturn/client_test.go index 71a957c798..c65d72a72f 100644 --- a/orderreturn/client_test.go +++ b/orderreturn/client_test.go @@ -8,16 +8,6 @@ import ( _ "github.com/stripe/stripe-go/testing" ) -func TestOrderReturnNew(t *testing.T) { - orret, err := New(&stripe.OrderReturnParams{ - Order: stripe.String("or_123"), - }) - - // Verify that we can create an order return - assert.Nil(t, err) - assert.NotNil(t, orret) -} - func TestOrderReturnGet(t *testing.T) { orret, err := Get("orret_123", &stripe.OrderReturnParams{})