Skip to content

Commit

Permalink
Add new methods for the Invoice resource
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Oct 14, 2018
1 parent 278b07d commit 218d5f9
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 27 deletions.
31 changes: 27 additions & 4 deletions lib/resources/Invoices.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ var utils = require('../utils');
module.exports = StripeResource.extend({

path: 'invoices',
includeBasic: ['create', 'list', 'retrieve', 'update'],
includeBasic: ['create', 'list', 'retrieve', 'update', 'del'],

retrieveLines: stripeMethod({
method: 'GET',
path: '{invoiceId}/lines',
finalize: stripeMethod({
method: 'POST',
path: '{invoiceId}/finalize',
urlParams: ['invoiceId'],
}),

markUncollectible: stripeMethod({
method: 'POST',
path: '{invoiceId}/mark_uncollectible',
urlParams: ['invoiceId'],
}),

Expand All @@ -21,6 +27,12 @@ module.exports = StripeResource.extend({
urlParams: ['invoiceId'],
}),

retrieveLines: stripeMethod({
method: 'GET',
path: '{invoiceId}/lines',
urlParams: ['invoiceId'],
}),

retrieveUpcoming: stripeMethod({
method: 'GET',
path: function(urlData) {
Expand All @@ -40,4 +52,15 @@ module.exports = StripeResource.extend({
encode: utils.encodeParamWithIntegerIndexes.bind(null, 'subscription_items'),
}),

send: stripeMethod({
method: 'POST',
path: '{invoiceId}/send',
urlParams: ['invoiceId'],
}),

void: stripeMethod({
method: 'POST',
path: '{invoiceId}/void',
urlParams: ['invoiceId'],
}),
});
107 changes: 84 additions & 23 deletions test/resources/Invoices.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ var expect = require('chai').expect;
describe('Invoices Resource', function() {
describe('retrieve', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieve('invoiceId1');
stripe.invoices.retrieve('in_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/invoiceId1',
url: '/v1/invoices/in_123',
headers: {},
data: {},
});
Expand All @@ -28,24 +28,48 @@ describe('Invoices Resource', function() {
});
});

describe('list', function() {
it('Sends the correct request', function() {
stripe.invoices.list({count: 25});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices',
headers: {},
data: {count: 25},
});
});
});

describe('update', function() {
it('Sends the correct request', function() {
stripe.invoices.update('invoiceId1', {application_fee: 200});
stripe.invoices.update('in_123', {application_fee: 200});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/invoices/invoiceId1',
url: '/v1/invoices/in_123',
headers: {},
data: {application_fee: 200},
});
});
});

describe('del', function() {
it('Sends the correct request', function() {
stripe.invoices.del('in_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'DELETE',
url: '/v1/invoices/in_123',
headers: {},
data: {},
});
});
});

describe('retrieveLines', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieveLines('invoiceId2');
stripe.invoices.retrieveLines('in_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/invoiceId2/lines',
url: '/v1/invoices/in_123/lines',
headers: {},
data: {},
});
Expand All @@ -55,10 +79,10 @@ describe('Invoices Resource', function() {
describe('retrieveUpcoming', function() {
describe('With just a customer ID', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieveUpcoming('customerId1');
stripe.invoices.retrieveUpcoming('cus_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/upcoming?customer=customerId1',
url: '/v1/invoices/upcoming?customer=cus_123',
headers: {},
data: {},
});
Expand All @@ -67,10 +91,10 @@ describe('Invoices Resource', function() {

describe('With a subscription ID in addition to a customer ID', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieveUpcoming('customerId1', 'subscriptionId123');
stripe.invoices.retrieveUpcoming('cus_123', 'sub_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/upcoming?customer=customerId1&subscription=subscriptionId123',
url: '/v1/invoices/upcoming?customer=cus_123&subscription=sub_123',
headers: {},
data: {},
});
Expand All @@ -79,7 +103,7 @@ describe('Invoices Resource', function() {

describe('With an options object that includes `subscription_items`', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieveUpcoming('customerId1', {
stripe.invoices.retrieveUpcoming('cus_123', {
subscription_items: [
{plan: 'potato'},
{plan: 'rutabaga'},
Expand All @@ -88,7 +112,7 @@ describe('Invoices Resource', function() {

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/upcoming?customer=customerId1&' +
url: '/v1/invoices/upcoming?customer=cus_123&' +
'subscription_items%5B0%5D%5Bplan%5D=potato&subscription_items%5B1%5D%5Bplan%5D=rutabaga',
headers: {},
data: {},
Expand All @@ -98,7 +122,7 @@ describe('Invoices Resource', function() {

describe('With an options object that includes `subscription_items` in addition to a subscription ID', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieveUpcoming('customerId1', 'subscriptionID1',
stripe.invoices.retrieveUpcoming('cus_123', 'sub_123',
{
subscription_items: [
{plan: 'potato'},
Expand All @@ -110,7 +134,7 @@ describe('Invoices Resource', function() {

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/upcoming?customer=customerId1&subscription=subscriptionID1',
url: '/v1/invoices/upcoming?customer=cus_123&subscription=sub_123',
headers: {},
data: {
subscription_items: {
Expand All @@ -133,39 +157,76 @@ describe('Invoices Resource', function() {

describe('With a options object in addition to a customer ID', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieveUpcoming('customerId1', {plan: 'planId123'});
stripe.invoices.retrieveUpcoming('cus_123', {plan: 'planId123'});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/upcoming?customer=customerId1&plan=planId123',
url: '/v1/invoices/upcoming?customer=cus_123&plan=planId123',
headers: {},
data: {},
});
});
});
});

describe('finalize', function() {
it('Sends the correct request', function() {
stripe.invoices.finalize('in_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/invoices/in_123/finalize',
headers: {},
data: {}
});
});
});

describe('mark uncollectible', function() {
it('Sends the correct request', function() {
stripe.invoices.markUncollectible('in_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/invoices/in_123/mark_uncollectible',
headers: {},
data: {}
});
});
});


describe('pay', function() {
it('Sends the correct request', function() {
stripe.invoices.pay('invoiceId6', {
stripe.invoices.pay('in_123', {
source: 'tok_FooBar',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/invoices/invoiceId6/pay',
url: '/v1/invoices/in_123/pay',
headers: {},
data: {source: 'tok_FooBar'},
});
});
});

describe('list', function() {
describe('send', function() {
it('Sends the correct request', function() {
stripe.invoices.list({count: 25});
stripe.invoices.send('in_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices',
method: 'POST',
url: '/v1/invoices/in_123/send',
headers: {},
data: {count: 25},
data: {}
});
});
});

describe('void', function() {
it('Sends the correct request', function() {
stripe.invoices.void('in_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/invoices/in_123/void',
headers: {},
data: {}
});
});
});
Expand Down

0 comments on commit 218d5f9

Please sign in to comment.