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 Subscription Schedule resource #562

Merged
merged 1 commit into from
Feb 12, 2019
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
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
29 changes: 5 additions & 24 deletions test/resources/Checkout/Sessions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ describe('Checkout', function () {
describe('Sessions Resource', function () {
describe('create', function() {
it('Sends the correct request', function() {
stripe.checkout.sessions.create({
allowed_source_types: ['card'],
var params = {
cancel_url: 'https://stripe.com/cancel',
client_reference_id: '1234',
line_items: [
Expand All @@ -27,34 +26,16 @@ describe('Checkout', function () {
payment_intent_data: {
receipt_email: '[email protected]',
},
payment_method_types: ['card'],
success_url: 'https://stripe.com/success',
});
};
stripe.checkout.sessions.create(params);

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/checkout/sessions',
headers: {},
data: {
allowed_source_types: ['card'],
cancel_url: 'https://stripe.com/cancel',
client_reference_id: '1234',
line_items: [
{
amount: 123,
currency: 'usd',
description: 'item 1',
images: [
'https://stripe.com/img1',
],
name: 'name',
quantity: 2,
},
],
payment_intent_data: {
receipt_email: '[email protected]',
},
success_url: 'https://stripe.com/success',
},
data: params,
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/resources/PaymentIntents.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe('Payment Intents Resource', function() {
describe('create', function() {
it('Sends the correct request', function() {
var params = {
allowed_source_types: ['card'],
amount: 200,
currency: 'usd',
payment_method_types: ['card'],
};
stripe.paymentIntents.create(params);
expect(stripe.LAST_REQUEST).to.deep.equal({
Expand Down
117 changes: 117 additions & 0 deletions test/resources/SubscriptionSchedule.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
'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('cancel', function() {
it('Sends the correct request', 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('list', function() {
it('Sends the correct request', function() {
stripe.subscriptionSchedules.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/subscription_schedules',
data: {},
headers: {},
});
});
});

describe('release', function() {
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
it('Sends the correct request', 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', 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('update', function() {
it('Sends the correct request', function() {
var data = {metadata: {key: 'value'}};
stripe.subscriptionSchedules.update(SCHEDULE_TEST_ID, data);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID,
data: 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: {},
});
});
});
});