Repository: stripe/stripe-node
Pull request #1042 (2020-10-14 02:29:06)

Add support for the Payout Reverse API
Codegen for openapi 4bd4c01

r? @richardm-stripe 
cc @stripe/api-libraries 


Patch:
diff --git a/lib/resources/Payouts.js b/lib/resources/Payouts.js
index 3c2ad0df..49522266 100644
--- a/lib/resources/Payouts.js
+++ b/lib/resources/Payouts.js
@@ -14,4 +14,9 @@ module.exports = StripeResource.extend({
     method: 'POST',
     path: '/{payout}/cancel',
   }),
+
+  reverse: stripeMethod({
+    method: 'POST',
+    path: '/{payout}/reverse',
+  }),
 });
diff --git a/types/2020-08-27/Payouts.d.ts b/types/2020-08-27/Payouts.d.ts
index 6e76f44c..2afc23b3 100644
--- a/types/2020-08-27/Payouts.d.ts
+++ b/types/2020-08-27/Payouts.d.ts
@@ -91,6 +91,16 @@ declare module 'stripe' {
        */
       method: string;
 
+      /**
+       * If the payout reverses another, this is the ID of the original payout.
+       */
+      original_payout?: string | Stripe.Payout | null;
+
+      /**
+       * If the payout was reversed, this is the ID of the payout that reverses this payout.
+       */
+      reversed_by?: string | Stripe.Payout | null;
+
       /**
        * The source balance this payout came from. One of `card`, `fpx`, or `bank_account`.
        */
@@ -216,6 +226,18 @@ declare module 'stripe' {
       expand?: Array<string>;
     }
 
+    interface PayoutReverseParams {
+      /**
+       * Specifies which fields in the response should be expanded.
+       */
+      expand?: Array<string>;
+
+      /**
+       * Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
+       */
+      metadata?: MetadataParam;
+    }
+
     class PayoutsResource {
       /**
        * To send funds to your own bank account, you create a new payout object. Your [Stripe balance](https://stripe.com/docs/api#balance) must be able to cover the payout amount, or you'll receive an “Insufficient Funds” error.
@@ -272,6 +294,21 @@ declare module 'stripe' {
         id: string,
         options?: RequestOptions
       ): Promise<Stripe.Response<Stripe.Payout>>;
+
+      /**
+       * Reverses a payout by debiting the destination bank account. Only payouts for connected accounts to US bank accounts may be reversed at this time. If the payout is in the pending status, /v1/payouts/:id/cancel should be used instead.
+       *
+       * By requesting a reversal via /v1/payouts/:id/reverse, you confirm that the authorized signatory of the selected bank account has authorized the debit on the bank account and that no other authorization is required.
+       */
+      reverse(
+        id: string,
+        params?: PayoutReverseParams,
+        options?: RequestOptions
+      ): Promise<Stripe.Response<Stripe.Payout>>;
+      reverse(
+        id: string,
+        options?: RequestOptions
+      ): Promise<Stripe.Response<Stripe.Payout>>;
     }
   }
 }


Test patch:
diff --git a/test/resources/Payouts.spec.js b/test/resources/Payouts.spec.js
index 76fbd914..62a16908 100644
--- a/test/resources/Payouts.spec.js
+++ b/test/resources/Payouts.spec.js
@@ -75,4 +75,17 @@ describe('Payouts Resource', () => {
       });
     });
   });
+
+  describe('reverse', () => {
+    it('Sends the correct request', () => {
+      stripe.payouts.reverse(PAYOUT_TEST_ID);
+      expect(stripe.LAST_REQUEST).to.deep.equal({
+        method: 'POST',
+        url: `/v1/payouts/${PAYOUT_TEST_ID}/reverse`,
+        headers: {},
+        data: {},
+        settings: {},
+      });
+    });
+  });
 });