4

I would like to allow users to add a "card on file" outside of the payment workflow. I have authorize.net configured and I'm able to save a "card on file" during order completion. The cards list view appears correctly at the path user/1/cards:

enter image description here

This path is provided by commerce_cardonfile's implementation of hook_menu():

$items['user/%user/cards/add'] = array(

So logged in as user 1, I should be able to add a card from the page at the path user/1/cards/add

But I get "Access denied"... How can I access a form to add a card outside of the payment workflow?

3
  • It's commerce_cardonfile_access() that provides the access checks. Here's a random patch that seems to provide what you're looking for – Clive Jun 10 '14 at 17:56
  • To which branch does this patch apply? Thanks! – Joe Beuckman Jun 10 '14 at 18:13
  • I'll be honest, I stumbled across that patch after about a minute of Googling, I couldn't find the related issue. If I've got time later I'll try to see what's going on with the code, but some debugging in commerce_cardonfile_access to see which condition is failing for you would probably be the best thing to do. That'll give you something to go on, and if it's still not clear why just update the question and someone else might know – Clive Jun 10 '14 at 18:15
2

commerce_cardonfile looks for a 'create callback' from the payment method modules. commerce_authnet does not come with the callback, but this patch adds one:

add_card_on_file-2051357-21.patch

Here is the discussion: https://www.drupal.org/node/2051357

After I applied the patch, commerce_authnet_cim_cardonfile_create() was defined on both lines 760 and 1021. I renamed the latter so that Drupal was happy. Then "+ Add a card" became available on each user's "Stored cards" tab. And... it works!

Can I get my +250 points back? ;)

1
  • 2
    no you can't get back 250, its just like advertisement. – Bala Dec 17 '14 at 0:38
0

As Clive says, card on file restricted the ability to create cards outside the checkout process and the issue referred in the comments is this one: https://www.drupal.org/node/2051331

If you're using a card of file module version that includes the patch above (anything newer than 9 months as for today), you can try this workaround suggested in the issue: https://www.drupal.org/node/2051331#comment-8296497

   /**
    * Implements hook_form_alter().
    */
    function modulename_form_alter(&$form, $form_state, $form_id)
    {
        if($form_id == 'commerce_cardonfile_card_form') {
            if($form_state['op'] == 'create'){
                $form['credit_card']['type']['#prefix'] = '<div class="credit-card">';
                $form['submit']['#suffix'] = '</div';
            }
        }
        return $form;
    }

Also this issue might be related as well: https://www.drupal.org/node/2224063

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.