ghost-payment-service
Advanced tools
Comparing version 1.0.0 to 1.0.1
'use strict'; | ||
const Promise = require('bluebird'); | ||
const _ = require('lodash'); | ||
@@ -121,2 +122,7 @@ const AbstractGhostPaymentService = require('../AbstractGhostPaymentService'); | ||
) | ||
.then(result => { | ||
if (!result._original || result._original.errors) reject(this._buildChargeError(result._original.errors)); | ||
resolve(_.mapValues(result._original, (val) => _.head(val))); // auth net returns an object where each value is an array, map to normal object | ||
}) | ||
.catch(err => reject('Unable to process transaction, please try again or contact support.')); | ||
}) | ||
@@ -195,2 +201,11 @@ } | ||
} | ||
/** | ||
* @param {[object]} errors | ||
* @return {String} | ||
*/ | ||
static _buildChargeError(errors) { | ||
if (!Array.isArray(errors) || !errors.length || !errors[0].error[0].errorText) return 'Unable to complete transaction.'; | ||
return errors[0].error[0].errorText; | ||
} | ||
@@ -197,0 +212,0 @@ _validateBillingAddress (data = {}) { |
@@ -9,3 +9,3 @@ 'use strict'; | ||
* @param {GhostPaymentService_AuthorizeNetConfig} options | ||
* @return {StripeService} | ||
* @return {AuthorizeNetService} | ||
*/ | ||
@@ -12,0 +12,0 @@ static create (options = {}) { |
{ | ||
"name": "ghost-payment-service", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "nodejs client to interact with the authorize.net & stripe apis", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -206,4 +206,50 @@ const Chai = require('chai'); | ||
it('should create a charge', () => { | ||
return service.createCharge({ | ||
amount: Chance.integer({ min: 100, max: 1000000 }), | ||
customerId: customer.customerProfileId, | ||
cardId: customer.paymentProfiles.customerPaymentProfileId | ||
}) | ||
.then(charge => { | ||
expect(charge).to.exist; | ||
expect(charge.transId).to.exist; | ||
}) | ||
}); | ||
it('should return an error when an incorrect customerId is provided', () => { | ||
return service.createCharge({ | ||
amount: Chance.integer({ min: 100, max: 1000000 }), | ||
customerId: 'fakecustomerid', | ||
cardId: customer.paymentProfiles.customerPaymentProfileId | ||
}) | ||
.then(charge => expect(charge).to.not.exist) | ||
.catch(err => expect(err).to.exist) | ||
}); | ||
it('should return an error when an incorrect amount is provided', () => { | ||
return service.createCharge({ | ||
amount: -10000, | ||
customerId: customer.customerProfileId, | ||
cardId: customer.paymentProfiles.customerPaymentProfileId | ||
}) | ||
.then(charge => expect(charge).to.not.exist) | ||
.catch(err => expect(err).to.exist) | ||
}); | ||
it('should return an error when an incorrect cardId is provided', () => { | ||
return service.createCharge({ | ||
amount: 10000, | ||
customerId: customer.customerProfileId, | ||
cardId: 'nocard' | ||
}) | ||
.then(charge => expect(charge).to.not.exist) | ||
.catch(err => expect(err).to.exist) | ||
}); | ||
@@ -210,0 +256,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32384
927