• Billing on the Brain: Credit Card Storage

    February 07, 2008 by PJ Hyett

    FamSpam is a subscription-based service, so we had to come up with a solution for billing customers every month. One solution would be to mail them monthly invoices like a credit card statement. The other, not completely insane solution, is to just store their credit card information and use it when it comes time to bill them each month.

    How does one store credit card info?

    You have two options: store it yourself or pay someone to store it for you. For us, storing credit card information on our servers was out of the question. The technical and legal hurdles are enormous, and just like our stance on using someone to send our email, this is absolutely another service that’s worth paying for.

    Where does one store credit card info?

    The simplest solution is to find a merchant that also has some sort of secure ‘vault’ service. The concept is straightforward: you give them the customer’s credit card info, they give you back a vault id that you store, and then you use that vault id anytime you need to bill them.

    Code on Dynamite?

    ActiveMerchant has support built-in for dealing with vaults, so using them works something like the following:

    Step 1: Bill using credit card (and storing card in vault)
    creditcard = ActiveMerchant::Billing::CreditCard.new(
      :type       => 'visa',
      :number     => '4242424242424242',
      :month      => 8,
      :year       => 2009,
    )
    
    gateway.purchase(1000, creditcard, :store => true)
    
    Step 2: Bill using vault id
    gateway.purchase(1000, vaultid)
    

    Not only does ActiveMerchant have a great API, it also includes wrappers for over two dozen gateways. Give it a good look before you roll your own code.

    But, wait, there’s more!

    Next up is how to handle subscriptions now that we know how to store credit cards, the suspense is killing me!

    • Comments

    • Sebastian 13 days later

      thanks fpr sharing your experiences!

      just curious: what payment service do you use for famspam?

      i am searching for some vault service that I can use from europe. any suggestions?

    • dave 15 days later

      The suspense is killing me… 2 weeks without word on how you handle your subscriptions! :)

    • jason 18 days later

      The suspense is killing me too! I am working on my own billing system and the first two posts have been extremely helpful!

    • sean 20 days later

      oof! I think I just died from 20 days of suspense!

    • Eliot 23 days later

      ”:store => true” suggests Braintree, as dustym pointed out to me.

    • Michael 27 days later

      Interested in seeing how your subscription model is designed as I did this today and would like to see if I’m missing anything sooner rather than later. Come on PJ :-)

    • Mike Mangino 2 months later

      This is pretty cool. As the author of the Braintree gateway, I’m excited to see so many people using it.

    • Jason Long 2 months later

      Yes, please post the next installment! I’d love to hear your thoughts on the monthly processing bit.

      Thanks!

    Participate

    We reserve the right to remove any comments deemed offensive or off topic.

  • dynamite!

    The Err Free Weblog, wherein we discuss the finer points of business, coding, our products and, for better or worse, the occasional rounded corner.

  • Advertisement
  • products

    FamSpam
    The easiest way to stay in touch with the people you love.
    Err the Blog
    Our Ruby and Rails observations and experimentations.
Original Content ©2008 Err Free, LLC
contact us

Err Free

Contact Us

We're only an email away: work@errfree.com

Got a cool new project, speaking gig, or top secret idea you think we'd be interested in? Hit us up.