From e4d13c33758b83c054c56a9cf5e2efd5a1147470 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Mon, 12 Oct 2020 21:33:53 -0700 Subject: [PATCH] Add support for the Payout Reverse API --- .travis.yml | 2 +- payout.go | 7 +++++++ payout/client.go | 13 +++++++++++++ payout/client_test.go | 15 ++++++++++++--- testing/testing.go | 2 +- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d6c235a91..16891db3f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,7 +44,7 @@ cache: env: global: # If changing this number, please also change it in `testing/testing.go`. - - STRIPE_MOCK_VERSION=0.99.0 + - STRIPE_MOCK_VERSION=0.101.0 go: - "1.10.x" diff --git a/payout.go b/payout.go index cba1f6b605..81caceb8a3 100644 --- a/payout.go +++ b/payout.go @@ -103,6 +103,11 @@ type PayoutListParams struct { Status *string `form:"status"` } +// PayoutReverseParams is the set of parameters that can be used when reversing a payout. +type PayoutReverseParams struct { + Params `form:"*"` +} + // Payout is the resource representing a Stripe payout. // For more details see https://stripe.com/docs/api#payouts. type Payout struct { @@ -124,6 +129,8 @@ type Payout struct { Livemode bool `json:"livemode"` Metadata map[string]string `json:"metadata"` Method PayoutMethodType `json:"method"` + OriginalPayout *Payout `json:"original_payout"` + ReversedBy *Payout `json:"reversed_by"` SourceType PayoutSourceType `json:"source_type"` StatementDescriptor string `json:"statement_descriptor"` Status PayoutStatus `json:"status"` diff --git a/payout/client.go b/payout/client.go index ccfcbb62dc..cbf10e56ed 100644 --- a/payout/client.go +++ b/payout/client.go @@ -65,6 +65,19 @@ func (c Client) Cancel(id string, params *stripe.PayoutParams) (*stripe.Payout, return payout, err } +// Reverse reverses a pending payout. +func Reverse(id string, params *stripe.PayoutReverseParams) (*stripe.Payout, error) { + return getC().Reverse(id, params) +} + +// Reverse reverses a pending payout. +func (c Client) Reverse(id string, params *stripe.PayoutReverseParams) (*stripe.Payout, error) { + path := stripe.FormatURLPath("/v1/payouts/%s/reverse", id) + payout := &stripe.Payout{} + err := c.B.Call(http.MethodPost, path, c.Key, params, payout) + return payout, err +} + // List returns a list of payouts. func List(params *stripe.PayoutListParams) *Iter { return getC().List(params) diff --git a/payout/client_test.go b/payout/client_test.go index baea875ae8..850f539064 100644 --- a/payout/client_test.go +++ b/payout/client_test.go @@ -21,7 +21,8 @@ func TestPayoutGet(t *testing.T) { } func TestPayoutList(t *testing.T) { - i := List(&stripe.PayoutListParams{}) + params := &stripe.PayoutListParams{} + i := List(params) // Verify that we can get at least one payout assert.True(t, i.Next()) @@ -39,14 +40,22 @@ func TestPayoutNew(t *testing.T) { assert.NotNil(t, payout) } +func TestPayoutReverse(t *testing.T) { + params := &stripe.PayoutReverseParams{} + payout, err := Reverse("po_123", params) + assert.Nil(t, err) + assert.NotNil(t, payout) +} + func TestPayoutUpdate(t *testing.T) { - payout, err := Update("tr_123", &stripe.PayoutParams{ + params := &stripe.PayoutParams{ Params: stripe.Params{ Metadata: map[string]string{ "foo": "bar", }, }, - }) + } + payout, err := Update("po_123", params) assert.Nil(t, err) assert.NotNil(t, payout) } diff --git a/testing/testing.go b/testing/testing.go index 155f868139..bd10451ccc 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -25,7 +25,7 @@ const ( // added in a more recent version of stripe-mock, we can show people a // better error message instead of the test suite crashing with a bunch of // confusing 404 errors or the like. - MockMinimumVersion = "0.99.0" + MockMinimumVersion = "0.101.0" // TestMerchantID is a token that can be used to represent a merchant ID in // simple tests.