During an anonymous user checkout, if "Always create a CIM profile for securely storing CC info for later use." Authorize.net payment gateway module option is enabled, the CIM profile merchantCustomerId was set to 0. The attached patches will update the merchantCustomerId to the $user->uid through hook_user('insert',...

Please review...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jaypark’s picture

if you can get a cleaner patch file for the inc file, here's the raw file as a zip (diff saw the previously attached patch file as ALL different)

univate’s picture

Status: Needs work » Active

From the drupal coding standard (http://drupal.org/coding-standards):

Files should be formatted with \n as the line ending (Unix line endings), not \r\n (Windows line endings).

Your patches are in windows format (which is the reason all lines are different in the patch).

I can't commit the first patch to uc_recurring as that adds hacks for authorize.net, the place for that code is going to be in the authorize.net module in the ubercart project.

univate’s picture

Status: Active » Needs work
jaypark’s picture

Status: Active » Needs work

thanks univate. yes it's a hack, but hopefully it will get the ball rolling in the right direction to get this issue resolved. i'm not sure where the lines are being drawn between ubercart and uc_recurring; the patches were coded for files within only uc_recurring.

univate’s picture

Payment gateway code goes in either:
1) the payment gateway module
2) include/uc_recurring.
.inc

1 is the preferred place, since it can actually be maintained by people who use the gateway, 2 is for gateways that can't get the changes into them, like the ones stuck in ubercart that its become almost impossible to get patches accepted.

mattcasey’s picture

We are trying to implement Authorize.net CIM on a site, and updates on this?

mattcasey’s picture

[Update] jaypark's patch got me there 99% of the way using most recent 2.x-dev of Recurring and ubercart :)

On line 216 of the .inc file, $user-uid was still returning Anonymous, so instead I passed the $account variable through the parent functions and used the uid from that.

tinker’s picture

After tracking through the code in uc_reccuring and ubercart I have come to the conclusion that this is not a problem with uc_recurring module. The problem occurs in uc_authorize.net because _uc_authorizenet_cim_profile_create() is triggered in _uc_authorizenet_charge() before the user account is created during anonymous checkout. This value is set later by uc_cart_complete_sale().

Having a fix in uc_recurring does not make sense because it did not create the problem. The fix should probably go in a new uc_authorizenet_complete() function that will update the CIM profile if that payment method was used.

j0rd’s picture

Jaypark seems to have explained fairly large holes in this process in his other Ubercart issue queue:
http://drupal.org/node/901544

Are his patches or at least problems he's found, going to get applied into uc_recurring, so that it can actually be used on the only processor is actually claims to support?

univate’s picture

I provided a review and mentioned the issue that need to be fixed, as soon as they are I will happy commit a patch if its required.

But... this module has NOTHING to do with authorize.net, I'm not sure why everyone thinks this module is about that gateway. This module is a framework/api for handling recurring payments with ubercart. I use it with a couple of different gateways that aren't authorize.net, I am not putting my gateway specific code in this module, so I hope you understand why i will not be putting other gateways code like authorisze.net into uc_recurring.

Having said this, this issue would be far better solved in the Ubercart Authorize.net payment gateway module so all CIM payments by anonymous users are entered correct, not just sites using this module.

j0rd’s picture

Thanks for the clarification. I guess we really need to pull the contrib payment modules out of Ubercart, much like they did with uc_recurring so that they can move forward. Been almost a year since an upgrade of Ubercart.

vmi’s picture

This issue was filed against 6.x-2.x-dev and has been open for over a year.

I'm currently experiencing a related problem with version 6.x-2.0-beta1and have cross referenced this issue under a new project issue: #1423482: Anonymous checkout for Recurring Product not listed properly under Subscription Manager and My Account

I would appreciate it if someone here could please advise on the best approach to the above referenced issue.

Thanks.

