IMPORTANT: this is work in progress.
This module implements Redecard (former VisaNet) WebSevice Komerci for Node.js.
Redecard is 2nd largest Brazilian credit card processor.
- MasterCard®, Diners and Visa® credit cards. Debit cards, such as Visa Electron, are not accepted.
- Pre-authorization or full authorization
- Splitting total amount into several installments
- Additional installment fee applied to either merchant or the user
- Support for Airline Companies, Hotels and Car Rental merchants (untested)
- Parameter names and return values in English
- Normal POST over HTTPS, no SOAP
- Automatic retries
- Configuration files for request/response field mapping, data type conversion and validation
- Redecard test environment supported
- Online tests
- Evens out some inconsistencies in Redecard API
- Clean and maintainable code
var redecard = require('redecard')
, merchant = new redecard.Instance('test', 'john.doe', 'secret')
, details = { amount: 0.01
, type: redecard.TYPES.FULL_PAYMENT
, installments: 0
, supplierId: '36483184'
, orderId: 'ORDER001'
, cardNumber: '4111111111111111'
, cardCode: '123'
, cardExpMonth: 1
, cardExpYear: 2016
, cardFullName: 'JOHN DOE'
}
merchant.getAuthorized(details, function(err, data) {
if(err) throw(err)
if(data.isApproved) {
// transaction approved, confirm it
var confirmationDetails =
{ date: data.date
, uniqSeq: data.uniqSeq
, receiptId: data.receiptId
, authorizationId: data.authorizationId
, installments: details.installments
, type: details.type
, amount: details.amount
, supplierId: details.supplierId
, orderId: details.orderId
}
merchant.confirmTxn(
confirmationDetails, function(err, data) {
if(err) throw(err)
// data.code should be one of:
// redecard.CONFIRMATION_CODES.OK
// redecard.CONFIRMATION_CODES.ALREADY_CONFIRMED
// redecard.CONFIRMATION_CODES.TRX_UNDONE
// TRX_UNDONE means that more than 2 minutes have passed
// before confirmation was sent.
}
)
} else {
// transaction NOT approved
}
}GetAuthorized takes two parameters: a hash of arguments and a callback.
| Field | Type | Required? | Max. length | Original Redecard Field | Description |
|---|---|---|---|---|---|
| amount | money | Yes | 10 | TOTAL | Sales total amount |
| type | zpad2 | Yes | 2 | TRANSACAO | Transaction type code |
| installments | zpad2 | Yes | 2 | PARCELAS | Number of installments |
| supplierId | zpad9 | Yes | 9 | FILIACAO | Supplying store membership number |
| orderId | string | Yes | 16 | NUMPEDIDO | Order number generated by the merchant |
| cardNumber | digits | Yes | 16 | NRCARTAO | Card number |
| cardCode | digits | Yes | 3 | CVC2 | Card CVC2 |
| cardExpMonth | month | Yes | 2 | MES | Card expiration month |
| cardExpYear | year | Yes | 2 | ANO | Card expiration year |
| cardFullName | string | Yes | 50 | PORTADOR | Cardholder name |
| iata | string | Yes | 9 | IATA | Airline: IATA code |
| distributorId | string | Yes | 9 | DISTRIBUIDOR | Membership number of distributing store / card issuer, when B2B |
| concentradorId | string | Yes | 5 | CONCENTRADOR | N/A – Send parameter blank |
| boardingFee | money | Yes | 10 | TAXAEMBARQUE | Airline: Boarding fee |
| checkinFee | money | Yes | 10 | ENTRADA | Airline: Check-in fee |
| docNum1 | string | Yes | 16 | NUMDOC1 | Airline: ticket number of the main passenger |
| docNum2 | string | Yes | 16 | NUMDOC2 | Airline: ticket number of the second passenger |
| docNum3 | string | Yes | 16 | NUMDOC3 | Airline: ticket number of the third passenger |
| docNum4 | string | Yes | 16 | NUMDOC4 | Airline: ticket number of the fourth passenger |
| pax1 | string | Yes | 26 | PAX1 | Airline: The name of the main passenger |
| pax2 | string | Yes | 26 | PAX2 | Airline: The name of the second passenger |
| pax3 | string | Yes | 26 | PAX3 | Airline: The name of the third passenger |
| pax4 | string | Yes | 26 | PAX4 | Airline: The name of the fourth passenger |
| autoConfirm | boolean | Yes | 1 | CONFTXN | Auto-confirm transaction? |
| addDataTst | string | Yes | 0 | ADDData | Only for Airline Companies, Hotels and Car Rental merchants |
| additionalData | string | Yes | 0 | ADD_Data | Only for Airline Companies, Hotels and Car Rental merchants |
Callback function receives ```err``` and a hash of return values.
| Field | Type | Original Redecard Field | Description |
|---|---|---|---|
| code | integer | CODRET | Return code |
| message | urlencoded | MSGRET | Return code description |
| date | date | DATA | Transaction date |
| orderId | string | NUMPEDIDO | Order number |
| authorizationId | string | NUMAUTOR | Authorization number |
| receiptId | string | NUMCV | Sales receipt number |
| authenticationId | string | NUMAUTENT | Authentication number |
| uniqSeq | string | NUMSQN | Unique sequential number |
| countryCode | string | ORIGEM_BIN | Code of issuer country, 2-letter or 3-letter ISO country code |
| distributorId | string | DISTRIBUIDOR | Membership number of distributor / cardholder, when B2B |
| iata | string | IATA | IATA |
| autoConfirmCode | integer | CONFCODRET | Automatic confirmation return code |
| autoConfirmMessage | urlencoded | CONFMSGRET | Return code description |
| expires | date | DATA_EXPI | Pre-authorization expiration date |
| _xml | string | _xml | Unparsed XML response (for debugging) |
ConfirmTxn takes two parameters: a hash of arguments and a callback.
| Field | Type | Required? | Max. length | Original Redecard Field | Description |
|---|---|---|---|---|---|
| date | date | Yes | 8 | DATA | Transaction date |
| uniqSeq | string | Yes | 12 | NUMSQN | Unique sequential number |
| receiptId | string | Yes | 9 | NUMCV | Sales receipt number |
| authorizationId | string | Yes | 6 | NUMAUTOR | Authorization number |
| installments | zpad2 | Yes | 2 | PARCELAS | Number of installments |
| type | zpad2 | Yes | 2 | TRANSORIG | Transaction type code |
| amount | money | Yes | 10 | TOTAL | Sales total amount |
| supplierId | zpad9 | Yes | 9 | FILIACAO | Supplying store membership number |
| distributorId | string | Yes | 9 | DISTRIBUIDOR | Membership number of distributing store / card issuer, when B2B |
| orderId | string | Yes | 16 | NUMPEDIDO | Order number generated by the merchant |
| docNum1 | string | Yes | 16 | NUMDOC1 | Airline: ticket number of the main passenger |
| docNum2 | string | Yes | 16 | NUMDOC2 | Airline: ticket number of the second passenger |
| docNum3 | string | Yes | 16 | NUMDOC3 | Airline: ticket number of the third passenger |
| docNum4 | string | Yes | 16 | NUMDOC4 | Airline: ticket number of the fourth passenger |
| pax1 | string | Yes | 26 | PAX1 | Airline: The name of the main passenger |
| pax2 | string | Yes | 26 | PAX2 | Airline: The name of the second passenger |
| pax3 | string | Yes | 26 | PAX3 | Airline: The name of the third passenger |
| pax4 | string | Yes | 26 | PAX4 | Airline: The name of the fourth passenger |
| additionalData | string | Yes | 0 | AddData | Only for Airline Companies, Hotels and Car Rental merchants |
Callback function receives ```err``` and a hash of return values.
| Field | Type | Original Redecard Field | Description |
|---|---|---|---|
| code | integer | CODRET | Return code |
| message | string | MSGRET | Return message |
| orderId | string | NUMPEDIDO | Order number |
| _xml | string | _xml | Unparsed XML response (for debugging) |