Accounts = function () {
Super.apply(this, arguments);
}n/a
ApplePayDomains = function () {
Super.apply(this, arguments);
}n/a
ApplicationFeeRefunds = function () {
Super.apply(this, arguments);
}...
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var APPFEE_TEST_ID = 'appFeeIdTest999';
var REFUND_TEST_ID = 'refundIdTest999';
// Create new CustomerCard instance with pre-filled customerId:
var appFeeRefund = new resources.ApplicationFeeRefunds(
stripe,
{feeId: APPFEE_TEST_ID}
);
// Use spy from existing resource:
appFeeRefund._request = stripe.customers._request;
...ApplicationFees = function () {
Super.apply(this, arguments);
}n/a
Balance = function () {
Super.apply(this, arguments);
}n/a
BitcoinReceivers = function () {
Super.apply(this, arguments);
}n/a
ChargeRefunds = function () {
Super.apply(this, arguments);
}...
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var CHARGE_TEST_ID = 'chargeIdTest999';
var REFUND_TEST_ID = 'refundIdTest999';
// Create new CustomerCard instance with pre-filled customerId:
var chargeRefund = new resources.ChargeRefunds(
stripe,
{chargeId: CHARGE_TEST_ID}
);
// Use spy from existing resource:
chargeRefund._request = stripe.customers._request;
...Charges = function () {
Super.apply(this, arguments);
}n/a
CountrySpecs = function () {
Super.apply(this, arguments);
}n/a
Coupons = function () {
Super.apply(this, arguments);
}n/a
CustomerCards = function () {
Super.apply(this, arguments);
}...
var resources = require('../../lib/stripe').resources;
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var CUSTOMER_TEST_ID = 'customerIdTest999';
// Create new CustomerCard instance with pre-filled customerId:
var customerCard = new resources.CustomerCards(
stripe,
{customerId: CUSTOMER_TEST_ID}
);
// Use spy from existing resource:
customerCard._request = stripe.customers._request;
...CustomerSubscriptions = function () {
Super.apply(this, arguments);
}...
var resources = require('../../lib/stripe').resources;
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var CUSTOMER_TEST_ID = 'customerIdTest999';
// Create new CustomerSubscription instance with pre-filled customerId:
var customerSubscription = new resources.CustomerSubscriptions(
stripe,
{customerId: CUSTOMER_TEST_ID}
);
// Use spy from existing resource:
customerSubscription._request = stripe.customers._request;
...Customers = function () {
Super.apply(this, arguments);
}n/a
Disputes = function () {
Super.apply(this, arguments);
}n/a
function _Error(raw) {
this.populate.apply(this, arguments);
this.stack = (new Error(this.message)).stack;
}n/a
Events = function () {
Super.apply(this, arguments);
}n/a
FileUploads = function () {
Super.apply(this, arguments);
}n/a
InvoiceItems = function () {
Super.apply(this, arguments);
}n/a
Invoices = function () {
Super.apply(this, arguments);
}n/a
OrderReturns = function () {
Super.apply(this, arguments);
}n/a
Orders = function () {
Super.apply(this, arguments);
}n/a
Payouts = function () {
Super.apply(this, arguments);
}n/a
Plans = function () {
Super.apply(this, arguments);
}n/a
Products = function () {
Super.apply(this, arguments);
}n/a
RecipientCards = function () {
Super.apply(this, arguments);
}...
var resources = require('../../lib/stripe').resources;
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var RECIPIENT_TEST_ID = 'recipientIdTest999';
// Create new recipientCard instance with pre-filled recipientId:
var recipientCard = new resources.RecipientCards(
stripe,
{recipientId: RECIPIENT_TEST_ID}
);
// Use spy from existing resource:
recipientCard._request = stripe.recipients._request;
...Recipients = function () {
Super.apply(this, arguments);
}n/a
Refunds = function () {
Super.apply(this, arguments);
}n/a
SKUs = function () {
Super.apply(this, arguments);
}n/a
Sources = function () {
Super.apply(this, arguments);
}n/a
function StripeResource(stripe, urlData) {
this._stripe = stripe;
this._urlData = urlData || {};
this.basePath = utils.makeURLInterpolator(stripe.getApiField('basePath'));
this.resourcePath = this.path;
this.path = utils.makeURLInterpolator(this.path);
if (this.includeBasic) {
this.includeBasic.forEach(function(methodName) {
this[methodName] = StripeResource.BASIC_METHODS[methodName];
}, this);
}
this.initialize.apply(this, arguments);
}n/a
SubscriptionItems = function () {
Super.apply(this, arguments);
}n/a
Subscriptions = function () {
Super.apply(this, arguments);
}n/a
ThreeDSecure = function () {
Super.apply(this, arguments);
}n/a
Tokens = function () {
Super.apply(this, arguments);
}n/a
TransferReversals = function () {
Super.apply(this, arguments);
}...
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var TRANSFER_TEST_ID = 'transferIdTest999';
var REVERSAL_TEST_ID = 'reversalIdTest999';
// Create new CustomerCard instance with pre-filled customerId:
var transferReversal = new resources.TransferReversals(
stripe,
{transferId: TRANSFER_TEST_ID}
);
// Use spy from existing resource:
transferReversal._request = stripe.customers._request;
...Transfers = function () {
Super.apply(this, arguments);
}n/a
Accounts = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
create = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
The package needs to be configured with your account's secret key which is
available in your [Stripe Dashboard][api-keys]. Require it with the key's
value:
``` js
var stripe = require('stripe')('sk_test_...');
stripe.customers.create(
{ email: 'customer@example.com' },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
}
);
```
...createExternalAccount = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('createExternalAccount', function() {
it('Sends the correct request', function() {
stripe.account.createExternalAccount('accountIdFoo321', {
number: '123456', currency: 'usd', country: 'US',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/accounts/accountIdFoo321/external_accounts',
headers: {},
data: {number: '123456', currency: 'usd', country: 'US'},
...del = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
}
},
add: function(fn) {
this._cleanupFns.push(fn);
},
deleteCustomer: function(custId) {
this.add(function() {
return this._stripe.customers.del(custId);
});
},
deletePlan: function(pId) {
this.add(function() {
return this._stripe.plans.del(pId);
});
},
...deleteExternalAccount = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {default_for_currency: true},
});
});
});
describe('deleteExternalAccount', function() {
it('Sends the correct request', function() {
stripe.account.deleteExternalAccount('accountIdFoo321', 'externalAccountIdFoo456
');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'DELETE',
url: '/v1/accounts/accountIdFoo321/external_accounts/externalAccountIdFoo456',
headers: {},
data: {},
});
});
...list = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
},
});
});
});
describe('list', function() {
it('Sends the correct request', function() {
stripe.applePayDomains.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/apple_pay/domains',
headers: {},
data: {},
});
});
...listExternalAccounts = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('listExternalAccounts', function() {
it('Sends the correct request', function() {
stripe.account.listExternalAccounts('accountIdFoo321');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/accountIdFoo321/external_accounts',
headers: {},
data: {},
});
});
...reject = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('reject', function() {
it('rejects an account successfully', function() {
stripe.account.reject('acct_16Tzq6DBahdM4C8s', {reason: 'fraud'
;});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/accounts/acct_16Tzq6DBahdM4C8s/reject',
data: {reason: 'fraud'},
headers: {},
});
});
...retrieve = function (id) {
// No longer allow an api key to be passed as the first string to this function due to ambiguity between
// old account ids and api keys. To request the account for an api key, send null as the id
if (typeof id === 'string') {
return stripeMethod({
method: 'GET',
path: 'accounts/{id}',
urlParams: ['id'],
}).apply(this, arguments);
} else {
if (id === null || id === undefined) {
// Remove id as stripeMethod would complain of unexpected argument
[].shift.apply(arguments);
}
return stripeMethod({
method: 'GET',
path: 'account',
}).apply(this, arguments);
}
}...
### Configuring For Connect
A per-request `Stripe-Account` header for use with [Stripe Connect][connect]
can be added to any method:
``` js
// Retrieve the balance for a connected account:
stripe.balance.retrieve({
stripe_account: "acct_foo"
}).then(function(balance) {
// The balance object for the connected account
}).catch(function(err) {
// Error
});
```
...retrieveExternalAccount = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
});
});
});
describe('External account methods', function() {
describe('retrieveExternalAccount', function() {
it('Sends the correct request', function() {
stripe.account.retrieveExternalAccount('accountIdFoo321', 'externalAccountIdFoo456
');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/accountIdFoo321/external_accounts/externalAccountIdFoo456',
headers: {},
data: {},
});
});
...update = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
customer = joined[1];
})
).to.not.be.eventually.rejected;
});
describe('And I apply the coupon to the customer', function() {
it('Does so', function() {
return expect(
stripe.customers.update(customer.id, {
coupon: coupon.id,
})
).to.not.be.eventually.rejected;
});
it('Can be retrieved from that customer', function() {
return expect(
stripe.customers.retrieve(customer.id)
...updateExternalAccount = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('updateExternalAccount', function() {
it('Sends the correct request', function() {
stripe.account.updateExternalAccount('accountIdFoo321', 'externalAccountIdFoo456
', {
default_for_currency: true,
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/accounts/accountIdFoo321/external_accounts/externalAccountIdFoo456',
headers: {},
data: {default_for_currency: true},
...ApplePayDomains = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
ApplicationFeeRefunds = function () {
Super.apply(this, arguments);
}...
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var APPFEE_TEST_ID = 'appFeeIdTest999';
var REFUND_TEST_ID = 'refundIdTest999';
// Create new CustomerCard instance with pre-filled customerId:
var appFeeRefund = new resources.ApplicationFeeRefunds(
stripe,
{feeId: APPFEE_TEST_ID}
);
// Use spy from existing resource:
appFeeRefund._request = stripe.customers._request;
...extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
ApplicationFees = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
createRefund = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
url: '/v1/application_fees/appFeeIdExample3242/refunds/refundIdExample2312',
data: {metadata: {key: 'value'}},
headers: {},
});
});
it('Sends the correct create request', function() {
stripe.applicationFees.createRefund(
'appFeeIdExample3242',
{amount: 100}
);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/application_fees/appFeeIdExample3242/refunds',
data: {amount: 100},
...listRefunds = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
url: '/v1/application_fees/appFeeIdExample3242/refunds',
data: {amount: 100},
headers: {},
});
});
it('Sends the correct list request', function() {
stripe.applicationFees.listRefunds(
'appFeeIdExample3242'
);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/application_fees/appFeeIdExample3242/refunds',
data: {},
headers: {},
...refund = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('refund', function() {
it('Sends the correct request', function() {
stripe.applicationFees.refund('applicationFeeIdExample3242', {amount: 23
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/application_fees/applicationFeeIdExample3242/refund',
data: {amount: 23},
headers: {},
});
});
...retrieveRefund = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
* requires an application fee id , and therefore each of its methods only
* require the refundId argument.
*
* This streamlines the API specifically for the case of accessing refunds
* on a returned application fee object.
*
* E.g. applicationFeeObject.refunds.retrieve(refundId)
* (As opposed to the also-supported stripe.applicationFees.retrieveRefund(chargeId,
* refundId))
*/
module.exports = StripeResource.extend({
path: 'application_fees/{feeId}/refunds',
includeBasic: ['create', 'list', 'retrieve', 'update'],
});
...updateRefund = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('refunds', function() {
it('Sends the correct update request', function() {
stripe.applicationFees.updateRefund(
'appFeeIdExample3242',
'refundIdExample2312',
{metadata: {key: 'value'}}
);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/application_fees/appFeeIdExample3242/refunds/refundIdExample2312',
...Balance = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
listTransactions = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('listTransactions', function() {
it('Sends the correct request', function() {
stripe.balance.listTransactions();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/balance/history',
data: {},
headers: {},
});
});
...retrieve = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
### Configuring For Connect
A per-request `Stripe-Account` header for use with [Stripe Connect][connect]
can be added to any method:
``` js
// Retrieve the balance for a connected account:
stripe.balance.retrieve({
stripe_account: "acct_foo"
}).then(function(balance) {
// The balance object for the connected account
}).catch(function(err) {
// Error
});
```
...retrieveTransaction = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11',
});
});
});
describe('retrieveTransaction', function() {
it('Sends the correct request', function() {
stripe.balance.retrieveTransaction('transactionIdFoo');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/balance/history/transactionIdFoo',
data: {},
headers: {},
});
});
...BitcoinReceivers = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
listTransactions = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('listTransactions', function() {
it('Sends the correct request', function() {
stripe.balance.listTransactions();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/balance/history',
data: {},
headers: {},
});
});
...ChargeRefunds = function () {
Super.apply(this, arguments);
}...
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var CHARGE_TEST_ID = 'chargeIdTest999';
var REFUND_TEST_ID = 'refundIdTest999';
// Create new CustomerCard instance with pre-filled customerId:
var chargeRefund = new resources.ChargeRefunds(
stripe,
{chargeId: CHARGE_TEST_ID}
);
// Use spy from existing resource:
chargeRefund._request = stripe.customers._request;
...extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Charges = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
capture = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('capture', function() {
it('Sends the correct request', function() {
stripe.charges.capture('chargeIdExample3242', {amount: 23});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/charges/chargeIdExample3242/capture',
headers: {},
data: {amount: 23},
});
});
...closeDispute = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {evidence: 'foo'},
});
});
});
describe('closeDispute', function() {
it('Sends the correct request', function() {
stripe.charges.closeDispute('chargeIdExample3242', {});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/charges/chargeIdExample3242/dispute/close',
headers: {},
data: {},
});
});
...createRefund = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
url: '/v1/application_fees/appFeeIdExample3242/refunds/refundIdExample2312',
data: {metadata: {key: 'value'}},
headers: {},
});
});
it('Sends the correct create request', function() {
stripe.applicationFees.createRefund(
'appFeeIdExample3242',
{amount: 100}
);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/application_fees/appFeeIdExample3242/refunds',
data: {amount: 100},
...listRefunds = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
url: '/v1/application_fees/appFeeIdExample3242/refunds',
data: {amount: 100},
headers: {},
});
});
it('Sends the correct list request', function() {
stripe.applicationFees.listRefunds(
'appFeeIdExample3242'
);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/application_fees/appFeeIdExample3242/refunds',
data: {},
headers: {},
...markAsFraudulent = function (chargeId) {
return this.update(chargeId, {'fraud_details': {'user_report': 'fraudulent'}})
}...
data: {},
});
});
});
describe('markAsFraudulent', function() {
it('Sends the correct request', function() {
stripe.charges.markAsFraudulent('chargeIdExample3242');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/charges/chargeIdExample3242',
data: {'fraud_details': {'user_report': 'fraudulent'}},
headers: {},
});
});
...markAsSafe = function (chargeId) {
return this.update(chargeId, {'fraud_details': {'user_report': 'safe'}})
}...
headers: {},
});
});
});
describe('markAsSafe', function() {
it('Sends the correct request', function() {
stripe.charges.markAsSafe('chargeIdExample3242');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/charges/chargeIdExample3242',
data: {'fraud_details': {'user_report': 'safe'}},
headers: {},
});
});
...refund = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('refund', function() {
it('Sends the correct request', function() {
stripe.applicationFees.refund('applicationFeeIdExample3242', {amount: 23
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/application_fees/applicationFeeIdExample3242/refund',
data: {amount: 23},
headers: {},
});
});
...retrieveRefund = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
* requires an application fee id , and therefore each of its methods only
* require the refundId argument.
*
* This streamlines the API specifically for the case of accessing refunds
* on a returned application fee object.
*
* E.g. applicationFeeObject.refunds.retrieve(refundId)
* (As opposed to the also-supported stripe.applicationFees.retrieveRefund(chargeId,
* refundId))
*/
module.exports = StripeResource.extend({
path: 'application_fees/{feeId}/refunds',
includeBasic: ['create', 'list', 'retrieve', 'update'],
});
...updateDispute = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {},
});
});
});
describe('updateDispute', function() {
it('Sends the correct request', function() {
stripe.charges.updateDispute('chargeIdExample3242', {evidence: 'foo
'});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/charges/chargeIdExample3242/dispute',
headers: {},
data: {evidence: 'foo'},
});
});
...updateRefund = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('refunds', function() {
it('Sends the correct update request', function() {
stripe.applicationFees.updateRefund(
'appFeeIdExample3242',
'refundIdExample2312',
{metadata: {key: 'value'}}
);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/application_fees/appFeeIdExample3242/refunds/refundIdExample2312',
...CountrySpecs = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Coupons = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
CustomerCards = function () {
Super.apply(this, arguments);
}...
var resources = require('../../lib/stripe').resources;
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var CUSTOMER_TEST_ID = 'customerIdTest999';
// Create new CustomerCard instance with pre-filled customerId:
var customerCard = new resources.CustomerCards(
stripe,
{customerId: CUSTOMER_TEST_ID}
);
// Use spy from existing resource:
customerCard._request = stripe.customers._request;
...extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
CustomerSubscriptions = function () {
Super.apply(this, arguments);
}...
var resources = require('../../lib/stripe').resources;
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var CUSTOMER_TEST_ID = 'customerIdTest999';
// Create new CustomerSubscription instance with pre-filled customerId:
var customerSubscription = new resources.CustomerSubscriptions(
stripe,
{customerId: CUSTOMER_TEST_ID}
);
// Use spy from existing resource:
customerSubscription._request = stripe.customers._request;
...extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
deleteDiscount = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
return expect(
stripe.customers.retrieve(customer.id)
).to.eventually.have.deep.property('discount.coupon.id', coupon.id);
});
describe('The resulting discount', function() {
it('Can be removed', function() {
return expect(
stripe.customers.deleteDiscount(customer.id)
).to.eventually.have.property('deleted', true);
});
describe('Re-querying it', function() {
it('Does indeed indicate that it is deleted', function() {
return expect(
stripe.customers.retrieve(customer.id)
).to.eventually.have.deep.property('discount', null);
...Customers = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
_legacyCancelSubscription = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}n/a
_legacyUpdateSubscription = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}n/a
_newstyleCancelSubscription = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}n/a
_newstyleUpdateSubscription = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}n/a
cancelSubscription = function (customerId, subscriptionId) {
// This is a hack, but it lets us maximize our overloading.
// Precarious assumption: If it's not an auth key it _could_ be a sub id:
if (typeof subscriptionId == 'string' && !utils.isAuthKey(subscriptionId)) {
return this._newstyleCancelSubscription.apply(this, arguments);
} else {
return this._legacyCancelSubscription.apply(this, arguments);
}
}...
cleanup.deleteCustomer(customer.id);
cleanup.deletePlan(plan.id);
return stripe.customers.updateSubscription(customer.id, {
plan: plan.id,
});
}).then(function(subscription) {
return stripe.customers.cancelSubscription(subscription.customer, {
at_period_end: true,
});
})
).to.eventually.have.property('cancel_at_period_end', true);
});
describe('Plan name variations', function() {
...createCard = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
resolve('Called!');
});
})).to.eventually.equal('Called!');
});
it('Given an error the callback will receive it', function() {
return expect(new Promise(function(resolve, reject) {
stripe.customers.createCard('nonExistentCustId', {card: {}}, function(err
, customer) {
if (err) {
resolve('ErrorWasPassed');
} else {
reject('NoErrorPassed');
}
});
})).to.eventually.become('ErrorWasPassed');
...createSource = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
callback:
``` js
// Create a new customer and then a new charge for that customer:
stripe.customers.create({
email: 'foo-customer@example.com'
}).then(function(customer){
return stripe.customers.createSource(customer.id, {
source: {
object: 'card',
exp_month: 10,
exp_year: 2018,
number: '4242 4242 4242 4242',
cvc: 100
}
...createSubscription = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
).then(function(j) {
plan = j[0];
var customer = j[1];
cleanup.deleteCustomer(customer.id);
cleanup.deletePlan(plan.id);
return stripe.customers.createSubscription(customer.id, {
plan: plan.id,
});
}).then(function(subscription) {
return stripe.customers.updateSubscription(subscription.customer, subscription.id, {
plan: plan.id, quantity: '3',
});
}).then(function(subscription) {
...deleteCard = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {name: 'Bob M. Baz'},
});
});
});
describe('deleteCard', function() {
it('Sends the correct request', function() {
stripe.customers.deleteCard('customerIdFoo321', 'cardIdFoo456'
;);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'DELETE',
url: '/v1/customers/customerIdFoo321/cards/cardIdFoo456',
headers: {},
data: {},
});
});
...deleteDiscount = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
return expect(
stripe.customers.retrieve(customer.id)
).to.eventually.have.deep.property('discount.coupon.id', coupon.id);
});
describe('The resulting discount', function() {
it('Can be removed', function() {
return expect(
stripe.customers.deleteDiscount(customer.id)
).to.eventually.have.property('deleted', true);
});
describe('Re-querying it', function() {
it('Does indeed indicate that it is deleted', function() {
return expect(
stripe.customers.retrieve(customer.id)
).to.eventually.have.deep.property('discount', null);
...deleteSource = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {name: 'Bob M. Baz'},
});
});
});
describe('deleteSource', function() {
it('Sends the correct request', function() {
stripe.customers.deleteSource('customerIdFoo321', 'cardIdFoo456'
;);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'DELETE',
url: '/v1/customers/customerIdFoo321/sources/cardIdFoo456',
headers: {},
data: {},
});
});
...deleteSubscriptionDiscount = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {},
});
});
});
describe('deleteSubscriptionDiscount', function() {
it('Sends the correct request', function() {
stripe.customers.deleteSubscriptionDiscount('customerIdFoo321', 'subscriptionIdFoo456
');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'DELETE',
url: '/v1/customers/customerIdFoo321/subscriptions/subscriptionIdFoo456/discount',
headers: {},
data: {},
});
});
...listCards = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('listCards', function() {
it('Sends the correct request', function() {
stripe.customers.listCards('customerIdFoo321');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/customers/customerIdFoo321/cards',
headers: {},
data: {},
});
});
...listSources = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('listSources', function() {
it('Sends the correct request', function() {
stripe.customers.listSources('customerIdFoo321');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/customers/customerIdFoo321/sources',
headers: {},
data: {},
});
});
...listSubscriptions = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
});
});
});
});
describe('listSubscriptions', function() {
it('Sends the correct request', function() {
stripe.customers.listSubscriptions('customerIdFoo321');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/customers/customerIdFoo321/subscriptions',
headers: {},
data: {},
});
});
...retrieveCard = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
* requires a customerId, and therefore each of its methods only
* require the cardId argument.
*
* This streamlines the API specifically for the case of accessing cards
* on a returned customer object.
*
* E.g. customerObject.cards.retrieve(cardId)
* (As opposed to the also-supported stripe.customers.retrieveCard(custId, cardId))
*/
module.exports = StripeResource.extend({
path: 'customers/{customerId}/cards',
includeBasic: ['create', 'list', 'retrieve', 'update', 'del'],
});
...retrieveSource = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
});
});
});
describe('Source methods', function() {
describe('retrieveSource', function() {
it('Sends the correct request', function() {
stripe.customers.retrieveSource('customerIdFoo321', 'cardIdFoo456
');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/customers/customerIdFoo321/sources/cardIdFoo456',
headers: {},
data: {},
});
});
...retrieveSubscription = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
});
});
});
describe('Subscription methods', function() {
describe('retrieveSubscription', function() {
it('Sends the correct request', function() {
stripe.customers.retrieveSubscription('customerIdFoo321', 'subscriptionIdFoo456
');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/customers/customerIdFoo321/subscriptions/subscriptionIdFoo456',
headers: {},
data: {},
});
});
...updateCard = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('updateCard', function() {
it('Sends the correct request', function() {
stripe.customers.updateCard('customerIdFoo321', 'cardIdFoo456'
;, {
name: 'Bob M. Baz',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/customers/customerIdFoo321/cards/cardIdFoo456',
headers: {},
data: {name: 'Bob M. Baz'},
...updateSource = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('updateSource', function() {
it('Sends the correct request', function() {
stripe.customers.updateSource('customerIdFoo321', 'cardIdFoo456'
;, {
name: 'Bob M. Baz',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/customers/customerIdFoo321/sources/cardIdFoo456',
headers: {},
data: {name: 'Bob M. Baz'},
...updateSubscription = function (customerId, subscriptionId) {
if (typeof subscriptionId == 'string') {
return this._newstyleUpdateSubscription.apply(this, arguments);
} else {
return this._legacyUpdateSubscription.apply(this, arguments);
}
}...
).then(function(j) {
var plan = j[0];
var customer = j[1];
cleanup.deleteCustomer(customer.id);
cleanup.deletePlan(plan.id);
return stripe.customers.updateSubscription(customer.id, {
plan: plan.id,
});
})
).to.eventually.have.property('status', 'active');
});
it(
...verifySource = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
});
});
describe('verifySource', function() {
it('Sends the correct request', function() {
var data = {amounts: [32,45]}
stripe.customers.verifySource('customerIdFoo321', 'cardIdFoo456',
data, TEST_AUTH_KEY);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/customers/customerIdFoo321/sources/cardIdFoo456/verify',
headers: {},
data: data,
auth: TEST_AUTH_KEY,
})
...Disputes = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
close = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('close', function() {
it('Sends the correct request', function() {
stripe.disputes.close('dp_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/disputes/dp_123/close',
headers: {},
data: {},
});
});
...function _Error(raw) {
this.populate.apply(this, arguments);
this.stack = (new Error(this.message)).stack;
}n/a
StripeAPIError = function () {
Super.apply(this, arguments);
}...
StripeError.generate = function(rawStripeError) {
switch (rawStripeError.type) {
case 'card_error':
return new _Error.StripeCardError(rawStripeError);
case 'invalid_request_error':
return new _Error.StripeInvalidRequestError(rawStripeError);
case 'api_error':
return new _Error.StripeAPIError(rawStripeError);
}
return new _Error('Generic', 'Unknown Error');
};
// Specific Stripe Error types:
_Error.StripeCardError = StripeError.extend({type: 'StripeCardError'});
_Error.StripeInvalidRequestError = StripeError.extend({type: 'StripeInvalidRequestError'});
...StripeAuthenticationError = function () {
Super.apply(this, arguments);
}...
// These are now available on the top-level resource's
// lastResponse, but we keep them here too for backwards
// compatibility.
response.error.statusCode = res.statusCode;
response.error.requestId = res.requestId;
if (res.statusCode === 401) {
err = new Error.StripeAuthenticationError(response.error);
} else if (res.statusCode === 403) {
err = new Error.StripePermissionError(response.error);
} else if (res.statusCode === 429) {
err = new Error.StripeRateLimitError(response.error);
} else {
err = Error.StripeError.generate(response.error);
}
...StripeCardError = function () {
Super.apply(this, arguments);
}...
/**
* Helper factory which takes raw stripe errors and outputs wrapping instances
*/
StripeError.generate = function(rawStripeError) {
switch (rawStripeError.type) {
case 'card_error':
return new _Error.StripeCardError(rawStripeError);
case 'invalid_request_error':
return new _Error.StripeInvalidRequestError(rawStripeError);
case 'api_error':
return new _Error.StripeAPIError(rawStripeError);
}
return new _Error('Generic', 'Unknown Error');
};
...StripeConnectionError = function () {
Super.apply(this, arguments);
}...
timeoutErr.code = 'ETIMEDOUT';
req._isAborted = true;
req.abort();
callback.call(
self,
new Error.StripeConnectionError({
message: 'Request aborted due to timeout being reached (' + timeout + 'ms)',
detail: timeoutErr,
}),
null
);
}
},
...StripeError = function () {
Super.apply(this, arguments);
}n/a
StripeInvalidRequestError = function () {
Super.apply(this, arguments);
}...
* Helper factory which takes raw stripe errors and outputs wrapping instances
*/
StripeError.generate = function(rawStripeError) {
switch (rawStripeError.type) {
case 'card_error':
return new _Error.StripeCardError(rawStripeError);
case 'invalid_request_error':
return new _Error.StripeInvalidRequestError(rawStripeError);
case 'api_error':
return new _Error.StripeAPIError(rawStripeError);
}
return new _Error('Generic', 'Unknown Error');
};
// Specific Stripe Error types:
...StripePermissionError = function () {
Super.apply(this, arguments);
}...
// compatibility.
response.error.statusCode = res.statusCode;
response.error.requestId = res.requestId;
if (res.statusCode === 401) {
err = new Error.StripeAuthenticationError(response.error);
} else if (res.statusCode === 403) {
err = new Error.StripePermissionError(response.error);
} else if (res.statusCode === 429) {
err = new Error.StripeRateLimitError(response.error);
} else {
err = Error.StripeError.generate(response.error);
}
return callback.call(self, err, null);
}
...StripeRateLimitError = function () {
Super.apply(this, arguments);
}...
response.error.requestId = res.requestId;
if (res.statusCode === 401) {
err = new Error.StripeAuthenticationError(response.error);
} else if (res.statusCode === 403) {
err = new Error.StripePermissionError(response.error);
} else if (res.statusCode === 429) {
err = new Error.StripeRateLimitError(response.error);
} else {
err = Error.StripeError.generate(response.error);
}
return callback.call(self, err, null);
}
} catch (e) {
return callback.call(
...extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...populate = function (type, message) {
this.type = type;
this.message = message;
}n/a
Events = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
FileUploads = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
create = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
The package needs to be configured with your account's secret key which is
available in your [Stripe Dashboard][api-keys]. Require it with the key's
value:
``` js
var stripe = require('stripe')('sk_test_...');
stripe.customers.create(
{ email: 'customer@example.com' },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
}
);
```
...requestDataProcessor = function (method, data, headers) {
data = data || {};
if (method === 'POST') {
return multipartDataGenerator(method, data, headers);
} else {
return utils.stringifyRequestData(data);
}
}...
},
_request: function(method, path, data, auth, options, callback) {
var self = this;
var requestData;
if (self.requestDataProcessor) {
requestData = self.requestDataProcessor(method, data, options.headers);
} else {
requestData = utils.stringifyRequestData(data || {});
}
var apiVersion = this._stripe.getApiField('version');
var headers = {
...InvoiceItems = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Invoices = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
pay = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
});
});
});
});
describe('pay', function() {
it('Sends the correct request', function() {
stripe.invoices.pay('invoiceId6');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/invoices/invoiceId6/pay',
headers: {},
data: {},
});
});
...retrieveLines = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {application_fee: 200},
});
});
});
describe('retrieveLines', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieveLines('invoiceId2');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/invoiceId2/lines',
headers: {},
data: {},
});
});
...retrieveUpcoming = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
});
});
});
describe('retrieveUpcoming', function() {
describe('With just a customer ID', function() {
it('Sends the correct request', function() {
stripe.invoices.retrieveUpcoming('customerId1');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/invoices/upcoming?customer=customerId1',
headers: {},
data: {},
});
});
...OrderReturns = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Orders = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
create = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
The package needs to be configured with your account's secret key which is
available in your [Stripe Dashboard][api-keys]. Require it with the key's
value:
``` js
var stripe = require('stripe')('sk_test_...');
stripe.customers.create(
{ email: 'customer@example.com' },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
}
);
```
...pay = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
});
});
});
});
describe('pay', function() {
it('Sends the correct request', function() {
stripe.invoices.pay('invoiceId6');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/invoices/invoiceId6/pay',
headers: {},
data: {},
});
});
...returnOrder = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {source: 'tok_FooBar'},
});
});
});
describe('returnOrder', function() {
it('Sends the correct request', function() {
stripe.orders.returnOrder('orderIdFoo3242', {
items: [
{parent: 'sku_123'},
],
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/orders/orderIdFoo3242/returns',
...Payouts = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
cancel = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {metadata: {key: 'value'}},
});
});
});
describe('cancel', function() {
it('Sends the correct request', function() {
stripe.payouts.cancel(PAYOUT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payouts/' + PAYOUT_TEST_ID + '/cancel',
headers: {},
data: {},
});
});
...listTransactions = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('listTransactions', function() {
it('Sends the correct request', function() {
stripe.balance.listTransactions();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/balance/history',
data: {},
headers: {},
});
});
...Plans = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Products = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
create = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
The package needs to be configured with your account's secret key which is
available in your [Stripe Dashboard][api-keys]. Require it with the key's
value:
``` js
var stripe = require('stripe')('sk_test_...');
stripe.customers.create(
{ email: 'customer@example.com' },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
}
);
```
...RecipientCards = function () {
Super.apply(this, arguments);
}...
var resources = require('../../lib/stripe').resources;
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var RECIPIENT_TEST_ID = 'recipientIdTest999';
// Create new recipientCard instance with pre-filled recipientId:
var recipientCard = new resources.RecipientCards(
stripe,
{recipientId: RECIPIENT_TEST_ID}
);
// Use spy from existing resource:
recipientCard._request = stripe.recipients._request;
...extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Recipients = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
createCard = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
resolve('Called!');
});
})).to.eventually.equal('Called!');
});
it('Given an error the callback will receive it', function() {
return expect(new Promise(function(resolve, reject) {
stripe.customers.createCard('nonExistentCustId', {card: {}}, function(err
, customer) {
if (err) {
resolve('ErrorWasPassed');
} else {
reject('NoErrorPassed');
}
});
})).to.eventually.become('ErrorWasPassed');
...deleteCard = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {name: 'Bob M. Baz'},
});
});
});
describe('deleteCard', function() {
it('Sends the correct request', function() {
stripe.customers.deleteCard('customerIdFoo321', 'cardIdFoo456'
;);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'DELETE',
url: '/v1/customers/customerIdFoo321/cards/cardIdFoo456',
headers: {},
data: {},
});
});
...listCards = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('listCards', function() {
it('Sends the correct request', function() {
stripe.customers.listCards('customerIdFoo321');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/customers/customerIdFoo321/cards',
headers: {},
data: {},
});
});
...retrieveCard = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
* requires a customerId, and therefore each of its methods only
* require the cardId argument.
*
* This streamlines the API specifically for the case of accessing cards
* on a returned customer object.
*
* E.g. customerObject.cards.retrieve(cardId)
* (As opposed to the also-supported stripe.customers.retrieveCard(custId, cardId))
*/
module.exports = StripeResource.extend({
path: 'customers/{customerId}/cards',
includeBasic: ['create', 'list', 'retrieve', 'update', 'del'],
});
...updateCard = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
auth: TEST_AUTH_KEY,
});
});
});
describe('updateCard', function() {
it('Sends the correct request', function() {
stripe.customers.updateCard('customerIdFoo321', 'cardIdFoo456'
;, {
name: 'Bob M. Baz',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/customers/customerIdFoo321/cards/cardIdFoo456',
headers: {},
data: {name: 'Bob M. Baz'},
...Refunds = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
SKUs = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
create = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
The package needs to be configured with your account's secret key which is
available in your [Stripe Dashboard][api-keys]. Require it with the key's
value:
``` js
var stripe = require('stripe')('sk_test_...');
stripe.customers.create(
{ email: 'customer@example.com' },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
}
);
```
...Sources = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
verify = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {metadata: {foo: 'bar'}},
});
});
});
describe('verify', function() {
it('Sends the correct request', function() {
stripe.sources.verify('src_foo', {values: [32, 45]});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/sources/src_foo/verify',
headers: {},
data: {values: [32, 45]},
});
});
...create = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
The package needs to be configured with your account's secret key which is
available in your [Stripe Dashboard][api-keys]. Require it with the key's
value:
``` js
var stripe = require('stripe')('sk_test_...');
stripe.customers.create(
{ email: 'customer@example.com' },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
}
);
```
...del = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
}
},
add: function(fn) {
this._cleanupFns.push(fn);
},
deleteCustomer: function(custId) {
this.add(function() {
return this._stripe.customers.del(custId);
});
},
deletePlan: function(pId) {
this.add(function() {
return this._stripe.plans.del(pId);
});
},
...getMetadata = function (id, auth, cb) {
if (!cb && typeof auth == 'function') {
cb = auth;
auth = null;
}
var urlData = this.createUrlData();
var path = this.createFullPath('/' + id, urlData);
return this.wrapTimeout(new Promise((function(resolve, reject) {
this._request('GET', path, {}, auth, {}, function(err, response) {
if (err) {
reject(err);
} else {
resolve(response.metadata);
}
});
}).bind(this)), cb);
}...
stripe.customers.create(CUSTOMER_DETAILS)
.then(function(cust) {
customer = cust;
cleanup.deleteCustomer(cust.id);
return stripe.customers.setMetadata(cust.id, {foo: '123'});
})
.then(function() {
return stripe.customers.getMetadata(customer.id);
})
).to.eventually.deep.equal({foo: '123'});
});
it('Can reset metadata', function() {
var customer;
return expect(
stripe.customers.create(CUSTOMER_DETAILS)
...list = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
},
});
});
});
describe('list', function() {
it('Sends the correct request', function() {
stripe.applePayDomains.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/apple_pay/domains',
headers: {},
data: {},
});
});
...retrieve = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
### Configuring For Connect
A per-request `Stripe-Account` header for use with [Stripe Connect][connect]
can be added to any method:
``` js
// Retrieve the balance for a connected account:
stripe.balance.retrieve({
stripe_account: "acct_foo"
}).then(function(balance) {
// The balance object for the connected account
}).catch(function(err) {
// Error
});
```
...setMetadata = function (id, key, value, auth, cb) {
var self = this;
var data = key;
var isObject = isPlainObject(key);
// We assume null for an empty object
var isNull = data === null || (isObject && !Object.keys(data).length);
// Allow optional passing of auth & cb:
if ((isNull || isObject) && typeof value == 'string') {
auth = value;
} else if (typeof auth != 'string') {
if (!cb && typeof auth == 'function') {
cb = auth;
}
auth = null;
}
var urlData = this.createUrlData();
var path = this.createFullPath('/' + id, urlData);
return this.wrapTimeout(new Promise((function(resolve, reject) {
if (isNull) {
// Reset metadata:
sendMetadata(null, auth);
} else if (!isObject) {
// Set individual metadata property:
var metadata = {};
metadata[key] = value;
sendMetadata(metadata, auth);
} else {
// Set entire metadata object after resetting it:
this._request('POST', path, {
metadata: null,
}, auth, {}, function(err, response) {
if (err) {
return reject(err);
}
sendMetadata(data, auth);
});
}
function sendMetadata(metadata, auth) {
self._request('POST', path, {
metadata: metadata,
}, auth, {}, function(err, response) {
if (err) {
reject(err);
} else {
resolve(response.metadata);
}
});
}
}).bind(this)), cb);
}...
it('Can save and retrieve metadata', function() {
var customer;
return expect(
stripe.customers.create(CUSTOMER_DETAILS)
.then(function(cust) {
customer = cust;
cleanup.deleteCustomer(cust.id);
return stripe.customers.setMetadata(cust.id, {foo: '123'});
})
.then(function() {
return stripe.customers.getMetadata(customer.id);
})
).to.eventually.deep.equal({foo: '123'});
});
it('Can reset metadata', function() {
...update = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
customer = joined[1];
})
).to.not.be.eventually.rejected;
});
describe('And I apply the coupon to the customer', function() {
it('Does so', function() {
return expect(
stripe.customers.update(customer.id, {
coupon: coupon.id,
})
).to.not.be.eventually.rejected;
});
it('Can be retrieved from that customer', function() {
return expect(
stripe.customers.retrieve(customer.id)
...function StripeResource(stripe, urlData) {
this._stripe = stripe;
this._urlData = urlData || {};
this.basePath = utils.makeURLInterpolator(stripe.getApiField('basePath'));
this.resourcePath = this.path;
this.path = utils.makeURLInterpolator(this.path);
if (this.includeBasic) {
this.includeBasic.forEach(function(methodName) {
this[methodName] = StripeResource.BASIC_METHODS[methodName];
}, this);
}
this.initialize.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
_errorHandler = function (req, callback) {
var self = this;
return function(error) {
if (req._isAborted) {
// already handled
return;
}
callback.call(
self,
new Error.StripeConnectionError({
message: 'An error occurred with our connection to Stripe',
detail: error,
}),
null
);
}
}...
agent: self._stripe.getApiField('agent'),
headers: headers,
ciphers: 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5',
});
req.setTimeout(timeout, self._timeoutHandler(timeout, req, callback));
req.on('response', self._responseHandler(req, callback));
req.on('error', self._errorHandler(req, callback));
req.on('socket', function(socket) {
socket.on((isInsecureConnection ? 'connect' : 'secureConnect'), function() {
// Send payload; we're safe:
req.write(requestData);
req.end();
});
..._request = function (method, path, data, auth, options, callback) {
var self = this;
var requestData;
if (self.requestDataProcessor) {
requestData = self.requestDataProcessor(method, data, options.headers);
} else {
requestData = utils.stringifyRequestData(data || {});
}
var apiVersion = this._stripe.getApiField('version');
var headers = {
// Use specified auth token or use default from this stripe instance:
'Authorization': auth ?
'Basic ' + new Buffer(auth + ':').toString('base64') :
this._stripe.getApiField('auth'),
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': requestData.length,
'User-Agent': 'Stripe/v1 NodeBindings/' + this._stripe.getConstant('PACKAGE_VERSION'),
};
if (apiVersion) {
headers['Stripe-Version'] = apiVersion;
}
// Grab client-user-agent before making the request:
this._stripe.getClientUserAgent(function(cua) {
headers['X-Stripe-Client-User-Agent'] = cua;
if (options.headers) {
objectAssign(headers, options.headers);
}
makeRequest();
});
function makeRequest() {
var timeout = self._stripe.getApiField('timeout');
var isInsecureConnection = self._stripe.getApiField('protocol') == 'http';
var host = self.overrideHost || self._stripe.getApiField('host');
var req = (
isInsecureConnection ? http : https
).request({
host: host,
port: self._stripe.getApiField('port'),
path: path,
method: method,
agent: self._stripe.getApiField('agent'),
headers: headers,
ciphers: 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5',
});
req.setTimeout(timeout, self._timeoutHandler(timeout, req, callback));
req.on('response', self._responseHandler(req, callback));
req.on('error', self._errorHandler(req, callback));
req.on('socket', function(socket) {
socket.on((isInsecureConnection ? 'connect' : 'secureConnect'), function() {
// Send payload; we're safe:
req.write(requestData);
req.end();
});
});
}
}...
} else if (!isObject) {
// Set individual metadata property:
var metadata = {};
metadata[key] = value;
sendMetadata(metadata, auth);
} else {
// Set entire metadata object after resetting it:
this._request('POST', path, {
metadata: null,
}, auth, {}, function(err, response) {
if (err) {
return reject(err);
}
sendMetadata(data, auth);
});
..._responseHandler = function (req, callback) {
var self = this;
return function(res) {
var response = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
response += chunk;
});
res.on('end', function() {
var headers = res.headers || {};
try {
response = JSON.parse(response);
// For convenience, make Request-Id easily accessible on
// lastResponse.
res.requestId = headers['request-id'];
if (response.error) {
var err;
// These are now available on the top-level resource's
// lastResponse, but we keep them here too for backwards
// compatibility.
response.error.statusCode = res.statusCode;
response.error.requestId = res.requestId;
if (res.statusCode === 401) {
err = new Error.StripeAuthenticationError(response.error);
} else if (res.statusCode === 403) {
err = new Error.StripePermissionError(response.error);
} else if (res.statusCode === 429) {
err = new Error.StripeRateLimitError(response.error);
} else {
err = Error.StripeError.generate(response.error);
}
return callback.call(self, err, null);
}
} catch (e) {
return callback.call(
self,
new Error.StripeAPIError({
message: 'Invalid JSON received from the Stripe API',
response: response,
exception: e,
requestId: headers['request-id'],
}),
null
);
}
// Expose res object
Object.defineProperty(response, 'lastResponse', {
enumerable: false,
writable: false,
value: res,
});
callback.call(self, null, response);
});
};
}...
method: method,
agent: self._stripe.getApiField('agent'),
headers: headers,
ciphers: 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5',
});
req.setTimeout(timeout, self._timeoutHandler(timeout, req, callback));
req.on('response', self._responseHandler(req, callback));
req.on('error', self._errorHandler(req, callback));
req.on('socket', function(socket) {
socket.on((isInsecureConnection ? 'connect' : 'secureConnect'), function() {
// Send payload; we're safe:
req.write(requestData);
req.end();
..._timeoutHandler = function (timeout, req, callback) {
var self = this;
return function() {
var timeoutErr = new Error('ETIMEDOUT');
timeoutErr.code = 'ETIMEDOUT';
req._isAborted = true;
req.abort();
callback.call(
self,
new Error.StripeConnectionError({
message: 'Request aborted due to timeout being reached (' + timeout + 'ms)',
detail: timeoutErr,
}),
null
);
}
}...
path: path,
method: method,
agent: self._stripe.getApiField('agent'),
headers: headers,
ciphers: 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5',
});
req.setTimeout(timeout, self._timeoutHandler(timeout, req, callback));
req.on('response', self._responseHandler(req, callback));
req.on('error', self._errorHandler(req, callback));
req.on('socket', function(socket) {
socket.on((isInsecureConnection ? 'connect' : 'secureConnect'), function() {
// Send payload; we're safe:
req.write(requestData);
...createFullPath = function (commandPath, urlData) {
return path.join(
this.basePath(urlData),
this.path(urlData),
typeof commandPath == 'function' ?
commandPath(urlData) : commandPath
).replace(/\\/g, '/'); // ugly workaround for Windows
}...
if (!cb && typeof auth == 'function') {
cb = auth;
}
auth = null;
}
var urlData = this.createUrlData();
var path = this.createFullPath('/' + id, urlData);
return this.wrapTimeout(new Promise((function(resolve, reject) {
if (isNull) {
// Reset metadata:
sendMetadata(null, auth);
} else if (!isObject) {
// Set individual metadata property:
...createResourcePathWithSymbols = function (pathWithSymbols) {
return '/' + path.join(
this.resourcePath,
pathWithSymbols
).replace(/\\/g, '/'); // ugly workaround for Windows
}...
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
...createUrlData = function () {
var urlData = {};
// Merge in baseData
for (var i in this._urlData) {
if (hasOwn.call(this._urlData, i)) {
urlData[i] = this._urlData[i];
}
}
return urlData;
}...
} else if (typeof auth != 'string') {
if (!cb && typeof auth == 'function') {
cb = auth;
}
auth = null;
}
var urlData = this.createUrlData();
var path = this.createFullPath('/' + id, urlData);
return this.wrapTimeout(new Promise((function(resolve, reject) {
if (isNull) {
// Reset metadata:
sendMetadata(null, auth);
} else if (!isObject) {
...initialize = function () {}n/a
wrapTimeout = function (promise, callback) {
if (callback) {
// Ensure callback is called outside of promise stack.
return promise.then(function(res) {
setTimeout(function() { callback(null, res) }, 0);
}, function(err) {
setTimeout(function() { callback(err, null); }, 0);
});
}
return promise;
}...
}
auth = null;
}
var urlData = this.createUrlData();
var path = this.createFullPath('/' + id, urlData);
return this.wrapTimeout(new Promise((function(resolve, reject) {
if (isNull) {
// Reset metadata:
sendMetadata(null, auth);
} else if (!isObject) {
// Set individual metadata property:
var metadata = {};
metadata[key] = value;
...SubscriptionItems = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Subscriptions = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
create = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
The package needs to be configured with your account's secret key which is
available in your [Stripe Dashboard][api-keys]. Require it with the key's
value:
``` js
var stripe = require('stripe')('sk_test_...');
stripe.customers.create(
{ email: 'customer@example.com' },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
}
);
```
...deleteDiscount = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
return expect(
stripe.customers.retrieve(customer.id)
).to.eventually.have.deep.property('discount.coupon.id', coupon.id);
});
describe('The resulting discount', function() {
it('Can be removed', function() {
return expect(
stripe.customers.deleteDiscount(customer.id)
).to.eventually.have.property('deleted', true);
});
describe('Re-querying it', function() {
it('Does indeed indicate that it is deleted', function() {
return expect(
stripe.customers.retrieve(customer.id)
).to.eventually.have.deep.property('discount', null);
...update = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
customer = joined[1];
})
).to.not.be.eventually.rejected;
});
describe('And I apply the coupon to the customer', function() {
it('Does so', function() {
return expect(
stripe.customers.update(customer.id, {
coupon: coupon.id,
})
).to.not.be.eventually.rejected;
});
it('Can be retrieved from that customer', function() {
return expect(
stripe.customers.retrieve(customer.id)
...ThreeDSecure = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Tokens = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
TransferReversals = function () {
Super.apply(this, arguments);
}...
var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var TRANSFER_TEST_ID = 'transferIdTest999';
var REVERSAL_TEST_ID = 'reversalIdTest999';
// Create new CustomerCard instance with pre-filled customerId:
var transferReversal = new resources.TransferReversals(
stripe,
{transferId: TRANSFER_TEST_ID}
);
// Use spy from existing resource:
transferReversal._request = stripe.customers._request;
...extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
Transfers = function () {
Super.apply(this, arguments);
}n/a
extend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}...
_Error.extend = utils.protoExtend;
/**
* Create subclass of internal Error klass
* (Specifically for errors returned from Stripe's REST API)
*/
var StripeError = _Error.StripeError = _Error.extend({
type: 'StripeError',
populate: function(raw) {
// Move from prototype def (so it appears in stringified obj)
this.type = this.type;
this.stack = (new Error(raw.message)).stack;
this.rawType = raw.type;
...function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}n/a
cancel = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {metadata: {key: 'value'}},
});
});
});
describe('cancel', function() {
it('Sends the correct request', function() {
stripe.payouts.cancel(PAYOUT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payouts/' + PAYOUT_TEST_ID + '/cancel',
headers: {},
data: {},
});
});
...createReversal = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}n/a
listReversals = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}n/a
listTransactions = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
headers: {},
});
});
});
describe('listTransactions', function() {
it('Sends the correct request', function() {
stripe.balance.listTransactions();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/balance/history',
data: {},
headers: {},
});
});
...retrieveReversal = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
* requires a transferId, and therefore each of its methods only
* require the reversalId argument.
*
* This streamlines the API specifically for the case of accessing reversals
* on a returned transfer object.
*
* E.g. transferObject.reversals.retrieve(reversalId)
* (As opposed to the also-supported stripe.transfers.retrieveReversal(transferId,
* reversalId))
*/
module.exports = StripeResource.extend({
path: 'transfers/{transferId}/reversals',
includeBasic: ['create', 'list', 'retrieve', 'update'],
});
...reverse = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}...
data: {},
});
});
});
describe('reverse', function() {
it('Sends the correct request', function() {
stripe.transfers.reverse('transferId4');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/transfers/transferId4/reversals',
headers: {},
data: {},
});
});
...updateReversal = function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] == 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function(resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (param == 'id' && typeof arg !== 'string') {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: "id" must be a string, but got: ' + typeof arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to `' + requestMethod + ' ' + path + '`)'
);
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
);
reject(err);
return;
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
};
var options = {headers: objectAssign(opts.headers, spec.headers)};
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
}n/a
arrayToObject = function (arr) {
if (Array.isArray(arr)) {
var obj = {};
arr.map(function(item, i) {
obj[i.toString()] = item;
});
return obj;
}
return arr;
}...
});
expect(args.length).to.equal(0);
});
});
describe('arrayToObject', function() {
it('handles an empty array', function() {
expect(utils.arrayToObject([])).to.deep.equal({});
});
it('handles an array of integers', function() {
var arr = [1, 3];
expect(utils.arrayToObject(arr)).to.deep.equal({'0': 1, '1': 3});
});
it('ignores passes non-array data through', function() {
var arr = '3';
...getDataFromArgs = function (args) {
if (args.length > 0) {
if (isPlainObject(args[0]) && !utils.isOptionsHash(args[0])) {
return args.shift();
}
}
return {};
}...
reject(err);
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
...getOptionsFromArgs = function (args) {
var opts = {
auth: null,
headers: {},
}
if (args.length > 0) {
var arg = args[args.length - 1];
if (utils.isAuthKey(arg)) {
opts.auth = args.pop();
} else if (utils.isOptionsHash(arg)) {
var params = args.pop();
if (params.api_key) {
opts.auth = params.api_key;
}
if (params.idempotency_key) {
opts.headers['Idempotency-Key'] = params.idempotency_key;
}
if (params.stripe_account) {
opts.headers['Stripe-Account'] = params.stripe_account;
}
}
}
return opts;
}...
return;
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var path = this.createResourcePathWithSymbols(spec.path);
var err = new Error(
'Stripe: Unknown arguments (' + args + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' +
' (on API request to ' + requestMethod + ' `' + path + '`)'
...isAuthKey = function (key) {
return typeof key == 'string' && /^(?:[a-z]{2}_)?[A-z0-9]{32}$/.test(key);
}...
getOptionsFromArgs: function(args) {
var opts = {
auth: null,
headers: {},
}
if (args.length > 0) {
var arg = args[args.length - 1];
if (utils.isAuthKey(arg)) {
opts.auth = args.pop();
} else if (utils.isOptionsHash(arg)) {
var params = args.pop();
if (params.api_key) {
opts.auth = params.api_key;
}
if (params.idempotency_key) {
...isOptionsHash = function (o) {
return isPlainObject(o) && ['api_key', 'idempotency_key', 'stripe_account'].some(function(key) {
return o.hasOwnProperty(key);
});
}...
}()),
/**
* Return the data argument from a list of arguments
*/
getDataFromArgs: function(args) {
if (args.length > 0) {
if (isPlainObject(args[0]) && !utils.isOptionsHash(args[0])) {
return args.shift();
}
}
return {};
},
/**
...function makeURLInterpolator(str) {
var cleanString = str.replace(/["\n\r\u2028\u2029]/g, function($0) {
return rc[$0];
});
return function(outputs) {
return cleanString.replace(/\{([\s\S]+?)\}/g, function($0, $1) {
return encodeURIComponent(outputs[$1] || '');
});
};
}...
* optionally passed through a hash (Object) as the penultimate argument
* (preceding the also-optional callback argument
* @param [spec.encode] Function for mutating input parameters to a method.
* Usefully for applying transforms to data on a per-method basis.
*/
function stripeMethod(spec) {
var commandPath = typeof spec.path == 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function(data) {return data;};
return function() {
var self = this;
var args = [].slice.call(arguments);
...protoExtend = function (sub) {
var Super = this;
var Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor : function() {
Super.apply(this, arguments);
};
Constructor.prototype = Object.create(Super.prototype);
for (var i in sub) {
if (hasOwn.call(sub, i)) {
Constructor.prototype[i] = sub[i];
}
}
for (i in Super) {
if (hasOwn.call(Super, i)) {
Constructor[i] = Super[i];
}
}
return Constructor;
}n/a
stringifyRequestData = function (data) {
return qs.stringify(data, {arrayFormat: 'brackets'});
}...
_request: function(method, path, data, auth, options, callback) {
var self = this;
var requestData;
if (self.requestDataProcessor) {
requestData = self.requestDataProcessor(method, data, options.headers);
} else {
requestData = utils.stringifyRequestData(data || {});
}
var apiVersion = this._stripe.getApiField('version');
var headers = {
// Use specified auth token or use default from this stripe instance:
'Authorization': auth ?
...