ActiveMerchant, Paypal and Rails
Written by Robin Fisher in 306 words
25
Mar
I’ve spent most of the past week playing with ActiveMerchant and Paypal in order to implement recurring billing for my app.
After a false start with Datacash and some fumbling in the Paypal Sandbox, I got started with a test account for Website Payments Pro (UK). This has the benefit of using Paypal as your gateway service and also as your merchant account. The fees for processing are slightly higher than other gateways but I find the all in one solution worth it so far.
I should mention at this point that Cody Fauser’s ActiveMerchant PDF from PeepCode was invaluable in giving me a start to integration. Although the book is geared towards a straightforward purchase (rather than recurring billing), the code was a great starting point. Thankfully, the ActiveMerchant library is very well commented and easily understandable.
In brief, to setup the recurring billing (implemented through Subscription model), an account is created using the subdomain as account key model. If the account is a paying account, the user is redirected to a secure page to enter their credit card details and create the subscription. The credit card information, amount to be billed and frequency are passed to Paypal in the following form:
Subscription.recurring(amount, credit_card, options = {:ip => request.remote_ip})
This calls a method on the Subscription class which sends the data to Paypal. If a successful response is received, the response and other information is stored in the database.
In terms of updating the subscription, this is easily done with the AM library by sending the profile id (which is returned by Paypal when recurring billing is set up) along with the recurring billing request. Using this method, credit card details, payment amount and frequency can be simply changed.
I’m more than happy to share the code I’m using if you want to leave a comment.
Thanks for the article! I’m glad you found the PeepCode book useful.
I’d be very interested in learning more about how you implemented the recurring payments. I’m in the middle of doing something probably very similar. Sharing your solutions would be greatly appreciated, and I’d of course return the favor.
I am about to implement this with exactly the same set up, seeing your code would be great if possible.
Much appreciated you post.
I’d really appreciate seeing some code that works for a subscription model.
I’ve also been thinking about picking up that PeepCode book. (The others I’ve bought have been helpful.) Do you happen to know if it has enough information relevant to Paypal (US)?
This is great. I’d love to check out the code as well.
I’d love to take a gander at your implementation as well. I’ve found lots of good info on payment processing with AM per-say, but little regarding subscriptions.
I would love to take a look at your code. Great article.
Thanks.
I’d also be interested in seeing some code, I’m working on my first subscription based app at the moment as well
I’d like to see the code as well. I’m currently testing with the sandbox.
You said you wouldn’t mind sharing your subscription code. Would I be able to get a copy please?
Are you still sharing your subscription code with folks? I’m in the middle of implementing the same thing and would love to see your code. Many thanks!
Hey, Just wondering if you were able to share the code. Would be very helpful.
Thanks
I’d be interested to see how you are doing this, as I am in a similar situation, just not quite so far down this path.
Thanks!
I’m also trying to implement a recurring payment solution in the app I’m currently working, I need a subscription system and some kind of IPN for my app, everything seems more difficult because its an UK company, and most of the gateways don’t work with UK companies. Would be very helpful if you’re able to share the code! thx
I’m interested in seeing this code as well. Where do you store customer credit card info?
Hi Robin,
Great to know you got to the other end! I am integrating a subscription system into an application and would really like to see the code and how you implemented this. I’m also going to get the PDF you mentioned so thanks for that pointer too.
Thanks!
I would love to see your code if you’re still sharing! I have the ActiveMerchant PDF and I’ve been coding against a number of different options this week, to get a feel for them — I’ve been about to throw up my hands a number of times when dealing with PayPal, so this would be a boon!
Thanks for sharing. We have a Canadian client that would like to manage recurring subscriptions and looks like paypal will handle all of the currency conversion also. If we could have a copy of the code we would appreciate that and can share back anything we modify that will be useful