Dec 03

About a month ago one of our development teams is fortunate enough to have the chance implementing ServiceMerchant plugin
It is a plugin that makes use of ActiveMerchant, but designed specifically for recurring billing / subscription payment requirement.

As with all other gems, the best way to understand a gem, besides asking shifu Google, is to dig into the gem code itself and find sample apps, example usage, test units, etc

It’s pretty straightforward, and yet I feel like wanting to share some interesting things:

  1. If your PayPal timezone is different from your server’s timezone, you have to take note. Otherwise PayPal might refuse user payment because the start subscription time is in the past!
    Assuming you are saving times in UTC in your database, the following code would work well as the start subscription date passed to PayPal:
    TZInfo::Timezone.get(PAYPAL_TIMEZONE).utc_to_local(subscription.starts_on)
  2. You want to keep a history of user activities (valid payments, invalid payments, cancellation, etc). In this case you’ll have to set a notification URL in your PayPal setting. Make sure the URL is accessible by Paypal, and check the example in ActiveMerchant:
    /lib/active_merchant/billing/integrations/paypal/notification.rb

The necessary tweak is that we have to handle the case where a subscribing customer’s credit card on file has expired or becomes invalid – in which case we have to terminate the customer’s subscription on our database.

Btw if you need to develop a recurring billing paypal feature on your Rails app, we may be a good partner. Contact us info[at]kiranatama[dot]com

One Response to “PayPal Recurring Billing Ruby on Rails”

  1. Good , I am looking for payment solution in ruby and you came as great help for me.
    Thanks i will definitele try this soon.

Leave a Reply

Security Code: