Search code examples
ruby-on-rails-3paypalactivemerchant

Recurring billing with Rails - what are my options?


Before jumping in I'd like to know what all of my options are, and, if possible their pros and cons.

The two I know of are using ActiveMerchant, or the paypal_recurring gem, but will they satisfy these requirements?

  • Ability to accommodate monthly and annual billing
  • Ability to suspend, cancel accounts etc
  • Deal with out-of-date card details or failed payments

The to-do list for the paypal_recurring gem includes 'adding support for IPN' - how will not having this impact functionality?

I know there is the railskit SaaS but I'd rather code something myself as the railskit is still on 3.2.1.

I know there are services like cheddergedder/chargify etc, but do they tie you in? Are they US only? Are they worth considering - or are they usually just aimed at non-developers?

Thanks in advance.


Solution

  • I just finished going through this, so I'll try to shed some light on your options. I ended up using Paypal Express Checkout for all recurring purchases through Paypal. We had a custom-rolled recurring billing setup that charges a customer's credit card monthly through Authnet, but had to switch because we needed an international solution, and Paypal was one of the only ones that supported the currencies we needed, and wasn't entirely a nightmare to code.

    You can use ActiveMerchant for recurring billing with this plugin, though keep in mind that it is not officially a part of ActiveMerchant, and therefore is subject to break if ActiveMerchant changes how it handles certain things. Because of that, I ended up using the paypal-recurring to handle communication through Paypal, and then rolled my own IPN parser, with help from Railscasts. Another link that helped me a lot was this, though all the :txn_type values ended up being different.

    With regards to that last link, here are the 4 :txn_types that I specifically watch out for:

    1. express_checkout - first postback.
    2. recurring_payment_profile_created - sent on first postback when the user first subscribes.
    3. recurring_payment_profile_cancel - sent if user cancels subscription from Paypal's site.
    4. recurring_payment - Money has been transferred to your account. This is what I wait for before I renew their subscription on a monthly. This post also comes with payment_status, which needs to be completed.

    The other stuff you mentioned, like handling failed payments and out-of-date cards, is handled through your Paypal account.

    Just a word of warning - the only reason I ended up using Paypal is because it is universally recognized and trusted, and it accepted international currencies. There is an enormous amount of documentation on their site, and most of it is redundant, confusing, and entirely too long. My recommendation is to make sure you really want/need to deal with recurring payments, as they are difficult to implement correctly and can be more trouble than they're worth.