Posts: 4
Registered: ‎07-01-2016

Making async calls from node.js

I'm using the github code and trying to make a call from a node.js express route.


The calling code is this:

async charge(req, res) {
try {
const merchant = new authorizeNet();
const result = await merchant.chargeCreditCard(req.body);
console.log('result', result);
} catch (err) {


The charge function in the authorizeNet class is pretty much the charge function on the GitHub demo and looks like this:

async chargeCreditCard(props) {
return ctrl.execute(function() {

            const apiResponse = ctrl.getResponse();

            const response = new ApiContracts.CreateTransactionResponse(apiResponse);

            //pretty print response
            console.log('AuthorizeNet.charge response', JSON.stringify(response, null, 2));

             return response;

the problem is that the response returned in the last line of the chargeCreditCard function is undefined.  What gets printed out on the express server is the charge request (from github example), the undefined response, and then the console.log inside the ctrl.execute call.  It should be the charge request, the console.log inside the ctrl.execute and finally the response (and not undefined but the same object that was printed inside the ctrl.execute function).


What am I missing?