A recurring fee is created even if a transaction fails with Authorize.net CIM. This results in "Unknown Product" entries on /admin/store/subscriptions/subscribers, not to mention a database cluttered with extraneous recurring fees. I've tracked it down to this, starting on line 45 of uc_recurring.uc_authorizenet.inc

/**
 * Set up the recurring fee by creating a CIM profile for future payments
 *
 * @param $order
 *   The order object.
 * @param $fee
 *   The fee object.
 * @return
 *   TRUE if recurring fee setup
 */
function uc_recurring_authorizenet_cim_process($order, &$fee) {
  $fee->fee_handler = 'authorizenet_cim';
  if (variable_get('uc_authnet_cim_profile', FALSE) == FALSE) {
    $data = array(
      'txn_type' => UC_CREDIT_REFERENCE_SET,
    );
    return uc_authorizenet_charge($order->order_id, $order->total_amount, $data);
  }
  return TRUE;
}

Since the "uc_authnet_cim_profile" should be true (this is a checkbox on the Authnet config), this function will always return TRUE, even if the payment is going to fail.

I turned on my debugger, but the code is getting a little too dense for me to see how to fix this...

Comments

shaundychko’s picture

The issue here: http://drupal.org/node/1073704 was that multiple recurring fees were created for failed renewals, which is a similar issue.

The issue now is having recurring fees created for orders that never processed in the first place.

shaundychko’s picture

Title: Recurring fee created even though transaction fails - Authorize.net CIM » Recurring fee created even though initial transaction fails - Authorize.net CIM
shaundychko’s picture

The solution to this problems seems to be removing the checkbox at
/admin/store/settings/payment/edit/gateways
in the CIM section of the Authorize.net section that says
"Always create a CIM profile for securely storing CC info for later use."

This causes the code above to enter the "if" statement and have uc_recurring initiate creation of the CIM profile. This results in the "CIM profile created" order comment coming BEFORE the "recurring fee created..." comment, which is a good sign... This all worked out on the sandbox for valid credit cards, but I wonder how to test credit cards that fail, without being blocked by ubercart's own test for valid credit card numbers...

shaundychko’s picture

Status: Active » Needs review
shaundychko’s picture

Status: Needs review » Needs work

Ahh nuts, this doesn't work either, since both the "CIM profile" and "Recurring Fee added" processes happen before the payment is actually charged. By the time payment fails, a recurring fee has already been created, and the customer will get a few emails in a month telling them that their recurring fee has failed.

shaundychko’s picture

Status: Needs work » Closed (fixed)

Seems to be fixed by restoring the weight of the uc_recurring_product module in the system table back to the default '0'. Weight = -1 was tried as a solution to http://drupal.org/node/1423482#comment-5829842.