The comments for the function commerce_authnet_cim_cardonfile_charge() state:
* @return
* TRUE if the transaction was successful
For all scenarios where the charge failed, FALSE is returned - but in the only instance when the transaction succeeded, it does not return TRUE, just a return statement. This is interpreted as NULL, therefore, when invoking commerce_authnet_cim_cardonfile_charge() in custom code, the return value is NULL when it should be TRUE. Otherwise, it is unreliable to evaluate.
For example, if I have a statement like:
if ($balance['amount'] && commerce_authnet_cim_cardonfile_charge($params...))
The inner statement is never entered because both conditions do not evaluate to TRUE.
Simply changing line 917 in commerce_authnet.module to return TRUE; instead of just return; corrects this behavior.
Comments
Comment #1
andyg5000Setting as major since commerce_cardonfile_order_charge_card expects the callback to return a boolean. When null is returned, the rules to update the order status don't fire. Easy patch attached ;)
Comment #2
favrik commentedI think it should really be returning the transaction status and not just TRUE, for future proof or plans? Not sure.
http://drupalcode.org/project/commerce_cardonfile.git/blob/a34a42a926c26...
Comment #3
favrik commentedYep, I think it should be the transaction status. The reason returning TRUE works is because the
in_arraycheck is not using the strict parameter, hence you have something like:Comment #4
favrik commentedComment #5
focal55 commentedThank you favrik and andyg5000, working great.
Comment #6
apower commentedPatch #4 works great! I actually found this problem when using the Commerce Authorize.Net module with Commerce Recurring. Because the transaction status wasn't returned the Rules event "commerce_cardonfile_charge_success" was never invoked. Which meant the status of my recurring orders never changed.
So for anyone else using Commerce Authorize.Net 7.x-1.1 with Commerce Recurring, you'll definitely need to apply patch #4.
Comment #7
freality commentedPatch #4 works for me as well. But looking at the code there is a case where
$transaction->statusis not set.$transaction->statusis set to failed based on the authnet response at line 777. Else,$transaction->statusis set within a switch statement starting at line 781. However, for whatever reason, if$payment_method['settings']['txn_type']is not set,$transaction->statusis not set.I think a default case should be added to catch this, or a test
return (isset($transaction->status)) ? $transaction->status : TRUE;should exist in the return. I'm not sure what the default status should be, but a default would make the code more bulletproof.Comment #8
freality commentedThe attached patch simple tests if
$transaction->statusisset.return (isset($transaction->status)) ? $transaction->status : TRUE;Comment #9
andyg5000I love it when I am stumped by the same issue twice :) Let's get this committed so it doesn't happen again
Comment #10
sushantpaste#8 works great . thanks all.
Comment #11
greatmatter commentedYES. You ALL rock. Thank you.
Comment #12
mglaman#8 committed!
Comment #15
MichaelSt commentedUnfortunately I'm getting this again even with the latest 7.x-1.2.I thought it was committed but several charges were just run and they aren't supposed to be charged until the middle of June.Turned out I had a parallel cloud development version of my site I never set up or knew about - sorry for the false alarm.