15 replies [Last post]
digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Was this information Helpful?

Is "Card Type" not stored (outside of "debug mode") due to PCI guidelines?

This section of code from uc_credit.module (lines 264-283) seems to indicate so:

      case 'save':
      if ($arg1->payment_method == 'credit') {
        // Build an array of CC data to store with the order.
        if (!empty($arg1->payment_details)) {
          // Check for debug mode.
          if (variable_get('uc_credit_debug', FALSE) && arg(1) != 'checkout') {
            // If enabled, store the full payment details.
            $cc_data = $arg1->payment_details;
          }
          else {
            // Otherwise, save only some limited, PCI compliant data.
            $cc_data = array(
              'cc_number' => substr($arg1->payment_details['cc_number'], -4),
            );
          }

          _save_cc_data_to_order($cc_data, $arg1->order_id);
        }
      }
      break;

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Re: Storage of Credit Card Type info

Nope, it was just a feature added at a later date. There's discussion in another thread about this feature, but I don't know if there's been a patch.

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Re: Re: Storage of Credit Card Type info

Okay, thanks. I'll address it and try to find my way back here with a patch when I have time.

Cheers,
Stephen

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Re: Re: Re: Storage of Credit Card Type info

This seems to solve the issue and shows what type of CC was used (add line 277 to uc_credit.module):


'cc_type' => check_plain($arg1->payment_details['cc_type']), // DFM 1.13.09 save Credit Card type (Visa, MC, etc.)

So the above code snippet would look like:

    case 'save':
      if ($arg1->payment_method == 'credit') {
        // Build an array of CC data to store with the order.
        if (!empty($arg1->payment_details)) {
          // Check for debug mode.
          if (variable_get('uc_credit_debug', FALSE) && arg(1) != 'checkout') {
            // If enabled, store the full payment details.
            $cc_data = $arg1->payment_details;
          }
          else {
            // Otherwise, save only some limited, PCI compliant data.
            $cc_data = array(
              'cc_number' => substr($arg1->payment_details['cc_number'], -4),
  'cc_type' => check_plain($arg1->payment_details['cc_type']), // DFM 1.13.09 save Credit Card type (Visa, MC, etc.)
            );
          }

          _save_cc_data_to_order($cc_data, $arg1->order_id);
        }
      }
      break;

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Re: Re: Re: Re: Storage of Credit Card Type info

Do you have to do anything to get this to display, or is storing it enough?

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Hi Ryan, No, you don't have

Hi Ryan,

No, you don't have to do anything else. Just add the cc_type to the data being saved.

The "View card details" link in the "Payment:" pane on orders looks to see if that information is there or not and adds it to the view.

I believe it already does this in case you have selected the "Debug" mode for "Credit card settings" under the "Payment methods" tab at /admin/store/settings/payment/edit/methods .

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Well. You rock. I'll get

Well. You rock. Cool

I'll get this tested and committed as soon as I can.

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Re: Well. You rock. I'll get

Awesome! I have a feeling this is a little detail that many would find useful.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Re: Re: Well. You rock. I'll get

Well, that was indeed a simple fix. I've committed it and it should appear in the next release on d.o. I backported it to the D5 branch as well. Many thanks. Smiling

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Re: Re: Re: Well. You rock. I'll get

Here's another related issue. This appears to occur when entering an order through the administrative backend however it may happen on the storefront, too (I assume so but haven't checked).

A user sees the first Credit Card type option in the dropdown listed and assumes that is the current selection. If that selection matches their actual credit card type, they don't bother to change the selection. Upon saving the order, the cc_type is empty even though something like "Visa" may have appeared in the the dropdown as the "default selection".

I think the solution is in lines 879-885 of uc_credit.module:

    $form['cc_type'] = array(
      '#type' => 'select',
      '#title' => t('Card type'),
      '#options' => $options,
      '#default_value' => $order->payment_details['cc_type'],
    );
  }

Line 883 should check if there is any data in $order->payment_details['cc_type'] and supply a default if there isn't:

      '#default_value' => $order->payment_details['cc_type'] ? $order->payment_details['cc_type'] : t('Visa'), // DFM 1.28.09 ensures the type is not empty

I'm not sure if t('Visa') is truly the correct solution here in case someone has altered the "Card type select box options" in the "Credit card settings" fieldset at /admin/store/settings/payment/edit/methods, but this solves the problem of empty cc_type data.

Is there a better alternative to hardcoding t('Visa') as the default if $order->payment_details['cc_type'] is empty for a new order?

Oddly, I'd previously tried inserting

'#required' => TRUE,

but it seemed to just be ignored. Due to AJAX inserting the field after page load?

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Re: Re: Re: Re: Well. You rock. I'll get

Update: The fix proposed here only works for credit card orders created through the customer checkout. It does NOT work for orders entered in through the admin order interface.

I think the complete fix would require changes to the code in the routines of uc_credit.module around lines 165, 278, and 1242. I tried a fix similar to what worked for checkout at these places, but it didn't seem to do anything. I'll take a closer look at the code there, but if anyone has any instant insights, I'd appreciate it if you could share them!

Thanks!
Stephen

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Re: Re: Re: Re: Re: Well. You rock. I'll get
LiFTED's picture
Offline
Joined: 08/13/2009
Juice: 11
Is this working with UC 2 / D6

Hi there! I am also trying to have the credit card type appear somewhere in the backend of our Ubercart site and I came across this thread. After reading digitalfrontier's comments above I dug into the code a little big and it seems that what he is recommending has already been committed to ubercart?

Line 328 - 334 of uc_credit.module :

// Otherwise, save only some limited, PCI compliant data.
$cc_data = array(
'cc_number' => substr($arg1->payment_details['cc_number'], -4),
'cc_exp_month' => $arg1->payment_details['cc_exp_month'],
'cc_exp_year' => $arg1->payment_details['cc_exp_year'],
'cc_type' => $arg1->payment_details['cc_type'],
);

From these lines of code it appears that ubercart is already saving the credit card type somewhere... I just cant seem to display it anywhere??
All we are looking for is to have some place where site admins can login and see what type of credit card was used to make a purchase.

Any help would be much appreciated!!

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Re: Is this working with UC 2 / D6

Yes, these changes were committed and are a part of the current version of UC. As for the location of the settings, I don't recall their location in UC 2.x In UC 1.x you would enable the field under the Credit Card Settings section (Credit card fields). More info on this can be found at http://www.ubercart.org/docs/user/2731/credit_card_settings .

ttamniwdoog's picture
Offline
Joined: 10/28/2008
Juice: 63
Tokenized

Would the card-type be available as a token for me to display in a customer's invoice?
There is a most excellent little article by agileadam that explains how to create a cc-num token. Perhaps that is all I need.

digitalfrontiersmedia's picture
Offline
Getting busy with the Ubercode.
Joined: 11/08/2008
Juice: 283
Re: Tokenized

I don't believe it is available as a token by default. I think you'd have to add a custom module or something to make it available.