Node.js client for First Data Global Gateway e4 api.
Trying to provide a well documented & tested interaction with the First Data api. I have found many things that are undocumented and inconsistent hence the need for a place to gather some sanity.
Main goal is to provide proper handling for the various responses (first data gateway & banks).
Focus is on version 12+ by implementing the required SHA-1 HMAC hash security protocol. It should work with prior versions v9+ but currently not tested.
Some error codes are currently "untestable" within the integration test environment. This library covers significantly more response types then what is listed in the documentation or any other library. Many undocumented responses have been found thus far. (See Test section for more info).
- 100% test coverage
- Over 300 integration tests.
- Insane Error Handling
- 25 undocumented gateway response codes
- 33 undocumented bank response codes
- 23 bank responses with different names then in docs.
- 8 Additional custom codes to handle quirks.
- Reporting & Search API
- International Support: ~250 countries, ~150 currencies
- Accept: AmEx, Visa, Mastercard, Discover, Diners Club, JCB
- Magnetic Swipe (card in hand) support via api
- TransArmor Tokenization - token system that replaces CC numbers, greatly reducing your PCI requirements.
- Pre Authorization
- Partial Settlements - Charge what is available (not all or nothing)
- Recurring Billing
- Check processing with v13+
- Paypal Integration
- Gift Cards along with Virtual Gift Cards (must setup with your account)
- Soft Descriptors - ability to change processor info (must setup)
- 3-D Secure - optional extended security level (registration)
- Payment Type classification (ecommerce flag) - helps with rates
- Fine grain control over Fraud handling
- Level II & III processing options - ability to reduce rates and meet requirements of governments contracts.
- 3rd Party Processing options (Partner ID) v14+
- 24/7/365 instant live person support
npm install firstdata
Test Accounts are automatically provisioned, will remain active for 90 days with no activity. If you want a live account you must contact First Data directly.
- Setup a Test Account: http://www.firstdata.com/gg/apply_test_account.htm
- Receive email with credential
- Login to Admin**
- Go to the "Terminal Section"
- Click on the ECOMM Terminal it should expand (horrible ui).
- In the
Details
tab record:- GatewayID
- Password (click generate) - This is NOT the same password as your admin login
- Create a Transarmor Token (4 characters)
- Check
Allow Soft Descriptors
- Select
Support Level 2 Data and Level 3 Data
- In the
Api
tab record:- KeyId
- HMAC (click generate)
- make sure to hit the update button on the very bottom of the screen or else changes aren't saved.
** Note: You need to use Firefox for the login to work for some reason :(
var firstdata = require('firstdata')
, client = firstdata.createClient({
name: 'application name'
, version: 12
, key: '<your key id>'
, gateway_id: '<your gateway id>'
, password: '<password>'
, hmac: '<hmac string>'
, timeout: 3000
, admin: {username: '<username>', password: '<password>'} // search & report api
, sandbox: true });
client.purchase({
cardholder_name: "John Doe"
, cc_number: "4111111111111111"
, cc_expiry: "0515"
, amount: "38.95"
}, function(err, resp){
// See api below
});
Class for creating a First Data api client.
Class for creating a First Data response object. A Client
instance automatically return this. See Response Instance
Wrapper to create a firstdata.Client
instance.
options:
name
: name of your app - this shows up in the Admin Logs (optional, default="API-ExactID")version
: version of the api to use - valid values 8-14 (optional, default=12)key
: your keyID from admin for terminal you want to use (required)gateway_id
: your GatewayID from admin (required)password
: your terminal password - not your admin console login (required)hmac
: your HMAC generated string from admin console (required)timeout
: Prevent inactive sockets from hanging. Defaults to 3000ms (3 secs).admin
: optional object. Required to use search and report api.username
: username to login to your dashboardpassword
: password for accountversion
: 2 or 3. (optional). defaults to 3.
sandbox
: BOOL - if true uses testing environment (optional, default=false)
defaults:
Properties you would like to have set automatically with every transaction. Only a few actually make sense, for example:
{
cvd_presence_ind: 1 // handling of CVV2
, language: 'FR'
, currency_code: 'EUR'
, ecommerce_flag: 5 // Secure Electronic Commerce Transaction
, soft_descriptor: {
dba_name: "Doing Business As Company Name"
, street: "123 Main St."
, city: "Somewhere"
, region: 'CA'
, postal_code: '90120'
, country_code: 'US'
}
}
Note: gateway_id
& password
are required for every transaction and are automatically added to defaults. If name is defined in options it is also passed to defaults as user_name
helpful for filtering searches and aggergating reports.
Returns an instance of Client
Checks if a country code is
FirstData has several different types of transactions.
Regular
- Credit CardPayPal
- PayPalValueLink
- FirstData physical and virtual gift cards.TransArmor
- Token Replacement for easier PCI complianceTeleCheck
- Check processing
Generic wrapper for the API.
transaction_type: {String}
00
: Purchase01
: Pre-Authorization02
: Pre-Authorization Completion (Recommend 32 instead)04
: Refund13
: Void32
: Tagged Pre-Authorization Completion33
: Tagged Void34
: Tagged Refund07
: PayPal Order83
: CashOut - Gift Card85
: ValueLink Activation - Gift Card86
: Balance Inquiry - Gift Card88
: Reload - Gift Card89
: ValueLink Deactivation - Gift Card
transaction_type
is automatically added to request as '00'.
Regular Transaction required fields:
amount
cardholder_name
cc_number
cc_expiry
ValueLink Transaction required fields:
amount
cardholder_name
cc_number
credit_card_type
= 'Gift'
TransArmor Transaction required fields:
amount
cardholder_name
transarmor_token
cc_expiry
credit_card_type
= "American Express", "Visa", "Mastercard", "Discover", "Diners Club", "JCB", "Gift Card", "PayPal"
This object is frozen and read-only (immutable). : Trying to mutate will throw a TypeError
With the exception of search
& report
all methods return an instance of FirstDataResponse
.
It is important to note that regardless of errors gateway
& bank
responses are set. The following are the defaults if not found in response.
gateway
: is set to40
(Unable to Connect)bank
: is set to000
(No Answer)
req_headers
: {Object} HTTP headers users for the request.payload
: {String} Serialized JSON data sent to FirstData.headers
: {Object} HTTP headers received from FirstData response.raw
: {String} Original response body, regardless of parse errors.data
: {Object} Parsed body. See FirstData API docs for more info.statusCode
: {String} HTTP response status code.error
: {Error} - Could be undefined if no error occurred. ** See note below.gateway
{Object}code
: {String} FirstData Gateway response codemessage
: {String} Message explaining code.
bank
{Object}code
: {String} Bank response code.type
: {String} Type of response. * See type tablename
: {String} Name of responseaction
: {String} Action to take with response code. * See action tabledescription
: {String} Description of response.actual
: {String} (optional). This is the actual response name if it differs from FirstData documentation.
Bank Response Types
S
: SuccessfulR
: RejectD
: DeclineR\D
: Reject or DeclineU
: Unknown/Undocumented. Action is automatically set to 'Call'.
Bank Response Actions
Resend
: Send this transaction back at any time.Wait
: Wait 2-3 days before sending back, or try to resolve with your customerCust
: Try to resolve with customer, or get an alternate method of paymentFix
: There is an invalid field being sent Fix and resend.N/A
: Not applicableVoice
: Perform a voice authorization per First Data instructions.Call
: Call First Data.
FirstDataResponse
will explicitly create special error objects if the transactions don't meet specific criteria.
- If a network error occurs from
https.request
then the error object is return. (connection reset, socket timeout, unable to connect). - If no network error and gateway response !=
00
then aResponseError
is created. - If no network error or
ResponseError
andisSuccessful
== {false} then aBankError
is created.
Inherits from Error
var ResponseError = require('firstdata').errors.ResponseError;
var err = new ResponseError(obj);
err instanceof ResponseError; // true
err instanceof Error; // true
Properties
name
: 'FirstDataResponseError'code
: gateway response codemessage
: message for code
Inherits from Error
var BankError = require('firstdata').errors.BankError;
var err = new BankError(obj);
err instanceof BankError; // true
err instanceof Error; // true
Properties
name
: 'FirstDataBankResponseError'code
: bank response codetype
: type of response code (see chart below)action
: action to perform on response (see below)message
: message for codedescription
: description about the error code
Returns true if gateway code = 00
and bank response type = 'S'.
Requires the bank response to be S
(successful). In addition the payload must contain field transaction_approved
set to 1.
It is important to note that several bank responses will be successful yet will not pass the isApproved
test like (164) - 'Conditional Approval - Hold shipping for 24 hours'.
First Data returns csv. This
var search = firstdata.search({
start_date: '2014-07-12'
, end_date: '2014-07-15' }, function(err, data){
});
var search = firstdata.search({
start_date: '2014-07-12'
, end_date: '2014-07-15' });
search.on('data', function(data){
});
search.on('close', function(){
});
search.on('error', function(err){
});
This section describes how to use a magnetic card reader with the api.
** TODO **
** TODO **
** TODO **
** TODO **
The majority of the tests are integration tests with FirstData E4 Gateway. In order to test you must do the following:
- Setup a Test account (see Setup)
- Install mocha globally
npm install mocha -g
- Create
test/config.json
example:
{
"name": "test-api"
, "hmac": "<HMAC>"
, "key": "<KEY>"
, "gateway_id": "<GATEWAY_ID>"
, "password": "<API_PASSWORD>"
, "sandbox": true
, "admin": { "username": "<USERNAME>", "password": "<PASSWORD>"}
}
Run Tests with npm test
or mocha
- Gateway Response Codes
- Bank Response Code
- CVV codes
- AVS Codes
- HTTP Status codes
- Country Codes
- Currency Codes
- CVV Codes
- E-Commerce Flag Codes
- Tax Types
- Unit of Measure
(The MIT License)
Copyright (c) 2015 Nathan White [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.