Skip to content

Commit

Permalink
Merge 1f6cbb5 into 1d033ac
Browse files Browse the repository at this point in the history
  • Loading branch information
Zertz committed Jan 1, 2018
2 parents 1d033ac + 1f6cbb5 commit 314d176
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2,287 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: node_js
node_js:
- "8"
- "6"
- "4"
- "node"
sudo: false
before_install:
- npm i stripe@^4.0.0
- npm i stripe@^5.0.0
script:
- npm run lint
- npm run test-coverage
after_script:
- npm install coveralls@^2.0.0 && cat ./coverage/lcov.info | coveralls
- npm install coveralls@^3.0.0 && cat ./coverage/lcov.info | coveralls
51 changes: 27 additions & 24 deletions lib/stripe-chainable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict'

const _ = require('lodash')
const isFunction = require('lodash.isfunction')
const isNumber = require('lodash.isnumber')
const isString = require('lodash.isstring')
const omit = require('lodash.omit')
const inflection = require('inflection')

function StripeChainable (key, version) {
Expand Down Expand Up @@ -37,7 +40,7 @@ StripeChainable.prototype = {
return this.all()
},
for: function (value) {
if (!value || !_.isString(value)) {
if (!value || !isString(value)) {
throw new Error('for() must be called with an account id, charge id, customer id or file upload purpose')
}

Expand Down Expand Up @@ -67,7 +70,7 @@ StripeChainable.prototype = {
return this
},
last: function (limit) {
if (!limit || !_.isNumber(limit)) {
if (!limit || !isNumber(limit)) {
throw new Error('last() must be called with a numeric value')
}

Expand All @@ -88,7 +91,7 @@ StripeChainable.prototype = {
return this
},
are: function (status) {
if (!status || !_.isString(status)) {
if (!status || !isString(status)) {
throw new Error('are() must be called with a status string')
}

Expand All @@ -99,7 +102,7 @@ StripeChainable.prototype = {
return this
},
type: function (type) {
if (!type || !_.isString(type)) {
if (!type || !isString(type)) {
throw new Error('type() must be called with an event type')
}

Expand Down Expand Up @@ -127,7 +130,7 @@ StripeChainable.prototype = {

this._stripeOptions[key] = this._stripeOptions[key] || {}
this._stripeOptions[key].lt = Math.ceil(before.getTime() / 1000)
} else if (_.isString(before) && before.indexOf('_') === 2) {
} else if (isString(before) && before.indexOf('_') === 2) {
this._stripeOptions.ending_before = before
} else {
throw new Error('before() must be called with a Stripe object id or Date object')
Expand All @@ -149,7 +152,7 @@ StripeChainable.prototype = {

this._stripeOptions[key] = this._stripeOptions[key] || {}
this._stripeOptions[key].gt = Math.floor(after.getTime() / 1000)
} else if (_.isString(after) && after.indexOf('_') === 2) {
} else if (isString(after) && after.indexOf('_') === 2) {
this._stripeOptions.starting_after = after
} else {
throw new Error('after() must be called with a Stripe object id or Date object')
Expand Down Expand Up @@ -258,7 +261,7 @@ StripeChainable.prototype = {
this._chain.push('charges')
this._options.type = 'charge'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -268,7 +271,7 @@ StripeChainable.prototype = {
this._chain.push('customers')
this._options.type = 'customer'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -278,7 +281,7 @@ StripeChainable.prototype = {
this._chain.push('plans')
this._options.type = 'plan'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -288,7 +291,7 @@ StripeChainable.prototype = {
this._chain.push('subscriptions')
this._options.type = 'subscription'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -298,7 +301,7 @@ StripeChainable.prototype = {
this._chain.push('coupons')
this._options.type = 'coupon'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -308,7 +311,7 @@ StripeChainable.prototype = {
this._chain.push('invoices')
this._options.type = 'invoice'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -318,7 +321,7 @@ StripeChainable.prototype = {
this._chain.push('invoiceItems')
this._options.type = 'invoiceItem'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -328,7 +331,7 @@ StripeChainable.prototype = {
this._chain.push('transfers')
this._options.type = 'transfer'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -338,7 +341,7 @@ StripeChainable.prototype = {
this._chain.push('applicationFees')
this._options.type = 'applicationFee'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -348,7 +351,7 @@ StripeChainable.prototype = {
this._chain.push('accounts')
this._options.type = 'account'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -358,7 +361,7 @@ StripeChainable.prototype = {
this._chain.push('events')
this._options.type = 'event'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -368,7 +371,7 @@ StripeChainable.prototype = {
this._chain.push('bitcoinReceivers')
this._options.type = 'bitcoinReceiver'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

Expand All @@ -378,15 +381,15 @@ StripeChainable.prototype = {
this._chain.push('fileUploads')
this._options.type = 'fileUpload'

if (_.isFunction(progress)) {
if (isFunction(progress)) {
return this.please(progress, callback)
}

return this
},
// Execute
list: function (progress, callback) {
if (!_.isFunction(callback)) {
if (!isFunction(callback)) {
callback = progress
progress = function () {}
}
Expand Down Expand Up @@ -432,7 +435,7 @@ StripeChainable.prototype = {
if (objects.has_more && (options.retrieveAll || stripeOptions.limit > 100)) {
getObjects(data)
} else {
objects = _.omit(objects, 'data')
objects = omit(objects, 'data')
objects.data = data

this._reset()
Expand All @@ -446,7 +449,7 @@ StripeChainable.prototype = {
return this
},
listTransactions: function (progress, callback) {
if (!_.isFunction(callback)) {
if (!isFunction(callback)) {
callback = progress
progress = function () {}
}
Expand Down Expand Up @@ -489,7 +492,7 @@ StripeChainable.prototype = {
if (objects.has_more && (options.retrieveAll || stripeOptions.limit > 100)) {
getObjects(data)
} else {
objects = _.omit(objects, 'data')
objects = omit(objects, 'data')
objects.data = data

this._reset()
Expand Down

0 comments on commit 314d176

Please sign in to comment.