#289 PayPal Recurring Billing pro
Here I show how to add PayPal recurring payments to an existing checkout process using PayPal's Express Checkout and the paypal-recurring gem.
- Download:
- source codeProject Files in Zip (137 KB)
- mp4Full Size H.264 Video (60.2 MB)
- m4vSmaller H.264 Video (30 MB)
- webmFull Size VP8 Video (34 MB)
- ogvFull Size Theora Video (73.9 MB)
TL;DR Use Stripe :)
Actually I really appreciate the effort you took to put this together Ryan, even if it came out a bit longer than expected. It's certainly not one of the easier pieces of rails integration and is a great choice for a pro episode. Many websites will still require this so it's a valuable addition!
Unfortunately many of us have no option to use stripe. So this is a great resources for people outside the US.
Thanks ryan.
It's also nice for customers who prefer PayPal.
As a web developer, I know some clients love cutting corners and don't secure things like they should. I mean, look at Sony and their recent PSN issues. So I only checkout from PayPal except on sites like Amazon. I've never heard of PayPal servers getting hacked.
they got DDoS-ed
That's far from getting actually hacked though and there's no loss of customer information.
Hi Ryan,
Thanks for this amazing cast.
I was wondering if you can do another cast regarding Ebay complex database categories. Is Ancestry gem enough or should we go deeper.
Thanks anyway!
Thank you! Looking forward to the episode about handling insufficient funds, end of subscription and possibly the case when a user changes his plan.
I would love to see that as well.
I would also like to see an episode on insufficient funds and subscription cancellations. I would also like to see how you create tests for external web services like paypal, stripe or whatever.
+1 for testing the external web services. Even just a taste of it would be cool.
Testing of external web services would be awesome!
+1 for testing and +1 for future episodes on PayPal recurring subscriptions!
I know it's kinda late, but +1 for testing external web services as well.
I second that. Excellent cast!
WOW! what a cast! I also want to see this.
Me too, great work! One of the best I see here.
Agreed with Mischa! We need a Paypal Recurring billing II episode. =D Keep the great work Ryan!
+1 on handling insufficiant funds, etc
+1 for a follow up cast.
Awesome Stuff!
No worries on the length, please do follow up casts!
I've learned a ton!
+1
+1 I am looking forward to a feature complete cast following this one up!
Thank you for releasing this screencast about PayPal recurring billing.
I am also interested in a follow-up episode re handling insufficient funds, changing the plan or canceling the subscription.
Thanks for accommodating us non-US users with this cast. Hopefully Stripe will do too soon.
There is no PayPal yet in my work, but it was interesting to watch this episode. One thing that bothers me though is that you skip testing part which is crucial in billing and payments. I know, the episode would be two times longer if you covered this as well but it was very scary to see you just quickly testing the stuff in a browser.
Thats why paypal provides a sandbox :)
But when you get out of it in production you'd better have a well-tested billing system :-)
Excellent and just in time. I've been stuck trying to choose between Spreedly, Chargify, Recurly etc. but they're so expensive by the time you factor in internet merchant accounts and payment gateways etc. I really want to hear more about Paypal recurring payments!
I'd love to see a future episode on advanced subjects such as failed payments, canceled subscriptions and importantly upgrades/downgrades between packages and the associated pro-rata calculations. Usually very complex stuff (in terms of business logic) but I'm sure it's a subject you can cover with relative ease given your style! :)
Thanks for a great screencast!
Is something like this what was used for the railscasts pro? I thought my statement showed something other than paypal..
(may we ask what was used for this sites payments?)
Seems to me when I signed up, I looked at the HTML, and he was using Braintree. Ryan, interested in knowing if this is true and if you are planning on converting to stripe for credit cards?
I don't plan to switch to Stripe since I already have Braintree setup. They're both great though.
I'm using Braintree at the moment, but will be adding PayPal as an alternative checkout option soon.
Great work, i've been using active merchant fork supporting PPR for express checkout, and this does seem like a much lighter solution.
Very nicely done :)
Maybe another idea for an episode is how to save sensitive data (API user/password keys, etc) in production environment, while not disturbing Capistrano deployments etc.?
Or is it just me? :)
To do this you can place any sensitive data config files in the shared directory on the server and then symlink/copy them over upon each Capistrano deploy. See the how I'm doing it here for an example.
Can you actually explain what this does (are you copying or symlink?) and why (why separate directory since rails has a place for everything?)? From a beginner experience deploying rails app seems complex. Thanks.
I would love to signup to watch the Pro screencasts, but I only have a Paypal account.
I am guessing that this screencast came from a need on how to implement for the Pro casts. I expect you will find that payment option pretty soon. But I imagine there are other things that need sorting out:
PayPal support will be coming soon. Thanks for your interest in RailsCasts Pro.
Love to see more!
Cancelation, upgrade/downgrade, Error handling.
second that too
+1
A++++ would buy again.
+1
+1
+1
+1
+1 :)
+1
Looking at railscast.com on github, it has not been committed to since 11.08.2011. Are all this PRO features exluded form the open source railscast repo?
I have not yet made the Pro features open source, but i plan to at some point. I just want to make sure it's air tight before I do because I'm dealing with more sensitive information.
Excellent! So handy. I'm outside the US so Stripe is no use to me. We're woefully behind in terms of SaaS billing options here (Ireland/UK).
Looking forward to the next installment on how to handle failure callbacks. :)
Great stuff as usual Ryan. I'd be very interested in how to handle suspending a recurring payment for X number of months. Use case for that: SaaS company has coupon codes for free months, user already has a subscription with recurring payment but uses a free month coupon, need to skip this month's recurring payment but start again next month.
Many thanks and keep up the capital work.
I hope this (i.e., PayPal) is offered as an option in the near future to purchase a Railscasts Pro subscription!
Me too. I find it strange that there is a screencast about Paypal, but that the option is not yet implemented in to the website.
I love to use Paypal to subscribe to the pro section of this website, because I don't have a creditcard.
I will be adding a PayPal checkout option soon, stay tuned.
Any chances to subscribe Railscasts Pro via Paypal yet?
Yes, I will be adding a PayPal checkout option soon, stay tuned.
Great episode. But "Website Payments Pro" is not available in Germany :(
I wish there was a good solution for this but I can't think of any alternative recurring payment method that will work in Germany. If you have suggestions please let me know.
see my post below Hannes H. - you should be OK.
Tying to pick up some Coffeescripting from this episode:
Should the subscription.handleStripeResesponse function call not contain the two arguments (status and response) in the code above? The definition of the function includes these two.
Please explain.
Thanks.
Bharat
Great episode!
+1 For cancellation and insufficient funds episodes.
Stellar episode, Ryan!
I would love to see a Part 2 on cancellation and insufficient funds with test cases, hard to find relevant practical examples to learn from.
Keep up the great work!
Great screencast! Definitely a +1 for Part II; covering insufficient funds and cancellation would be really appreciated. Thanks!
wow - monster cast! love your work Ryan and i'm happy to start paying you some money for Pro as you have taught me so much over the years / every day still! i'm UK based and as Jon Hope said, online payment solutions in the UK are in the dark ages and PayPal is a safe route. i don't think a WPP account is necessary though, a Standard Business account should suffice when using the PP Express Checkout approach (source: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECGettingStarted) ... and i quote from there:
I hope that helps clear up some confusion for British (and probably German) customers.
Thanks for that information, Glenn. You said "should suffice" — did you have a chance to test that theory? Does it work?
One of the best casts I've seen from you! Big +1 for covering insufficient funds and cancellation. Would be a shame not to do it now that you refactored everything nicely into its own model. :)
Ryan, are you hoping to add a cast on Braintree as well? Seeing that you use it and that they offer Ruby support, I'd love to see a cast on it. Is it similar to paypal in terms of setup on the Rails end? Thanks!
Thanks Ryan, cast on cancellation would be great
Thanks Ryan, cast on cancellation would be great
+1 for follow up episode on PayPal integration!
Great screen cast Ryan, quality is always!
Is IPN working for anyone? I am not receiving IPN on payment made or for the recurrence.
My sandbox application is available on externally accessible domain.
Any help on this?
Thanks
Rohan
Ok guys I figured out my above problem, had to enable IPN for my paypal account.
Thanks
Rohan
Amaizing episode here. A railscast over cancellation/changing plans and other events like these that might happen would be awesome!
Thank you!
First of all, thanks for a great in depth episode!
I would definitely love to see cancellation / card decline situations being handled in the next ep. Thanks Ryan.
I bought a pro subscription just for this episode, and I'm not at all disappointed. A huge PLEASE for Paypal cancellation episodes!!
Same here. Exactly what I expect from Pro episodes. The full cycle with cancellation, changing plans and insufficient funds would be awesome. Thanks Ryan! (also waiting for PayPal implementation on Railscasts :)
signed up for pro specifically for this episode. Thanks!
another +1 for a follow up on handling cancellations and insufficient funds
I implemented the code as in the example, but for me it's taking money twice: first with request_payment and then with create_recurring_profile (probably because the subscription starts today and the customer needs to pay today?)
Does anyone else have this problem?
It's not a problem, it's how paypal works. If you create a recurring profile, you'll get a recurring payment sometime during the start day of that profile.
If you request an initial amount too, you'll receive the initial payment sometime during the day that you create the profile AND a recurring profile payment during the day that the profile actually starts (if you create it with the start date set as today, the customer will be billed twice during today)
The request_payment called before creating a recurring payment charges the customer instantly, and has nothing to do with the recurring profile itself (it's a totally separated payment)
Having these in mind, a couple of ways of doing this would sound like this:
1) Create a request payment, and if it passes, create a recurring profile, starting today+30.days (not sure it's very cool, n'or consistent)
2) Create a recurring profile starting today, and process the billing in your application by using an IPN listener when paypal sends it (maybe give the user a period of I dunno, 24-48 hours for the "Complete" IPN answer to come from paypal, in which he could use your app)
Did you fix this issue? Could you share the solution? Thanks.
Thanks Ryan, I'm about to do exactly this on a project and I've only been coding for in Ruby for three months. This cast is a massive help, thanks so much.
I'll be figuring out cancelled subs and failed transactions myself in the next few days, but still, + 1 for a part 2!
: )
Nice, I am satisfied, but yes I would like to see more on this topic, especially on error handlings like insufficient funds as well as tests and what is needed to be set in place in rails 3.2
Working with the code from github I learned:
* copy the folder best to a new path
* had to upgrade my rvm with iconv - http://beginrescueend.com/packages/iconv/
* run migrations
* realize there is no new for plans, thus open interactive console like this: rails console
* insert new plan p = Plan.new
* assign to p values, p.kisses =10 etc
* p.save!
* rails s
Another awesome episode Ryan!
I'd also like to add my support for a follow up episode that covers cancellations, insufficient funds etc
Just want to add that it's watching episodes like this that shows what a fantastic Ruby coder you are Ryan! I always pick up some tip or another watching you code :)
I'd also like to add my support for a follow up episode that covers cancellations, insufficient funds etc
Awesome episode!
I would love to see how to use recurring payments with IPN callback messages :)
Very nice episode. I bought the subscription just to watch it, and it didn't disappoint. Keep up the good work!
Hi Ryan,
I want Paypal recurring payment to notify with option notify_url, but gem "paypal-recurring" returns the following error:
undefined method `notify_url=' for #PayPal::Recurring::Base:0x131651bc
I do this at action "create_recurring_profile". Here is the content of the options:
Are you looking for ipn_url, not notify_url?
Hi kmoczydlowski,
I used ipn_url and tested with Link
But there's still one issue:
I update Ryan's methodology with the following:
But PayPal does not call back my "ipn_url".
I checked and saw the transaction was completed. I can see the transaction ID by printing the "reponse" value on console
By the way, I don't know whether PayPal will call my "ipn_url" in the next month recurring billing.
It can take anywhere from 24-48 hours for the IPN to go out actually. I assume this is why in the tutorial we request payment and then create a profile. To provide instant feedback on payment rather than have the person wait in order to start using services.
Try canceling the subscription and add a method in your ipn handling.
I found this a bit useful:
http://ianpurton.com/adding-paypal-subscriptions-to-your-rails-application
Hi kmoczydlowski ,
During the last month, I've tested many scenario but ipn_url does not work. For briefly:
1. I've set the ipn_url within Profile section of PayPal Account of Shop Owner
2. I set ipn_url as reference here: https://github.com/fnando/paypal-recurring/issues/7
3. I set the frequency of payment to DAILY. All the transactions are OK within the Paypal History.
BUT, IPN_URL just does not work
Hi All,
I had found solution for this issue.
Combine the following code with this tutorial of RailsCasts
def makerecurring(payment_notifications_url,current_user)
process :request_payment, ipn_url: "#{notifications_url}?custom=user_id#{current_user.id}"
process :create_recurring_profile, period: :daily, frequency: 1, start_at: Time.zone.now, ipn_url: notifications_url
end
Note:
1. ipn_url should be put within "request_payment" scope
2. Although I set up ipn_url for "create_recurring_profile" but it does not work.
If I have any more information, I will update.
I found that setting ipn within paypal settings on the account webpage it works.
Under My Account -> Profile
Then listed below select
Selling preferences -> Instant Payment Notification preferences
Set your callback address here and they'll ping though correctly.
Great episode! looking forward to see next episodes on recurring billing.
Such a great episode!
Can you please guide me how I can go with cancellations, insufficient funds etc..??
Thanks in advanced.
When I submit the form of new subscription, I get this error:
RuntimeError in SubscriptionsController#create
[{:code=>"11581", :messages=>["Invalid Data", "Profile description is invalid"]}]
Application Trace | Framework Trace | Full Trace
app/models/paypal_payment.rb:46:in
process'
make_recurring'app/models/paypal_payment.rb:18:in
app/models/subscription.rb:26:in
save_with_paypal_payment'
save_with_payment'app/models/subscription.rb:14:in
app/controllers/subscriptions_controller.rb:18:in `create'
Can any one help please ?
I found the solution, I have to send the same data sent at checkout, in the create_recurring_profile
"That’s it for this episode on PayPal. It was longer than usual but it’s still not feature complete as we need to handle customers who have insufficient funds or who cancel their subscriptions. These may be covered in a future episode."
PLEASE RYAN, COVER IT :D
+1 for a followup cast
as always - awesome work Ryan!
Thanks a lot!!!
+1 :)
+1 for follow up cast!
How can I use it in production? which option must I pass?
Thanks.
+1 for a follow-up railscast!
I need closure.
+1 for a follow up!
+1 for follow up!!!!!
whats the difference between "Website Payments Pro" and "Payflow Pro"? This tutorial is already outdated.
Also, I'm having nothing but problems. I copied the same exact code for period and frequency and I get errors:
[{:code=>"11518", :messages=>["Invalid billing period.", "Billing period must be one of Day, Week, SemiMonth, or Year"]}, {:code=>"11516", :messages=>["Invalid billing frequency", "Billing frequency must be > 0 and be less than or equal to one year"]}]
For some reason when I click to confirm subscription at the very end, I get an "Unknown action.. The action 'update' could not be found for SubscriptionsController" error.
So on subscriptions#create, it's actually trying to point to the non-existent subscriptions#update. Any ideas why??
+1 for follow up. Baa.
+1 for follow up, the screencast is not very useful if it doesn't cover cancellation. Great screencast anyway!
+1 for follow up
[{:code=>"10478", :messages=>["Invalid Data", "Recurring payments profile description must be provided if the billing agreement type is recurring payments."]}]
what does this mean if i get this error
The tutorial is great, helped me alot, but I have some problems with one thing.
In the tutorial in the first moment RB say to make a first express checkout payment and right soon create the subscription, but this is very bad, because the whole transaction happen in two parts, and I've been in troubles when the first payment happend smoothly, but the subscription is not created for some error.
Avoid this!
https://github.com/railscasts/289-paypal-recurring-billing/blob/master/saas-after/app/models/paypal_payment.rb#L15
Let the subscription make the first payment, case the subscription creation fails, the user won't make a first payment but no one subscription.
Excellent tutorial Ryan as usual .Thank you very much. Just an idea for future episode - how to allow user to top up his in-site account using Stripe/Paypal and activate/deactivate services provided based on the account balance.
How to send custom variables for IPN?