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 Issuing API calls, create a 'StripeNamespace' #481

Merged
merged 1 commit into from
Jul 26, 2018
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
22 changes: 22 additions & 0 deletions lib/ResourceNamespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

// ResourceNamespace allows you to create nested resources, i.e. `stripe.issuing.cards`.
// It also works recursively, so you could do i.e. `stripe.billing.invoicing.pay`.

function ResourceNamespace(stripe, resources) {
for (var name in resources) {
var camelCaseName = name[0].toLowerCase() + name.substring(1);

var resource = new resources[name](stripe);

this[camelCaseName] = resource;
}
}

module.exports = function(namespace, resources) {
return function (stripe) {
return new ResourceNamespace(stripe, resources);
};
};

module.exports.ResourceNamespace = ResourceNamespace;
22 changes: 22 additions & 0 deletions lib/resources/Issuing/Authorizations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

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

module.exports = StripeResource.extend({
path: 'issuing/authorizations',

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

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

decline: stripeMethod({
method: 'POST',
path: '/{id}/decline',
urlParams: ['id'],
}),
});
8 changes: 8 additions & 0 deletions lib/resources/Issuing/Cardholders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

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

module.exports = StripeResource.extend({
path: 'issuing/cardholders',
includeBasic: ['create', 'list', 'retrieve', 'update', 'setMetadata', 'getMetadata'],
});
16 changes: 16 additions & 0 deletions lib/resources/Issuing/Cards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

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

module.exports = StripeResource.extend({
path: 'issuing/cards',

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

retrieveDetails: stripeMethod({
method: 'GET',
path: '/{id}/details',
urlParams: ['id'],
}),
});
8 changes: 8 additions & 0 deletions lib/resources/Issuing/Disputes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

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

module.exports = StripeResource.extend({
path: 'issuing/disputes',
includeBasic: ['create', 'list', 'retrieve', 'update', 'setMetadata', 'getMetadata'],
});
8 changes: 8 additions & 0 deletions lib/resources/Issuing/Transactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

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

module.exports = StripeResource.extend({
path: 'issuing/transactions',
includeBasic: ['list', 'retrieve', 'update', 'setMetadata', 'getMetadata'],
});
10 changes: 10 additions & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var APP_INFO_PROPERTIES = ['name', 'version', 'url'];
var EventEmitter = require('events').EventEmitter;
var exec = require('child_process').exec;

var resourceNamespace = require('./ResourceNamespace');

var resources = {
// Support Accounts for consistency, Account for backwards compat
Account: require('./resources/Accounts'),
Expand Down Expand Up @@ -73,6 +75,14 @@ var resources = {
ApplicationFeeRefunds: require('./resources/ApplicationFeeRefunds'),
TransferReversals: require('./resources/TransferReversals'),

// Namespaced resources
Issuing: resourceNamespace('issuing', {
Authorizations: require('./resources/Issuing/Authorizations'),
Cardholders: require('./resources/Issuing/Cardholders'),
Cards: require('./resources/Issuing/Cards'),
Transactions: require('./resources/Issuing/Transactions'),
Disputes: require('./resources/Issuing/Disputes'),
}),
};

Stripe.StripeResource = require('./StripeResource');
Expand Down
78 changes: 78 additions & 0 deletions test/resources/Issuing/Authorization.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use strict';

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

describe('Issuing', function () {
describe('Authorization Resource', function() {
describe('retrieve', function() {
it('Sends the correct request', function() {
stripe.issuing.authorizations.retrieve('iauth_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/issuing/authorizations/iauth_123',
data: {},
headers: {},
});
});
});

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

describe('update', function() {
it('Sends the correct request', function() {
stripe.issuing.authorizations.update('iauth_123', {
metadata: {
thing1: true,
thing2: 'yes'
},
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/issuing/authorizations/iauth_123',
headers: {},
data: {
metadata: {
thing1: true,
thing2: 'yes'
},
},
});
});
});

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

describe('decline', function() {
it('Sends the correct request', function() {
stripe.issuing.authorizations.decline('iauth_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/issuing/authorizations/iauth_123/decline',
headers: {},
data: {},
});
});
});
});
});
76 changes: 76 additions & 0 deletions test/resources/Issuing/Cardholders.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';

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

var expect = require('chai').expect;

describe('Issuing', function () {
describe('Cardholders Resource', function () {
describe('retrieve', function () {
it('Sends the correct request', function () {
stripe.issuing.cardholders.retrieve('ich_123');

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/issuing/cardholders/ich_123',
headers: {},
data: {},
});
});
});

describe('create', function () {
it('Sends the correct request', function () {
stripe.issuing.cardholders.create({
billing: {},
name: 'Tim Testperson',
type: 'individual',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/issuing/cardholders',
headers: {},
data: {
billing: {},
name: 'Tim Testperson',
type: 'individual',
},
});
});
});

describe('update', function () {
it('Sends the correct request', function () {
stripe.issuing.cardholders.update('ich_123', {
metadata: {
thing1: true,
thing2: 'yes'
},
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/issuing/cardholders/ich_123',
headers: {},
data: {
metadata: {
thing1: true,
thing2: 'yes'
},
},
});
});
});

describe('list', function () {
it('Sends the correct request', function () {
stripe.issuing.cardholders.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/issuing/cardholders',
headers: {},
data: {},
});
});
});
});
});
89 changes: 89 additions & 0 deletions test/resources/Issuing/Cards.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'use strict';

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

var expect = require('chai').expect;

describe('Issuing', function () {
describe('Cards Resource', function () {
describe('retrieve', function () {
it('Sends the correct request', function () {
stripe.issuing.cards.retrieve('ic_123');

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/issuing/cards/ic_123',
headers: {},
data: {},
});
});
});

describe('create', function () {
it('Sends the correct request', function () {
stripe.issuing.cards.create({
currency: 'usd',
type: 'physical',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/issuing/cards',
headers: {},
data: {
currency: 'usd',
type: 'physical',
},
});
});
});

describe('update', function () {
it('Sends the correct request', function () {
stripe.issuing.cards.update('ic_123', {
metadata: {
thing1: true,
thing2: 'yes'
},
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/issuing/cards/ic_123',
headers: {},
data: {
metadata: {
thing1: true,
thing2: 'yes'
},
},
});
});
});

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

describe('Virtual Cards Resource', function () {
describe('retrieve', function () {
it('Sends the correct request', function () {
stripe.issuing.cards.retrieveDetails('ic_123');

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/issuing/cards/ic_123/details',
headers: {},
data: {},
});
});
});
});
});
Loading