Option name | Type | Description |
---|---|---|
consumerKey |
|
|
consumerSecret |
|
|
token |
|
|
tokenSecret |
|
|
realmId |
|
|
useSandbox | ||
debug |
|
Node.js client encapsulating access to the QuickBooks Payments API. An instance
of this class should be instantiated on behalf of each user accessing the api.
function Quickbooks(consumerKey, consumerSecret, token, tokenSecret, realmId, useSandbox, debug) {
var prefix = _.isObject(consumerKey) ? 'consumerKey.' : ''
this.consumerKey = eval(prefix + 'consumerKey')
this.consumerSecret = eval(prefix + 'consumerSecret')
this.token = eval(prefix + 'token')
this.tokenSecret = eval(prefix + 'tokenSecret')
this.realmId = eval(prefix + 'realmId')
this.useSandbox = eval(prefix + 'useSandbox')
this.debug = eval(prefix + 'debug')
this.endpoint = this.useSandbox ? Quickbooks.BASE_URL : Quickbooks.BASE_URL.replace('sandbox.', '')
}
// ********************** Charge Api **********************
Option name | Type | Description |
---|---|---|
card |
|
|
callback |
Create an opaque container that encapsulates a cardholder's credit card information or bank account information.
Quickbooks.prototype.createToken = function(card, callback) {
module.request(this, 'post', {
url: '/payments/tokens',
headers: {
'Company-Id': this.realmId
}
}, card, callback)
}
Option name | Type | Description |
---|---|---|
chargeId | string |
|
callback |
|
Get details of charge.
Quickbooks.prototype.getCharge = function(chargeId, callback) {
module.request(this, 'get', {
url: '/payments/charges/' + chargeId,
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
charge | object |
|
callback |
|
Process a credit card charge using card details or token.
Can capture funds or just authorize.
Quickbooks.prototype.charge = function(charge, callback) {
module.request(this, 'post', {
url: '/payments/charges',
headers: {
'Company-Id': this.realmId
}
}, charge, callback)
}
Option name | Type | Description |
---|---|---|
chargeId | string |
|
charge | object |
|
callback |
|
Allows you to capture funds for an existing charge that was intended to be captured at a later time.
Quickbooks.prototype.capture = function(chargeId, charge, callback) {
module.request(this, 'post', {
url: '/payments/charges/' + chargeId + '/capture',
headers: {
'Company-Id': this.realmId
}
}, charge, callback)
}
Option name | Type | Description |
---|---|---|
chargeId | string |
|
refundId | string |
|
callback |
|
Retrieves the Refund for the given refund id
Quickbooks.prototype.getChargeRefund = function(chargeId, refundId, callback) {
module.request(this, 'get', {
url: '/payments/charges/' + chargeId + '/refunds/' + refundId,
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
chargeId | string |
|
refund | object |
|
callback |
|
Allows you to refund an existing charge. Full and partial refund are supported.
Quickbooks.prototype.refundCharge = function(chargeId, refund, callback) {
module.request(this, 'post', {
url: '/payments/charges/' + chargeId + '/refunds',
headers: {
'Company-Id': this.realmId
}
}, refund, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
callback |
|
Retrieves a list of Bank Accounts for the customer
Quickbooks.prototype.bankAccounts = function(customerId, callback) {
module.request(this, 'get', {
url: '/payments/customers/' + customerId + '/bank-accounts',
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
bankAccountId | string |
|
callback |
|
Retrieves an individual Bank Account for a customer
Quickbooks.prototype.bankAccount = function(customerId, bankAccountId, callback) {
module.request(this, 'get', {
url: '/payments/customers/' + customerId + '/bank-accounts/' + bankAccountId,
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
bankAccount | string |
|
callback |
|
Create a new Bank Account for the customer
Quickbooks.prototype.createBankAccount = function(customerId, bankAccount, callback) {
module.request(this, 'post', {
url: '/payments/customers/' + customerId + '/bank-accounts',
headers: {
'Company-Id': this.realmId
}
}, bankAccount, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
bankAccount | string |
|
callback |
|
Create a new Bank Account for the customer
Quickbooks.prototype.createBankAccountFromToken = function(customerId, bankAccount, callback) {
module.request(this, 'post', {
url: '/payments/customers/' + customerId + '/bank-accounts/createFromToken',
headers: {
'Company-Id': this.realmId
}
}, bankAccount, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
bankAccountId | string |
|
callback |
|
Deletes an individual Bank Account for a customer
Quickbooks.prototype.deleteBankAccount = function(customerId, bankAccountId, callback) {
module.request(this, 'delete', {
url: '/payments/customers/' + customerId + '/bank-accounts/' + bankAccountId,
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
callback |
|
Retrieves a list of Cards for the customer
Quickbooks.prototype.cards = function(customerId, callback) {
module.request(this, 'get', {
url: '/payments/customers/' + customerId + '/cards',
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
cardId | string |
|
callback |
|
Retrieves an individual Card for a customer
Quickbooks.prototype.bankAccount = function(customerId, cardId, callback) {
module.request(this, 'get', {
url: '/payments/customers/' + customerId + '/cards/' + cardId,
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
card | string |
|
callback |
|
Create a new Card for the customer
Quickbooks.prototype.createCard = function(customerId, card, callback) {
module.request(this, 'post', {
url: '/payments/customers/' + customerId + '/cards',
headers: {
'Company-Id': this.realmId
}
}, card, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
card | string |
|
callback |
|
Create a new Card for the customer
Quickbooks.prototype.createCardFromToken = function(customerId, card, callback) {
module.request(this, 'post', {
url: '/payments/customers/' + customerId + '/cards/createFromToken',
headers: {
'Company-Id': this.realmId
}
}, card, callback)
}
Option name | Type | Description |
---|---|---|
customerId | string |
|
cardId | string |
|
callback |
|
Deletes an individual Card for a customer
Quickbooks.prototype.deleteCard = function(customerId, cardId, callback) {
module.request(this, 'delete', {
url: '/payments/customers/' + customerId + '/cards/' + cardId,
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
echeckId | string |
|
callback |
|
Get details of Echeck.
Quickbooks.prototype.getEcheck = function(echeckId, callback) {
module.request(this, 'get', {
url: '/payments/echecks/' + echeckId,
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
echeck | object |
|
callback |
|
Process an Echeck.
Quickbooks.prototype.echeck = function(echeck, callback) {
module.request(this, 'post', {
url: '/payments/echecks',
headers: {
'Company-Id': this.realmId
}
}, echeck, callback)
}
Option name | Type | Description |
---|---|---|
echeckId | string |
|
refundId | string |
|
callback |
|
Retrieves the Refund for the given refund id
Quickbooks.prototype.getEcheckRefund = function(echeckId, refundId, callback) {
module.request(this, 'get', {
url: '/payments/echecks/' + echeckId + '/refunds/' + refundId,
headers: {
'Company-Id': this.realmId
}
}, null, callback)
}
Option name | Type | Description |
---|---|---|
echeckId | string |
|
refund | object |
|
callback |
|
Allows you to refund an existing echeck. Full and partial refund are supported.
Quickbooks.prototype.refundEcheck = function(echeckId, refund, callback) {
module.request(this, 'post', {
url: '/payments/echecks/' + echeckId + '/refunds',
headers: {
'Company-Id': this.realmId
}
}, refund, callback)
}
module.request = function(context, verb, options, entity, callback) {
var url = context.endpoint + options.url
if (options.url === Quickbooks.RECONNECT_URL) {
url = options.url
}
var opts = {
url: url,
qs: options.qs || {},
headers: options.headers || {},
oauth: module.oauth(context),
json: true
}
opts.headers['Content-Type'] = 'application/json'
opts.headers['User-Agent'] = 'quickbooks4js: version ' + version
opts.headers['Request-Id'] = uuid.v1()
if (entity !== null) {
opts.body = entity
}
if ('production' !== process.env.NODE_ENV && context.debug) {
debug(request)
}
request[verb].call(context, opts, function (err, res, body) {
if ('production' !== process.env.NODE_ENV && context.debug) {
console.log('invoking endpoint: ' + url)
if (entity) console.log(entity)
console.log(util.inspect(err || body, {showHidden: false, depth: null}));
}
if (callback) {
if (err ||
res.statusCode >= 300 ||
(_.isObject(body) && body.Fault && body.Fault.Error && body.Fault.Error.length)) {
callback(err || body, body)
} else {
callback(null, body)
}
} else {
return
}
})
}
Quickbooks.prototype.reconnect = function(callback) {
module.request(this, 'get', {url: Quickbooks.RECONNECT_URL}, null, callback)
}
module.oauth = function(context) {
return {
consumer_key: context.consumerKey,
consumer_secret: context.consumerSecret,
token: context.token,
token_secret: context.tokenSecret
}
}