-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the Subscription Schedule resource
- Loading branch information
1 parent
db420f3
commit a138982
Showing
7 changed files
with
232 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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',], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: [ | ||
|
@@ -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, | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
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: {}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|