Skip to content
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

Add support for the Payout Reverse API #1208

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.101.0

go:
- "1.10.x"
Expand Down
7 changes: 7 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 All @@ -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"`
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.101.0"

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