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()->on('commerce_transactions.onSaveTransaction', function ($event){

            $transaction = $event->params['transaction'];
            $order = $transaction->order;

            // Transactions are saved before responses too....
                craft()->httpSession->add("gatewayResponse", $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'];

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

            $return = $gatewayResponse;


        return $return;
  • 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. Aug 3 '17 at 3:34
  • 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! Aug 3 '17 at 3:42
  • 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. Aug 3 '17 at 3:47
  • 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. Aug 3 '17 at 3:51

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 Jeremy Daalder's excellent answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.