Quickbooks Payments

Quickbooks

constructor
 Quickbooks() 

Option name Type Description
consumerKey
  • application key
consumerSecret
  • application password
token
  • the OAuth generated user-specific key
tokenSecret
  • the OAuth generated user-specific password
realmId
  • QuickBooks companyId, returned as a request parameter when the user is redirected to the provided callback URL following authentication
useSandbox
debug
  • boolean flag to turn on logging of HTTP requests, including headers and body

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 **********************

createToken

method
 Quickbooks.prototype.createToken() 

Option name Type Description
card
  • the user's credit card information
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)
}

getCharge

method
 Quickbooks.prototype.getCharge() 

Option name Type Description
chargeId string
  • of previously created charge
callback
  • Callback function which is called with any error or the Charge

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)
}

charge

method
 Quickbooks.prototype.charge() 

Option name Type Description
charge object
  • details, amount, currency etc. of charge to be processed
callback
  • Callback function which is called with any error or the saved Charge

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)
}

capture

method
 Quickbooks.prototype.capture() 

Option name Type Description
chargeId string
  • of previously created charge
charge object
  • details, amount, currency to capture
callback
  • Callback function which is called with any error or the capture description

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)
}

getChargeRefund

method
 Quickbooks.prototype.getChargeRefund() 

Option name Type Description
chargeId string
  • id of previously created charge
refundId string
  • id of previously created Refund
callback
  • Callback function which is called with any error or the Refund

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)
}

refundCharge

method
 Quickbooks.prototype.refundCharge() 

Option name Type Description
chargeId string
  • of previously created charge
refund object
  • details, amount, currency to refund
callback
  • Callback function which is called with any error or the refund description

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)
}

bankAccounts

method
 Quickbooks.prototype.bankAccounts() 

Option name Type Description
customerId string
  • id of customer
callback
  • Callback function which is called with any error or the list of Bank Accounts

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)
}

bankAccount

method
 Quickbooks.prototype.bankAccount() 

Option name Type Description
customerId string
  • id of customer
bankAccountId string
  • id of Bank Account
callback
  • Callback function which is called with any error or the Bank Account

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)
}

createBankAccount

method
 Quickbooks.prototype.createBankAccount() 

Option name Type Description
customerId string
  • id of customer
bankAccount string
  • Bank Account
callback
  • Callback function which is called with any error or the Bank Account

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)
}

createBankAccountFromToken

method
 Quickbooks.prototype.createBankAccountFromToken() 

Option name Type Description
customerId string
  • id of customer
bankAccount string
  • Bank Account
callback
  • Callback function which is called with any error or the Bank Account

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)
}

deleteBankAccount

method
 Quickbooks.prototype.deleteBankAccount() 

Option name Type Description
customerId string
  • id of customer
bankAccountId string
  • id of Bank Account
callback
  • Callback function which is called with any error or the Bank Account

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)
}

cards

method
 Quickbooks.prototype.cards() 

Option name Type Description
customerId string
  • id of customer
callback
  • Callback function which is called with any error or the list of Cards

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)
}

bankAccount

method
 Quickbooks.prototype.bankAccount() 

Option name Type Description
customerId string
  • id of customer
cardId string
  • id of Card
callback
  • Callback function which is called with any error or the Card

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)
}

createCard

method
 Quickbooks.prototype.createCard() 

Option name Type Description
customerId string
  • id of customer
card string
  • Card
callback
  • Callback function which is called with any error or the Card

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)
}

createCardFromToken

method
 Quickbooks.prototype.createCardFromToken() 

Option name Type Description
customerId string
  • id of customer
card string
  • Card
callback
  • Callback function which is called with any error or the Card

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)
}

deleteCard

method
 Quickbooks.prototype.deleteCard() 

Option name Type Description
customerId string
  • id of customer
cardId string
  • id of Card
callback
  • Callback function which is called with any error or the Card

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)
}

getEcheck

method
 Quickbooks.prototype.getEcheck() 

Option name Type Description
echeckId string
  • of previously created Echeck
callback
  • Callback function which is called with any error or the Echeck

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)
}

echeck

method
 Quickbooks.prototype.echeck() 

Option name Type Description
echeck object
  • details, amount, currency etc. of charge to be processed
callback
  • Callback function which is called with any error or the saved Echeck

Process an Echeck.

Quickbooks.prototype.echeck = function(echeck, callback) {
  module.request(this, 'post', {
    url: '/payments/echecks',
    headers: {
      'Company-Id': this.realmId
    }
  }, echeck, callback)
}

getEcheckRefund

method
 Quickbooks.prototype.getEcheckRefund() 

Option name Type Description
echeckId string
  • id of previously created echeck
refundId string
  • id of previously created Refund
callback
  • Callback function which is called with any error or the Refund

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)
}

refundEcheck

method
 Quickbooks.prototype.refundEcheck() 

Option name Type Description
echeckId string
  • of previously created echeck
refund object
  • details, amount, currency to refund
callback
  • Callback function which is called with any error or the refund description

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
  }
}