<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Making async calls from node.js in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Making-async-calls-from-node-js/m-p/73851#M45799</link>
    <description>&lt;P&gt;I'm using the github code and trying to make a call from a node.js express route.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The calling code is this:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;async &lt;/SPAN&gt;&lt;SPAN&gt;charge&lt;/SPAN&gt;(&lt;SPAN&gt;req&lt;/SPAN&gt;, &lt;SPAN&gt;res&lt;/SPAN&gt;) {&lt;BR /&gt;    &lt;SPAN&gt;try &lt;/SPAN&gt;{&lt;BR /&gt;        &lt;SPAN&gt;const &lt;/SPAN&gt;merchant &lt;SPAN&gt;= new &lt;/SPAN&gt;&lt;SPAN&gt;authorizeNet&lt;/SPAN&gt;();&lt;BR /&gt;        &lt;SPAN&gt;const &lt;/SPAN&gt;result &lt;SPAN&gt;= await &lt;/SPAN&gt;merchant.&lt;SPAN&gt;chargeCreditCard&lt;/SPAN&gt;(&lt;SPAN&gt;req&lt;/SPAN&gt;.body);&lt;BR /&gt;        &lt;SPAN&gt;console&lt;/SPAN&gt;.&lt;SPAN&gt;log&lt;/SPAN&gt;(&lt;SPAN&gt;'result'&lt;/SPAN&gt;, result);&lt;BR /&gt;        &lt;SPAN&gt;res&lt;/SPAN&gt;.&lt;SPAN&gt;send&lt;/SPAN&gt;(result);&lt;BR /&gt;    } &lt;SPAN&gt;catch &lt;/SPAN&gt;(&lt;SPAN&gt;err&lt;/SPAN&gt;) {&lt;BR /&gt;        &lt;SPAN&gt;res&lt;/SPAN&gt;.&lt;SPAN&gt;send&lt;/SPAN&gt;(&lt;SPAN&gt;err&lt;/SPAN&gt;);&lt;BR /&gt;    }&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The charge function in the authorizeNet class is pretty much the charge function on the GitHub demo and looks like this:&lt;/P&gt;&lt;PRE&gt;async chargeCreditCard(props) {
....&lt;/PRE&gt;&lt;PRE&gt;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;
        });&lt;/PRE&gt;&lt;P&gt;the problem is that the response returned in the last line of the chargeCreditCard function is undefined.&amp;nbsp; 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.&amp;nbsp; 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).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
    <pubDate>Wed, 04 Nov 2020 15:40:28 GMT</pubDate>
    <dc:creator>AndrewTraub</dc:creator>
    <dc:date>2020-11-04T15:40:28Z</dc:date>
    <item>
      <title>Making async calls from node.js</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Making-async-calls-from-node-js/m-p/73851#M45799</link>
      <description>&lt;P&gt;I'm using the github code and trying to make a call from a node.js express route.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The calling code is this:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;async &lt;/SPAN&gt;&lt;SPAN&gt;charge&lt;/SPAN&gt;(&lt;SPAN&gt;req&lt;/SPAN&gt;, &lt;SPAN&gt;res&lt;/SPAN&gt;) {&lt;BR /&gt;    &lt;SPAN&gt;try &lt;/SPAN&gt;{&lt;BR /&gt;        &lt;SPAN&gt;const &lt;/SPAN&gt;merchant &lt;SPAN&gt;= new &lt;/SPAN&gt;&lt;SPAN&gt;authorizeNet&lt;/SPAN&gt;();&lt;BR /&gt;        &lt;SPAN&gt;const &lt;/SPAN&gt;result &lt;SPAN&gt;= await &lt;/SPAN&gt;merchant.&lt;SPAN&gt;chargeCreditCard&lt;/SPAN&gt;(&lt;SPAN&gt;req&lt;/SPAN&gt;.body);&lt;BR /&gt;        &lt;SPAN&gt;console&lt;/SPAN&gt;.&lt;SPAN&gt;log&lt;/SPAN&gt;(&lt;SPAN&gt;'result'&lt;/SPAN&gt;, result);&lt;BR /&gt;        &lt;SPAN&gt;res&lt;/SPAN&gt;.&lt;SPAN&gt;send&lt;/SPAN&gt;(result);&lt;BR /&gt;    } &lt;SPAN&gt;catch &lt;/SPAN&gt;(&lt;SPAN&gt;err&lt;/SPAN&gt;) {&lt;BR /&gt;        &lt;SPAN&gt;res&lt;/SPAN&gt;.&lt;SPAN&gt;send&lt;/SPAN&gt;(&lt;SPAN&gt;err&lt;/SPAN&gt;);&lt;BR /&gt;    }&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The charge function in the authorizeNet class is pretty much the charge function on the GitHub demo and looks like this:&lt;/P&gt;&lt;PRE&gt;async chargeCreditCard(props) {
....&lt;/PRE&gt;&lt;PRE&gt;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;
        });&lt;/PRE&gt;&lt;P&gt;the problem is that the response returned in the last line of the chargeCreditCard function is undefined.&amp;nbsp; 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.&amp;nbsp; 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).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 15:40:28 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Making-async-calls-from-node-js/m-p/73851#M45799</guid>
      <dc:creator>AndrewTraub</dc:creator>
      <dc:date>2020-11-04T15:40:28Z</dc:date>
    </item>
  </channel>
</rss>

