Answers.Body: <p>Best to do this in your business logic plugin really, rather than in templates I'd say. </p>
  
  <p>(You probably don't want to be passing this through to templates generally.  That said, you could easily add a template variable to this approach I guess...)</p>
  
  <p>Here's some example code - and note what you get back will vary greatly depending on the gateway, so make sure you use defensive code like <code>array_key_exists</code> etc.</p>
  
  <p>If you set an http session var, you can then retrieve this using a template variable:</p>
  
  <pre><code>    // Save the Beagle Anti-Fraud Score to the order
      craft()-&gt;on('commerce_transactions.onSaveTransaction', function ($event){
  
              $transaction = $event-&gt;params['transaction'];
              $order = $transaction-&gt;order;
  
              // Transactions are saved before responses too....
              if($transaction-&gt;response){
                  craft()-&gt;httpSession-&gt;add("gatewayResponse", $transaction-&gt;response);
                  BusinessLogicPlugin::log($transaction-&gt;response);
  
                  //example of saving some of this data to a custom field in the order if you want to hang on to any of it...
                  if (array_key_exists("BeagleScore",$transaction-&gt;response)){
                      $score = (string) $transaction-&gt;response['BeagleScore'];
                      BusinessLogicPlugin::log($score);
                      $order-&gt;setContentFromPost(["beagleScore"=&gt;$score]);
                      BusinessLogicPlugin::log(craft()-&gt;commerce_orders-&gt;saveOrder($order));
                  }
              }
       });
  </code></pre>
  
  <p>Then, to set it up as a template variable, something like this will work:</p>
  
  <pre><code>class YourPluginVariable
  {
      public function gatewayResponse() {
  
          $return = "";
          $gatewayResponse = craft()-&gt;httpSession-&gt;get("gatewayResponse");
  
          if($gatewayResponse)
              $return = $gatewayResponse;
  
          craft()-&gt;httpSession-&gt;remove("gatewayResponse");
  
          return $return;
      }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T03:34:24.297Z
Answers.Text: Thanks for the reply Jeremy. I totally understand that this info shouldn't be displayed on the front-end for the end user. I'm just looking for a quick and dirty way to grab this information for debugging / testing purposes on the staging server.
Answers.UserDisplayName: Brett Burwell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T03:42:03.780Z
Answers.Text: Ok, no probs, updated above with some template var code.  But honestly a log file seems just as quick and dirty as a template var to me really :) - just make sure you don't accidentally leave this code behind later I guess!
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T03:47:05.647Z
Answers.Text: Thanks Jeremy. I appreciate the code example. I've never dug into plugin dev before, so I'm not totally sure what I'm looking at, but maybe this is a good nudge to dive in. And really, my experience with plugin dev aside, i'm honestly quite shocked that Commerce isn't already logging this info somewhere that's readily accessible. But I do appreciate you chiming in.
Answers.UserDisplayName: Brett Burwell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T03:51:55.693Z
Answers.Text: With Commerce you are bound to need some plugin code.  On SE there are plenty of references to either BusinessLogicPlugin or pluginfactory.io to generate the bones of your plugin, once you have that adding the above should be simple.
  
  Gateway data is confidential stuff, so I don't personally think Commerce should be logging it by default as it happens.
  
  That said I misread your question, I thought you were making a new gateway....using a built in one, you should be checking the flash data first and foremost for errors, plus you will get errors on the appropriate model fields generally.
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T03:52:18.787Z
Answers.Text: See e.g. https://craftcms.stackexchange.com/questions/16188/getting-to-grips-with-errors-and-flash-messages
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T03:57:19.883Z
Answers.Text: I'm a donkey. Craft already is logging that error in the `commerce.log` file. I definitely already looked but must have glazed over it with tired dev eyes. Silly silly.
Answers.UserDisplayName: Brett Burwell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T04:00:18.320Z
Answers.Text: But seriously. You're a champ for posting such a detailed reply. I appreciate it. Thanks again. And you're absolutely right... the deeper I get into Commerce the more I realize that you'll almost certainly need to do some amount of custom plugin dev to handle the odd wrinkles that are bound to come up with most any e-commerce project.
Answers.UserDisplayName: Brett Burwell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T02:12:50.430Z
Answers.LastActivityDate: 2017-08-03T05:12:25.007Z
Answers.LastEditDate: 2017-08-03T05:12:25.007Z
Answers.UserDisplayName: Jeremy Daalder
Answers.Body: <p>Bonkers. Craft is already logging this info in the <code>commerce.log</code> file and I somehow managed to miss it.</p>
  
  <p>For anyone looking to do something a bit more custom with the data that's coming back from the gateway check out Jeremy Daalder's excellent answer. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-03T04:05:10.640Z
Answers.LastActivityDate: 2017-08-03T04:05:10.640Z
Answers.UserDisplayName: Brett Burwell
Body: <p>I'm working through the integration of a new Authorize.net gateway and bumping into errors trying to successfully process payments. </p>
  
  <p>How do I view / output the response that's coming back from Authorize.net after the failed transactions in my template for debugging purposes?</p>
  
  <p>I spit out <code>{{ dump(paymentForm) }}</code>, but I'm not seeing anything especially insightful.</p>
  
Tags: <plugin-craftcommerce>
Title: How do I view / output the gateway response message?
ThreadText: # How do I view / output the gateway response message?
  
  (Asked by: username_0 on 2017-08-02)
  
  I'm working through the integration of a new Authorize.net gateway and bumping into errors trying to successfully process payments.
  
  How do I view / output the response that's coming back from Authorize.net after the failed transactions in my template for debugging purposes?
  
  I spit out `{{ dump(paymentForm) }}`, but I'm not seeing anything especially insightful.
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-08-03. Score: 2 | Accepted answer
  
  Best to do this in your business logic plugin really, rather than in templates I'd say.
  
  (You probably don't want to be passing this through to templates generally. That said, you could easily add a template variable to this approach I guess...)
  
  Here's some example code - and note what you get back will vary greatly depending on the gateway, so make sure you use defensive code like `array_key_exists` etc.
  
  If you set an http session var, you can then retrieve this using a template variable:
  
  ```
      // Save the Beagle Anti-Fraud Score to the order
      craft()->on('commerce_transactions.onSaveTransaction', function ($event){
  
              $transaction = $event->params['transaction'];
              $order = $transaction->order;
  
              // Transactions are saved before responses too....
              if($transaction->response){
                  craft()->httpSession->add("gatewayResponse", $transaction->response);
                  BusinessLogicPlugin::log($transaction->response);
  
                  //example of saving some of this data to a custom field in the order if you want to hang on to any of it...
                  if (array_key_exists("BeagleScore",$transaction->response)){
                      $score = (string) $transaction->response['BeagleScore'];
                      BusinessLogicPlugin::log($score);
                      $order->setContentFromPost(["beagleScore"=>$score]);
                      BusinessLogicPlugin::log(craft()->commerce_orders->saveOrder($order));
                  }
              }
       });
  
  ```
  
  Then, to set it up as a template variable, something like this will work:
  
  ```
  class YourPluginVariable
  {
      public function gatewayResponse() {
  
          $return = "";
          $gatewayResponse = craft()->httpSession->get("gatewayResponse");
  
          if($gatewayResponse)
              $return = $gatewayResponse;
  
          craft()->httpSession->remove("gatewayResponse");
  
          return $return;
      }
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for the reply username_1. I totally understand that this info shouldn't be displayed on the front-end for the end user. I'm just looking for a quick and dirty way to grab this information for debugging / testing purposes on the staging server.  
  > **username_1**: Ok, no probs, updated above with some template var code.  But honestly a log file seems just as quick and dirty as a template var to me really :) - just make sure you don't accidentally leave this code behind later I guess!  
  > **username_0**: Thanks username_1. I appreciate the code example. I've never dug into plugin dev before, so I'm not totally sure what I'm looking at, but maybe this is a good nudge to dive in. And really, my experience with plugin dev aside, i'm honestly quite shocked that Commerce isn't already logging this info somewhere that's readily accessible. But I do appreciate you chiming in.  
  > **username_1**: With Commerce you are bound to need some plugin code.  On SE there are plenty of references to either BusinessLogicPlugin or pluginfactory.io to generate the bones of your plugin, once you have that adding the above should be simple.  Gateway data is confidential stuff, so I don't personally think Commerce should be logging it by default as it happens.  That said I misread your question, I thought you were making a new gateway....using a built in one, you should be checking the flash data first and foremost for errors, plus you will get errors on the appropriate model fields generally.  
  > **username_1**: See e.g. https://craftcms.stackexchange.com/questions/16188/getting-to-grips-with-errors-and-flash-messages  
  > **username_0**: I'm a donkey. Craft already is logging that error in the `commerce.log` file. I definitely already looked but must have glazed over it with tired dev eyes. Silly silly.  
  > **username_0**: But seriously. You're a champ for posting such a detailed reply. I appreciate it. Thanks again. And you're absolutely right... the deeper I get into Commerce the more I realize that you'll almost certainly need to do some amount of custom plugin dev to handle the odd wrinkles that are bound to come up with most any e-commerce project.  
  
  ---
  
  ### Answer by username_0 on 2017-08-03. Score: 1
  
  Bonkers. Craft is already logging this info in the `commerce.log` file and I somehow managed to miss it.
  
  For anyone looking to do something a bit more custom with the data that's coming back from the gateway check out username_1 username_1's excellent answer.
  
  
  ---
  
  