One of our challenges with Ubercart has been the limited handling it provides for gateway results when a payment is processed.
For example, we use Authorize.Net as our gateway (with the appropriate payment module). We have some specific settings enabled in our Authorize.Net account to prevent fraud. These can let a payment process as normal, authorize the payment and hold it for manual review, or decline the transaction due to a specific reason.
Unfrotunately, Ubercart doesn't process each specific type of response. If the gateway authorizes the payment and holds it for review, UC still returns a "Rejected" response to the user as if the payment didn't work at all. While we don't want to provide our specific gateway responses to the end user, we do wish we could process responses and provide (customizable) messages based on each gateway response.
Is this capability (or the proper tools to obtain this capability--Ubercart tended to be something we avoided customizing) included in Drupal Commerce?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 1003476-8.alterable_error_messages.patch | 2.04 KB | rszrama |
| #6 | 1003476-create_hook_for_overriding_error_messages.patch | 1.85 KB | andyg5000 |
Comments
Comment #1
rszrama commentedMoving this to the Authorize.Net integration module, as the core modules really have no say in this. Each module will interact with the checkout form for its own payment method. Right now this one just outputs a user-friendly message combined with the actual reason message from Auth.Net. It would probably be good to handle the messaging in a separate submit handler so it can be overridden by the site developers if required.
If that tests out as a good pattern, we can recommend it as a general pattern for payment method module development.
Comment #2
archimedes commentedI wondered where it might fit. Thanks for moving it, Ryan.
It sounds like even the current model you describe is a step in the right direction, much less the exciting potential of adding override options.
One thing that's related is also how a transaction status is determined. Does a gateway hand back information that Commerce would use to identify how the status should be labeled? I'm not sure if that's a gateway integration thing, Commerce thing, or something else. For example, in a recent transaction that was held for approval by Authorize.Net, UC identified the transaction as being "in checkout" rather than "completed". For that reason, Google Analytics didn't detect the transaction as having actually been completed, so it didn't show up in our Analytics account as being revenue.
In my own mind (which has limited understanding of the way all of these modules interact), I would suggest that when a specific response comes back from the gateway (independent of the message that the user sees--that could still be overridden as desired), Commerce sets the status accordingly. Then, in a case like above with GA, hopefully when that status is changed, to Completed (manually, I assume) the GA module would detect that has a transaction to track.
There's essentially two parts to that:
1) Gateway response is handled properly by Commerce (helpful but not necessary to correct the example situation)
2) When a status is changed either manually or automatically, modules are informed and will act accordingly. I realize this part requires both work on both Commerce and that module to ensure that happens.
Comment #3
markie commentedSo I was doing some troubleshooting for a client and I realized there were a few things that have to happen for proper testing.
According to the AIM guide, testing has to happen against the test server (https://test.authorize.net/gateway/transact.dll) and the 'x_test_request' parameter has to be set. Then you can use the test credit card (4222222222222) and set the amount to the result code you would like returned.
For example, if you just want it to return the error 'Credit Card is Expired', that reason code is 8, so you would set the credit card as noted above, and the amount to $8.00.
Now, that being said, there is a bug in the commerce_authnet.module where the x_test_request parameter is incorrectly set. As it stands, the x_test_request is set to TRUE if the transaction mode is set to AUTHNET_TXN_MODE_LIVE_TEST. This however, tries to test against the live server (https://secure.authorize.net/gateway/transact.dll), not the proper test server (https://test.authorize.net/gateway/transact.dll). Therefore, we need to update the module, line 289 to:
'x_test_request' => $payment_method['settings']['txn_mode'] == AUTHNET_TXN_MODE_DEVELOPER ? 'TRUE' : 'FALSE',I will run a patch when I get a chance, but right now I can't.
markie
Comment #4
markie commentedNow that I think about it.. what's the point of AUTHNET_TXN_MODE_LIVE_TEST anyway?
Comment #5
keithm commented@markie: AUTHNET_TXN_MODE_LIVE_TEST is for final testing against a live (not test) account. No payments actually get processed when x_test_request has that value. In view of that, the code you thought contains a bug in #3 seems fine.
Comment #6
andyg5000Here's a patch that goes along with with Ryan's suggestion in #1. It creates a hook_commerce_authnet_aim_error_messages_alter() that allows you to override the messages displayed to a user when a transaction fails. The hook is passed an array of $error_messages as well as the full $response array. This patch does not fully address the feature request in this issue, but is a partial fix.
Here's an example of how to override the default messages:
Comment #7
andyg5000Comment #8
rszrama commentedIf we're going to make the messages list alterable, I don't see any reason to force the dual error messages. May as well just loop over the array to display them. However, this code is in use for CIM transactions it seems for Card on File support, so I'm not sure the hook name is going to work. Otherwise we might just need two hooks; one for AIM and another for CIM. That's probably the best idea.
We'll also need a .api.php file to document these hooks before committing.
Comment #9
rszrama commentedForgot to add my follow-up patch that supports variable length error messages arrays.