diff --git a/lib/resources/UsageRecords.js b/lib/resources/UsageRecords.js index 8230549467..c1871f621f 100644 --- a/lib/resources/UsageRecords.js +++ b/lib/resources/UsageRecords.js @@ -4,13 +4,19 @@ var stripeMethod = require('../StripeMethod'); module.exports = require('../StripeResource').extend({ path: 'subscription_items', - create: function(args) { - var requestPath = args.subscription_item + '/usage_records'; - var reqArgs = Object.assign({}, args); + create: function() { + var args = Array.prototype.slice.call(arguments); + + var reqArgs = args.shift(); + var requestPath = reqArgs.subscription_item + '/usage_records'; + delete reqArgs.subscription_item; + + args.unshift(reqArgs); + return stripeMethod({ method: 'POST', path: requestPath - }).bind(this)(reqArgs); + }).apply(this, args); } }); diff --git a/test/resources/UsageRecords.spec.js b/test/resources/UsageRecords.spec.js index f14cac308a..1aab57239b 100644 --- a/test/resources/UsageRecords.spec.js +++ b/test/resources/UsageRecords.spec.js @@ -12,6 +12,7 @@ describe('UsageRecords Resource', function() { timestmap: 123321, action: 'increment' }); + expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', url: '/v1/subscription_items/si_123/usage_records', @@ -23,5 +24,42 @@ describe('UsageRecords Resource', function() { } }); }); + + it('Includes any options that were provided', function(done) { + stripe.usageRecords.create({ + subscription_item: 'si_123', + quantity: 123, + timestmap: 123321, + action: 'increment' + }, { + stripe_account: 'acct_456', + }).then(function(record) { + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'POST', + url: '/v1/subscription_items/si_123/usage_records', + headers: { + 'Stripe-Account': 'acct_456' + }, + data: { + quantity: 123, + timestmap: 123321, + action: 'increment' + } + }); + + done(); + }); + }); + + it('Calls a given callback', function(done) { + stripe.usageRecords.create({ + subscription_item: 'si_123', + quantity: 123, + timestmap: 123321, + action: 'increment' + }, function(error, record) { + done(error); + }); + }); }); });