Are there "fake" credit card numbers I can use to test my integration?

Paul Singh's Avatar

Paul Singh

25 Nov, 2009 07:16 PM

Hey guys,

I'm fumbling along with the API doc and slowly making progress. Two questions:

  1. Is there a fake CC number/expiration date/ZIP that I can input to test that my integration works properly? (I've been entering random numbers and am getting "'4211111111111111' is not a valid credit card number" errors.

  2. I'm pretty new to RoR, but can you point me to some tips on how to handle the exceptions that get thrown when the card fails validation like this? (I'm asking new users to put this info in during the signup process and can't figure out how to get these errors to go into the standard form error messages that appear when a Rails validation fails...)

Thanks!

Paul

  1. 1 Posted by Paul Singh on 25 Nov, 2009 11:42 PM

    Paul Singh's Avatar

    Actually, I found a few "fake" CC numbers that seem to work... in case anyone else runs into the same question, here's what worked for me.

    FROM AUTHORIZE.net DOCS

    370000000000002 American Express
    6011000000000012 Discover
    5424000000000015 MasterCard
    4007000000027 Visa

    So now all I need help with is how to properly do error handling when/if CG throws an exception, etc. Any tips?

    Paul

  2. Support Staff 2 Posted by Marc Guyer on 26 Nov, 2009 03:59 PM

    Marc Guyer's Avatar

    I don't yet know the answer to your question about Ruby exception handling. It being thanksgiving day and all, I'll probably find it difficult to find someone to answer it. I'll try to find some time today to figure it out. I'd like to write a knowledge base article on the subject anyway. Let me know if you figure it out in the meantime.

  3. Support Staff 3 Posted by Marc Guyer on 26 Nov, 2009 08:02 PM

    Marc Guyer's Avatar

    Are you using the Hashrocket API wrapper?

  4. 4 Posted by Jon Larkowski on 27 Nov, 2009 02:35 AM

    Jon Larkowski's Avatar

    Paul, if you use Hashrocket's Mousetrap wrapper, it will raise errors when the CheddarGetter API returns error response codes. You can then catch those errors, and add them to your ActiveRecord errors collection. You do it in your model code, a little something like this...

    validate :customer_saved_on_cheddar_getter
    
    # bunch of other model code here...
    
    protected
    
    def customer_saved_on_cheddar_getter
      begin
        customer_attributes = {
          :email      => email,
          :code       => code,
          :first_name => first_name,
          :last_name  => last_name,
          :company    => company,
          :subscription_attributes => {
            :plan_code                    => plan_code,
            :credit_card_number           => credit_card_number,
            :credit_card_expiration_month => credit_card_expiration_month,
            :credit_card_expiration_year  => credit_card_expiration_year,
            :billing_first_name           => billing_first_name,
            :billing_last_name            => billing_last_name,
            :billing_zip_code             => billing_zip_code,
          }
        }
    
        Mousetrap::Customer.create customer_attributes
      rescue => error
        errors.add_to_base error.message
        Rails.logger.error error.message
        return false
      end
    
      true
    end
    

    That's the best I can do right now to get ya started. There's a bunch of other little complexities and special cases that come up, but this is the essence: make CheddarGetter communication part of your regular model validation lifecycle.

  5. 5 Posted by Paul Singh on 27 Nov, 2009 03:47 PM

    Paul Singh's Avatar

    Hey guys,

    For now, I've been using ADS' cheddargetter API wrapper... I'll take a closer look at the Hashrocket implementation though. Off the top of my head, it shouldn't be too hard for me to change over at this point.

    @Jon: Thanks for the example code -- that actually helps get me started pretty well!

    @Marc: Let me know when you start to put that doc together -- I'd be happy to help out.

    Paul

  6. Support Staff 6 Posted by Marc Guyer on 29 Nov, 2009 03:13 AM

    Marc Guyer's Avatar

    I'd suggest using the hashrocket implementation. It is certainly the most mature at this point.

  7. Marc Guyer closed this discussion on 05 Apr, 2010 08:04 PM.

Discussions are closed to public comments.
If you need help with Cheddar please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

28 Mar, 2024 10:45 PM
24 Jan, 2024 08:33 AM
11 Jan, 2024 07:13 AM
30 Nov, 2023 02:07 AM
22 Nov, 2023 08:41 AM