UPDATE:
Based on the explanation (and solution - thanks!) provided by @mattwad in comment#13 - I redact my previous statement about this issue being related and will leave a link to the other issue for future reference.

mattcasey’s picture

The issue in #12 is not really related to this, actually. This thread is gateway-specific and has to do with updating a Customer ID on Authorize.net that is tied to a user account in Drupal. If you want, I can make a patch for the most recent UC_Recurring using a custom version of the above code. I do agree with Univate's comment in #10 that this should be fixed in Ubercart, but I have not found another solution.

mattcasey’s picture

Here's a new version of the patch from OP using the most recent UC_Recurring.

Also want to repeat that this patch is a "hack" therefore it's not likely to get included in a future version of UC_Recurring, but I haven't been had time to try and fix it in Ubercart's module.

ShaunDychko’s picture

The patch in #14 needs to be re-rolled since it tries to duplicate function definitions and leads of WSOD after fatal PHP errors. (tested against 6.x-2.0-beta1)

mattcasey’s picture

Status: Needs work » Needs review
mattcasey’s picture

Here's a new one.. sorry about that. I changed status to review so the bot will test it (I think that's how DO works?).

ShaunDychko’s picture

Thanks for such a quick reply! This works! (maybe you could remove the debug statement at the end... but no point being picky...)

ShaunDychko’s picture

I wrapped the portion in the 'insert' of of hook_user with a check that the cart_order session variable is set. I was getting PHP errors complaining that the array_key function wasn't being passed an array when new users registered on the site (without a purchase). On line 231 of uc_recurring.module:

    case 'insert':
      if(isset($_SESSION['cart_order'])){
        $path = drupal_get_path('module', 'uc_recurring');
        if(!function_exists('_uc_recurring_uc_authorizenet_cim_update_paymentprofile')) {
          include($path.'/includes/uc_recurring.uc_authorizenet.inc');
        }
        $order = uc_order_load($_SESSION['cart_order']);
        $ref_ids = array_keys($order->data['cc_txns']['references']);
        $ref_id = $ref_ids[0];
        $is_customerprofile_update = true;
        _uc_recurring_uc_authorizenet_cim_update_paymentprofile($order, $ref_id, $is_customerprofile_update, $account );
      }
      break;
ShaunDychko’s picture

Here's a patch reflecting the change in #19

mattcasey’s picture

Oh thanks, on my sites *all users* have recurring billing so I have not run into this issue.

tinker’s picture

In an effort to get this comitted I rewrote the code in #20 to make it easier to remove if/when the root problems get addressed. This patch adds a uc_recurring_invoke() using a new callback 'checkout complete callback' to uc_recurring_uc_checkout_complete(). This makes it possible for all the unofficially supported payment methods to execute on hook_uc_checkout_complete() which is executed when all order & account info is known. I have added the new callback to uc_recurring_uc_authorizenet_recurring_info() which points to a new callback function uc_recurring_authorizenet_cim_checkout_complete() that updates the customer ID.

Unfortunately uc_recurring is having problems, with orders when the customer is not logged in, because of a bug in Ubercart which forces checkout before uc_recurring can process hook_order($op = 'submit'). This makes uc_recurring_uc_checkout_complete() process before the fee has been created. This means that the fee (in uc_recurring_users table) will be stuck with UID 0. BTW any module that appears in module_list() after uc_credit will have this problem.

See #1423482: Anonymous checkout for Recurring Product not listed properly under Subscription Manager and My Account

The simplest temp fix is to set the weight of uc_credit module to 1 which will make uc_recurring process before it. This change is required for the local and Auth.net CIM fee to be updated.

SQL code:
UPDATE system SET weight = 1 WHERE name = 'uc_credit'

Today I worked out a patch to fix the ubercart issue and safely provide a user account before the checkout process completes. This has the potential to bypass this issue and the need for uc_recurring_uc_checkout_complete() entirely.
See #1669968: hook_uc_checkout_complete() is called outside of checkout process (when payment is entered).