Skip to content

Commit

Permalink
Add support for the Payout Reverse API
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Oct 13, 2020
1 parent 6663aaf commit 9da042b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.100.0

go:
- "1.10.x"
Expand Down
5 changes: 5 additions & 0 deletions payout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions payout/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions payout/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.100.0"

// TestMerchantID is a token that can be used to represent a merchant ID in
// simple tests.
Expand Down

0 comments on commit 9da042b

Please sign in to comment.