ghost-payment-service
Advanced tools
Comparing version 1.1.7 to 1.2.0
@@ -5,2 +5,3 @@ 'use strict'; | ||
const _ = require('lodash'); | ||
const moment = require('moment'); | ||
@@ -13,3 +14,3 @@ const AbstractGhostPaymentService = require('../AbstractGhostPaymentService'); | ||
class AuthorizeNetService extends AbstractGhostPaymentService { | ||
/** | ||
@@ -20,3 +21,3 @@ * @param {GhostPaymentService_AuthorizeNetConfig} options | ||
super(); | ||
this._authorizeCIM = new AuthorizeCIM({ | ||
@@ -27,3 +28,3 @@ api: options.apiLoginId, | ||
}); | ||
this._authorizeClient = new AuthorizeNet({ // https://github.com/continuous-software/node-authorize-net | ||
@@ -35,3 +36,3 @@ API_LOGIN_ID: options.apiLoginId, | ||
} | ||
/** | ||
@@ -54,3 +55,3 @@ * @param {object} data | ||
} | ||
/** | ||
@@ -75,3 +76,3 @@ * @param {object} data | ||
let billingAddress, card; | ||
return Promise.resolve() | ||
@@ -86,3 +87,3 @@ .then(() => { | ||
return new Promise((resolve, reject) => { | ||
const paymentProfile = { | ||
@@ -93,3 +94,3 @@ customerType: 'business', | ||
}; | ||
this._authorizeCIM.createCustomerPaymentProfile({ | ||
@@ -113,3 +114,3 @@ customerProfileId: data.customerId, | ||
} | ||
/** | ||
@@ -128,5 +129,5 @@ * @param {object} data | ||
this._authorizeClient.chargeCustomer( | ||
{ amount: (data.amount / 100).toFixed(2) }, | ||
{ profileId: data.customerId }, | ||
{ customerPaymentProfileId: data.source || data.cardId } | ||
{ amount: (data.amount / 100).toFixed(2) }, | ||
{ profileId: data.customerId }, | ||
{ customerPaymentProfileId: data.source || data.cardId } | ||
) | ||
@@ -140,3 +141,3 @@ .then(result => { | ||
} | ||
/** | ||
@@ -156,3 +157,3 @@ * @param {object} data | ||
}); | ||
this._authorizeCIM.createCustomerProfile({ customerProfile: Customer }, (err, response) => { | ||
@@ -170,3 +171,3 @@ if (err) reject(err); | ||
} | ||
/** | ||
@@ -189,3 +190,3 @@ * @param {object} data | ||
} | ||
/** | ||
@@ -200,3 +201,3 @@ * @param {object} data | ||
} | ||
/** | ||
@@ -218,12 +219,38 @@ * @param {object} data | ||
/** | ||
* @param {object} data | ||
* @param {String} data.amount | ||
* @param {String} data.paymentId | ||
* @param {String} data.createdAt | ||
* @return Promise | ||
*/ | ||
refundTransaction (data = {}) { | ||
return new Promise((resolve, reject) => { | ||
const options = { | ||
amount: data.amount, | ||
expirationMonth: 'XX', | ||
expirationYear: 'XXXX' | ||
}; | ||
this._authorizeClient.refundTransaction( data.paymentId, options ) | ||
.then(result => resolve(result)) | ||
.catch(err => { | ||
if (moment(data.createdAt).add('2', 'days').isAfter(moment()) && err.message == 'The referenced transaction does not meet the criteria for issuing a credit.') { | ||
return resolve(this._authorizeClient.voidTransaction(data.paymentId)); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}) | ||
} | ||
/** | ||
* @param {[object]} errors | ||
* @return {String} | ||
*/ | ||
static _buildChargeError(errors) { | ||
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; | ||
} | ||
_validateBillingAddress (data = {}) { | ||
return Promise.resolve() | ||
@@ -237,3 +264,3 @@ .then(() => { | ||
if (!data.zip) throw new Error('Missing billing address zip.'); | ||
return new Types.BillingAddress({ | ||
@@ -250,3 +277,3 @@ firstName: data.firstName, | ||
} | ||
_validateCard (data = {}) { | ||
@@ -259,3 +286,3 @@ return Promise.resolve() | ||
if (!data.cvc) throw new Error('Missing card CVC.'); | ||
return new Types.CreditCard({ | ||
@@ -268,5 +295,5 @@ cardNumber: data.number, | ||
} | ||
} | ||
module.exports = AuthorizeNetService; |
{ | ||
"name": "ghost-payment-service", | ||
"version": "1.1.7", | ||
"version": "1.2.0", | ||
"description": "nodejs client to interact with the authorize.net & stripe apis", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "NODE_ENV=test mocha ./test --recursive" | ||
"test": "NODE_ENV=test mocha ./test --recursive", | ||
"test:grep": "NODE_ENV=test mocha ./test --grep" | ||
}, | ||
@@ -31,2 +32,3 @@ "repository": { | ||
"lodash": "^4.17.2", | ||
"moment": "~2.9.0", | ||
"stripe": "^4.9.0" | ||
@@ -33,0 +35,0 @@ }, |
@@ -14,2 +14,3 @@ const Chai = require('chai'); | ||
let customer; | ||
let transaction; | ||
let token; | ||
@@ -22,20 +23,20 @@ let service; | ||
describe('StripeService', () => { | ||
before(() => { | ||
return stripeSetup.setupCustomer() | ||
.tap(_customer_ => customer = _customer_) | ||
.then(_customer_ => stripeSetup.setupCard({ customerId: _customer_.id })) | ||
.then(() => stripeSetup.setupCard({ customerId: customer.id })) | ||
.then(() => stripeSetup.setupCard({ customerId: customer.id })) | ||
.tap(_card_ => card = _card_) | ||
.then(_card_ => stripeSetup.setupToken()) | ||
.tap(_token_ => token = _token_) | ||
.then(() => service = new GhostPaymentService({ | ||
processor: 'stripe', | ||
stripe: Config.get('stripe') | ||
})) | ||
}); | ||
return stripeSetup.setupCustomer() | ||
.tap(_customer_ => customer = _customer_) | ||
.then(_customer_ => stripeSetup.setupCard({ customerId: _customer_.id })) | ||
.then(() => stripeSetup.setupCard({ customerId: customer.id })) | ||
.then(() => stripeSetup.setupCard({ customerId: customer.id })) | ||
.tap(_card_ => card = _card_) | ||
.then(_card_ => stripeSetup.setupToken()) | ||
.tap(_token_ => token = _token_) | ||
.then(() => service = new GhostPaymentService({ | ||
processor: 'stripe', | ||
stripe: Config.get('stripe') | ||
})) | ||
}); | ||
describe('cards', () => { | ||
it('should create a card', () => { | ||
@@ -50,3 +51,3 @@ return service.createCard({ card: cardData, customerId: customer.id }) | ||
}); | ||
it('should get a customers card', () => { | ||
@@ -60,3 +61,3 @@ return service.getCard({ customerId: customer.id, cardId: card.id }) | ||
}); | ||
it('should list a customers cards', () => { | ||
@@ -70,3 +71,3 @@ return service.getCards({ customerId: customer.id }) | ||
}); | ||
it('should delete a card', () => { | ||
@@ -87,5 +88,5 @@ return service.deleteCard({ cardId: card.id, customerId: customer.id }) | ||
}); | ||
describe('charges', () => { | ||
it('should create a charge', () => { | ||
@@ -103,8 +104,8 @@ return service.createCharge({ | ||
}); | ||
}); | ||
}); | ||
describe('customers', () => { | ||
it('should create a customer', () => { | ||
@@ -117,3 +118,3 @@ return service.createCustomer({ description: `Test Profile` }) | ||
}); | ||
it('should get a customer', () => { | ||
@@ -126,3 +127,3 @@ return service.getCustomer({ customerId: customer.id }) | ||
}); | ||
it('should update a customer', () => { | ||
@@ -140,3 +141,3 @@ const customerCopy = { | ||
}); | ||
it('should delete a customer', () => { | ||
@@ -149,7 +150,7 @@ return service.deleteCustomer({ customerId: customer.id }) | ||
}); | ||
}); | ||
describe('AuthorizeNetService', () => { | ||
before(() => { | ||
@@ -170,6 +171,12 @@ return authorizeNetSetup.setupCustomer() | ||
})) | ||
.then(() => service.createCharge({ | ||
amount: 100, | ||
customerId: customer.customerProfileId, | ||
cardId: customer.paymentProfiles.customerPaymentProfileId | ||
})) | ||
.then(_transaction_ => transaction = _transaction_) | ||
}); | ||
describe('cards', () => { | ||
it('should get a customers card', () => { | ||
@@ -188,3 +195,3 @@ return service.getCard({ | ||
}); | ||
it('should list a customers cards', () => { | ||
@@ -204,3 +211,3 @@ return service.getCards({ customerId: customer.customerProfileId }) | ||
}); | ||
it('should create a card', () => { | ||
@@ -220,11 +227,27 @@ return service.createCard({ | ||
}); | ||
it('should delete a card', () => { | ||
// TODO | ||
}); | ||
}); | ||
describe('refundTransaction', () => { | ||
it('should void transaction', () => { | ||
return service.refundTransaction({ | ||
paymentId: transaction.transId, | ||
amount: 100, | ||
createdAt: transaction.createdAt | ||
}) | ||
.then(_refund_ => { | ||
expect(_refund_).to.exist; | ||
expect(_refund_._original.messages[0].message[0].description[0]).to.be.equal('This transaction has been approved.'); | ||
}) | ||
}); | ||
}); | ||
describe('charges', () => { | ||
it('should create a charge', () => { | ||
@@ -279,7 +302,7 @@ | ||
}); | ||
}); | ||
describe('customers', () => { | ||
it('should get a customer', () => { | ||
@@ -292,3 +315,3 @@ return service.getCustomer({ customerId: customer.customerProfileId }) | ||
}); | ||
it('should create a customer', () => { | ||
@@ -305,15 +328,15 @@ const newCustomer = { | ||
}); | ||
it('should update a customer', () => { | ||
}); | ||
it('should delete a customer', () => { | ||
}); | ||
}); | ||
}); | ||
}); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
36432
1065
7
1
+ Addedmoment@~2.9.0
+ Addedmoment@2.9.0(transitive)