Repository: stripe/stripe-node
Pull request #608 (2019-05-04 05:49:55)

Add support for Customer Balance Transaction resource and APIs
r? @ob-stripe 
cc @stripe/api-libraries 

remi-stripe: @ob-stripe PTAL
remi-stripe: PTAL @ob-stripe since I rebased on latest master and re-did the PR
remi-stripe: @ob-stripe fixed, PTAL

Patch:
diff --git a/lib/resources/Customers.js b/lib/resources/Customers.js
index 2c23989e..cc73e5e9 100644
--- a/lib/resources/Customers.js
+++ b/lib/resources/Customers.js
@@ -64,4 +64,25 @@ module.exports = StripeResource.extend({
     method: 'GET',
     path: '/{customer}/tax_ids/{id}',
   }),
+
+  createBalanceTransaction: stripeMethod({
+    method: 'POST',
+    path: '/{customer}/balance_transactions',
+  }),
+
+  listBalanceTransactions: stripeMethod({
+    method: 'GET',
+    path: '/{customer}/balance_transactions',
+    methodType: 'list',
+  }),
+
+  retrieveBalanceTransaction: stripeMethod({
+    method: 'GET',
+    path: '/{customer}/balance_transactions/{id}',
+  }),
+
+  updateBalanceTransaction: stripeMethod({
+    method: 'POST',
+    path: '/{customer}/balance_transactions/{id}',
+  }),
 });


Test patch:
diff --git a/test/resources/Customers.spec.js b/test/resources/Customers.spec.js
index 57881bb7..ccf00123 100644
--- a/test/resources/Customers.spec.js
+++ b/test/resources/Customers.spec.js
@@ -371,4 +371,59 @@ describe('Customers Resource', () => {
       });
     });
   });
+
+  describe('BalanceTransaction methods', () => {
+    describe('retrieveBalanceTransaction', () => {
+      it('Sends the correct request', () => {
+        stripe.customers.retrieveBalanceTransaction('cus_123', 'cbtxn_123');
+        expect(stripe.LAST_REQUEST).to.deep.equal({
+          method: 'GET',
+          url: '/v1/customers/cus_123/balance_transactions/cbtxn_123',
+          headers: {},
+          data: {},
+        });
+      });
+    });
+
+    describe('createBalanceTransaction', () => {
+      it('Sends the correct request', () => {
+        stripe.customers.createBalanceTransaction('cus_123', {
+          amount: 123,
+          currency: 'usd',
+        });
+        expect(stripe.LAST_REQUEST).to.deep.equal({
+          method: 'POST',
+          url: '/v1/customers/cus_123/balance_transactions',
+          headers: {},
+          data: {amount: 123, currency: 'usd'},
+        });
+      });
+    });
+
+    describe('updateBalanceTransaction', () => {
+      it('Sends the correct request', () => {
+        stripe.customers.updateBalanceTransaction('cus_123', 'cbtxn_123', {
+          description: 'description',
+        });
+        expect(stripe.LAST_REQUEST).to.deep.equal({
+          method: 'POST',
+          url: '/v1/customers/cus_123/balance_transactions/cbtxn_123',
+          headers: {},
+          data: {description: 'description'},
+        });
+      });
+    });
+
+    describe('listBalanceTransactions', () => {
+      it('Sends the correct request', () => {
+        stripe.customers.listBalanceTransactions('cus_123');
+        expect(stripe.LAST_REQUEST).to.deep.equal({
+          method: 'GET',
+          url: '/v1/customers/cus_123/balance_transactions',
+          headers: {},
+          data: {},
+        });
+      });
+    });
+  });
 });