Skip to content

Commit

Permalink
Add support for the Subscription Schedule resource
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Feb 2, 2019
1 parent db420f3 commit 70c229c
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/resources/SubscriptionScheduleRevisions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var StripeResource = require('../StripeResource');

/**
* SubscriptionScheduleRevisions is a unique resource in that, upon instantiation,
* requires a subscription schedule id, and therefore each of its methods only
* require the scheduleId argument.
*
* This streamlines the API specifically for the case of accessing a revision
* on a returned subscription schedule object.
*
* E.g. scheduleObject.revisions.retrieve(revisionId)
* (As opposed to the also-supported stripe.subscriptionSchedules.retrieveRevision(scheduleId,
* revisionId))
*/
module.exports = StripeResource.extend({
path: 'subscription_schedules/{scheduleId}/revisions',
includeBasic: ['list', 'retrieve',],
});
43 changes: 43 additions & 0 deletions lib/resources/SubscriptionSchedules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

var StripeResource = require('../StripeResource');
var stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({

path: 'subscription_schedules',

includeBasic: [
'create', 'list', 'retrieve', 'update',
'setMetadata', 'getMetadata',
],

release: stripeMethod({
method: 'POST',
path: '/{id}/release',
urlParams: ['id'],
}),

cancel: stripeMethod({
method: 'POST',
path: '/{id}/cancel',
urlParams: ['id'],
}),

/**
* SubscriptionSchedules: SubscriptionScheduleRevisions methods
*/

listRevisions: stripeMethod({
method: 'GET',
path: '/{scheduleId}/revisions',
urlParams: ['scheduleId'],
methodType: 'list',
}),

retrieveRevision: stripeMethod({
method: 'GET',
path: '/{scheduleId}/revisions/{revisionId}',
urlParams: ['scheduleId', 'revisionId'],
}),
});
2 changes: 2 additions & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var resources = {
Skus: require('./resources/SKUs'),
Sources: require('./resources/Sources'),
SubscriptionItems: require('./resources/SubscriptionItems'),
SubscriptionSchedules: require('./resources/SubscriptionSchedules'),
Subscriptions: require('./resources/Subscriptions'),
ThreeDSecure: require('./resources/ThreeDSecure'),
Tokens: require('./resources/Tokens'),
Expand All @@ -81,6 +82,7 @@ var resources = {
CustomerCards: require('./resources/CustomerCards'),
CustomerSubscriptions: require('./resources/CustomerSubscriptions'),
Persons: require('./resources/Persons'),
SubscriptionScheduleRevisions: require('./resources/SubscriptionScheduleRevisions'),
TransferReversals: require('./resources/TransferReversals'),

// Namespaced resources
Expand Down
92 changes: 92 additions & 0 deletions test/resources/SubscriptionSchedule.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict';

var stripe = require('../../testUtils').getSpyableStripe();
var expect = require('chai').expect;

var SCHEDULE_TEST_ID = 'sub_sched_123';
var REVISION_TEST_ID = 'sub_sched_rev_123';

describe('Subscription Schedule Resource', function() {
describe('release', function() {
it('release a subscription schedule successfully', function() {
var data = {
invoice_now: true,
}
stripe.subscriptionSchedules.cancel(SCHEDULE_TEST_ID, data);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/cancel',
data: data,
headers: {},
});
});
});

describe('create', function() {
it('Sends the correct request', function() {
var data = {
customer: 'cus_123',
};
stripe.subscriptionSchedules.create(data);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/subscription_schedules',
data: data,
headers: {},
});
});
});

describe('release', function() {
it('release a subscription schedule successfully', function() {
var data = {
preserve_cancel_date: true,
}
stripe.subscriptionSchedules.release(SCHEDULE_TEST_ID, data);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/release',
data: data,
headers: {},
});
});
});

describe('retrieve', function() {
it('Sends the correct request with ID param', function() {
stripe.subscriptionSchedules.retrieve(SCHEDULE_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/subscription_schedules/sub_sched_123',
data: {},
headers: {},
});
});
});

describe('Revision methods', function() {
describe('retrieveRevision', function() {
it('Sends the correct request', function() {
stripe.subscriptionSchedules.retrieveRevision(SCHEDULE_TEST_ID, REVISION_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/revisions/' + REVISION_TEST_ID,
headers: {},
data: {},
});
});
});

describe('listRevisions', function() {
it('Sends the correct request', function() {
stripe.subscriptionSchedules.listRevisions(SCHEDULE_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/revisions',
headers: {},
data: {},
});
});
});
});
});
44 changes: 44 additions & 0 deletions test/resources/SubscriptionScheduleRevision.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

var resources = require('../../lib/stripe').resources;
var stripe = require('../../testUtils').getSpyableStripe();
var expect = require('chai').expect;

var SCHEDULE_TEST_ID = 'sub_sched_123';
var REVISION_TEST_ID = 'sub_sched_rev_123';

// Create new SubscriptionScheduleRevision instance with pre-filled scheduleId:
var revision = new resources.SubscriptionScheduleRevisions(
stripe,
{scheduleId: SCHEDULE_TEST_ID}
);

// Use spy from existing resource:
revision._request = stripe.customers._request;

describe('SubscriptionScheduleRevision Resource', function() {
describe('list', function() {
it('Sends the correct request', function() {
revision.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/revisions',
data: {},
headers: {},
});
});
});

describe('retrieve', function() {
it('Sends the correct request', function() {
revision.retrieve(REVISION_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/revisions/' + REVISION_TEST_ID,
data: {},
headers: {},
});
});
});
});

0 comments on commit 70c229c

Please sign in to comment.