[Drupal] [Solved] How to fix the issue with product purchase through ubercart set user-id to (0) in the invoice by Authorize.net

| | 1 min read

We had faced an issue with invoice sent by authorize.net, for anonymous purchase a product in ubercart in one of our Drupal 7 site. After the purchase is completed, the user receives an invoice from authorize.net. But if the user is anonymous, the invoice's customer id is set as zero. We had sorted out the issue and fixed it. Read on to know how to solve this problem

When anonymous user purchases, user account is created only on checkout complete and the data sent to authorize.net is set before the hook_uc_checkout_complete is called. The submit data is prepares inside the uc_authorizenet.module file's function _uc_authorizenet_charge() and it fetches the uid from the $user varibale, but at that time it is zero. So to remove senting the field cust_id for anonymous user we had added the following code inside _uc_authorizenet_charge() function.

// When a new user purchases an invoice with cust id '0' is sent.
// Added to unset customer id.

if ($user->uid == 0) {

This code snippet helps to unset the customer id field in the invoice for anonymous users.