Open arvinkx opened 7 years ago
Thanks for the report, @arvinkx. We'll take a look on our end to see if we can reproduce this. Do you have a code snippet that calls into the library that we could review?
Here is where I am calling it, just FYI the documentation needs some work, there is no mention as to what developerId
or versionNumber
are but they seem to be required and none of the other SDKs seem to use them. Also, there are two versions of documentation on the HPS site - the one this repo links to doesn't seem to be the latest version (v1 instead of v2 - there also seems to be a v3).
'use strict';
const config = require('../config');
const heartland = require('heartland-nodejs');
const heartlandConfig = {
secretApiKey: config.HeartlandAPIKey,
versionNumber: '1234',
developerId: '123456'
};
const URL = "https://cert.api2.heartlandportico.com/hps.exchange.posgateway/posgatewayservice.asmx";
module.exports.chargeCreditCardToken = function(amount, token, purchaseID, cb) {
new heartland.HpsCreditService(heartlandConfig, URL).chargeWithToken(
amount,
'usd',
token,
null,
false,
purchaseID,
(err, response) => {
if (err) {
console.log("Error with payment validation: ", err);
cb(err);
return;
}
console.log("Heartland response: ", response);
}
);
};
@arvinkx Apologies for the delay. We definitely agree on the documentation, and we are actively working on improving it across the board. You can use this section of our documentation which applies to this SDK in its current form: https://developer.heartlandpaymentsystems.com/Documentation/v2/introduction.
The developerId
and versionNumber
properties on the config are required from an integration standpoint, so all integrations send these whether one of our SDKs are used or not. We typically cover how to set these when beginning our certification process as they are created and supplied at that time.
I wrote this quick sample script to simulate your code:
const heartland = require('heartland-nodejs');
const config = {
secretApiKey: 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A',
versionNumber: '0000',
developerId: '000000'
};
const url = 'https://cert.api2.heartlandportico.com/hps.exchange.posgateway/posgatewayservice.asmx';
function chargeCreditCardToken(amount, token, purchaseID, cb) {
console.log(token);
new heartland.HpsCreditService(config, url).chargeWithToken(
amount,
'usd',
token,
null,
false,
purchaseID,
(err, response) => {
if (err) {
console.log('error', err);
return;
}
console.log('response', response);
}
);
}
// here down just grabs a single-use token and executes the above function
const http = require('https');
const options = {
headers: {
"Content-Type": "application/json",
},
hostname: 'cert.api2.heartlandportico.com',
port: 443,
path: '/Hps.Exchange.PosGateway.Hpf.v1/api/token?api_key=pkapi_cert_jKc1FtuyAydZhZfbB3',
method: 'POST',
};
const req = {
token_type: 'supt',
object: 'token',
card: {
number: '4242424242424242',
exp_month: '12',
exp_year: '2025',
cvc: '123'
}
};
let token = '';
const request = http.request(options, (res) => {
res.on('data', (d) => token += d);
res.on('end', () => {
const response = JSON.parse(token);
if (response.token_value) {
chargeCreditCardToken(1.00, response.token_value, '123456', () => {});
}
});
});
request.write(JSON.stringify(req));
request.end();
Sadly, I'm not able to reproduce the same issue with reading the CreditSale
property in our SDK:
$ node index.js
supt_dj44Qjs6cfuWje6AsAm9D4ek
response { transactionId: 1025300723,
authorizationCode: '12323A',
avsResultCode: '0',
avsResultText: 'AVS Not Requested.',
cardType: 'Visa',
cpcIndicator: undefined,
cvvResultCode: 'M',
cvvResultText: 'Match.',
referenceNumber: '726314366759',
responseCode: '00',
responseText: 'APPROVAL',
tokenData: null }
Are you able to send more details about the account and when you're seeing these errors to SecureSubmitCert@e-hps.com and CC my team EntApp_DevPortal@e-hps.com? We can dive more into your account to see what may be happening.
Hi- I am getting this error intermittently, works fine most of the time. It seems the response is missing the body and the code doesn't handle that well. The charge goes through but the callback throws an error when it returns.
This is the code it is referencing:
Any ideas?