Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'CreditSale' of undefined #19

Open
arvinkx opened this issue Sep 11, 2017 · 3 comments
Open

Cannot read property 'CreditSale' of undefined #19

arvinkx opened this issue Sep 11, 2017 · 3 comments

Comments

@arvinkx
Copy link

arvinkx commented Sep 11, 2017

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.

TypeError: Cannot read property 'CreditSale' of undefined
    at /var/task/node_modules/heartland-nodejs/lib/services/secure-submit/hps-credit-service.js:144:63
    at /var/task/node_modules/heartland-nodejs/lib/services/portico-gateway.js:43:37
    at /var/task/node_modules/heartland-nodejs/lib/soap/client.js:106:13
    at /var/task/node_modules/heartland-nodejs/lib/soap/client.js:174:13
    at Request._callback (/var/task/node_modules/heartland-nodejs/lib/soap/http.js:63:13)
    at Request.self.callback (/var/task/node_modules/request/request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/var/task/node_modules/request/request.js:1171:10)
    at emitOne (events.js:96:13)

This is the code it is referencing:

if (tv4.validate(tx, schema)) {
                gateway.submitTransaction({'CreditSale':{'Block1':tx}}, function (err, result) {
                    if (err) {
                        callback(err, null);
                    } else {
                        var h = result.header, b = result.body.CreditSale;
                        processAuth(h, b, amount, currency, callback);
                    }
                });
            } else {
                callback(tv4.error, null);
            }

Any ideas?

@slogsdon
Copy link
Contributor

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?

@arvinkx
Copy link
Author

arvinkx commented Sep 13, 2017

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

@slogsdon
Copy link
Contributor

@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 [email protected] and CC my team [email protected]? We can dive more into your account to see what may be happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants