How do I view / output the gateway response message? 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.
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()-&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));
                }
            }
     });


Then, to set it up as a template variable, something like this will work:

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