Ask A Question

Notifications

You’re not receiving notifications from this thread.

Subscriptions with Stripe Discussion

Discussion for Subscriptions with Stripe
Fritz Rodriguez Jr. Fritz Rodriguez Jr.

Hey Chris! Not sure if this is just me, but there seems a problem downloading the video's.

Reply

Hmm, I tried downloading too and it keeps cutting short. It should be almost 600MB. Not sure what's wrong. Does the video fully load for you?

Reply

Thanks! I actually wanted a course to be released of Stripe Payment Processing since I just lost my OM account. This definitely helps me out!
I have 4 months left on GoRails and I'm excited to learn as much as possible on Stripe payment processing. I'm starting this video today and I'm really happy that you introduced this course OneMonth!

Reply

Is it possible to put the normal stripe js popup instead of a custom form????
If so, please make another screencast on that

Reply

You can swap a lot of the JS out with the Stripe Checkout button. The same process works there. You'd keep the token callback and server-side code. It's pretty much the same minus the form and the JS listener for submit. :)

Reply

The checkout.js popup is nice, but if you wish to use a coupon code, the custom form is required I believe. Maybe Chris knows a way to get around it.

Reply

So i have been following along with this screencast and i got it all to work :) I even added a select box so could choose what plan i wanted to use. However i would like to have multiple boxes each for a certain plan. What would you recommend.. checkboxes in the form of buttons.. or something else? I don't think a dropdown select box is very selling.. I would like to have 3 or 4 boxes next to each other with different length of the subscription like 1 months and 3 months and so on..

Reply

My suggestion would be to make a pricing page that have links to the checkout page and you put a "plan" in the URL with the ID of the plan to sign them up with. That way you can store the plan_id in a hidden field in the form nicely.

Reply

Check boxes make for great easy additions and you can hide/show them with some javascript based upon the plan that's selected.

Reply

Oh damn, learning a lot from here. Like the devise's user_return_to method. Damn nifty!

Reply

How would I need to modify the SubscriptionsController to allow for multiple Plans (monthly, every 3 months, yearly, etc.). Let's suppose I have a Plans model and table where I store the info about my plans. Your current subscriptions controller hard codes in the plan: "monthly" input. How would that change?

Reply

Great question and I meant to make a follow up episode talking about that. I will still do that, but here's the gist:

1. You'll need a pricing page that lists the plans. When you click on the link to subscribe, you'll pass the plan ID in the URL to the checkout page.
2. The checkout page will load up the plan based on the ID to verify it exists and is allowed (makes it easy for changing things over time).
3. You'll pass the plan ID as a hidden field during checkout
4. SubscriptionsController's create action will lookup the plan again to verify it and then submits the stripe ID instead of the hardcoded "monthly" value
5. After signing up, you'll link the user to the plan as well so you can use it for your authorization and functionality of your site that they paid for access to.

That should do the trick! I'll try and record a screencast on this very soon as a follow up.

Reply

Hi, Chris
I'm getting this error. I looked around online but still hitting a wall. Thoughts? Thanks :)

Reply

Error

Reply

Are you sure that params[:stripeToken] is set to the value from the JS? Check your params?

Reply

I'm also facing this issue, apparently it seems when we come to 'checkout' page from any other page (e.g. pricing) the JS in checkout is not loaded correctly due to which the token is not being created. If you refresh the checkout page and then submit the form it should work fine. Probably the turbolink issue.

Reply

Love this episode Chris...thanks!

One question, why did you put the `current_user_subscribed` method in the ApplicationController and not in say ApplicationHelper? That feels like something that the views will use, which is what the helpers are for, no?

Just curious to hear the logic.

Reply

Oh good question. Subtle thing here, but very important. The reason it's in the controller is because you're probably going to use the same logic to do authorization in the controller actions. You can easily expose the method as a helper using helper_method for the views, so this allows you to write it in one place and use it in both the controller and the views.

Reply

Chris, my subscription.coffee file is never getting called. Therefore, I'm getting the following error even when I comment out the #$form.get(0)submit() as you instruct around 24:31 in the video. Is this due to turbo-links? Any help on this would be much appreciated.

Reply

You might double check that that file is getting required in your application.js. Sometimes that can be all that's missing. If it is, then add some print statements to see if your code is actually running, might be just something simple there.

Reply

anybody get this error: "Uncaught SecurityError: Blocked a frame with origin "https://js.stripe.com" from accessing a frame with origin "http://localhost:3000". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match." I'm stumped.

Reply

Likely some configuration issue. I'm not entirely sure what causes that, but it's definitely fine to run on localhost. Probably like this guy where you've got a mistake somewhere causing their JS to run incorrectly: http://stackoverflow.com/a/...

Reply

Hi guys - i'm receiving a curios intermittent error.
When I go to /subscription/new I get the following screen:-

https://uploads.disquscdn.c...

Please note the error, "Could not find payment information".

I'm not submitting the form, but the error is appended.

I then complete the form and select submit and get the following error:-

https://uploads.disquscdn.c...

I suppose this is to be anticipated.

I then check my stripe test account and I have an error here:-

https://uploads.disquscdn.c...

Any root cause analysis would be really appreciated.

Reply

Did you fix this? I'm getting the same problem.

Reply

Nice tutorial. Using this payment form, if form is submitted multiple times, multiple subscriptions occur for a single customer. Will stripe charge customer for all such subscriptions or only based on last one?

Reply

You can fail early server side if there's a subscription ID on the user so you can hopefully avoid double charging them. I believe stripe does allow you to have multiple subscriptions per user, so you may not want to rely on that.

Reply

I am using Stripe in development just fine, but when I push up to production on AWS, the logs are telling me "Stripe::AuthenticationError (No API key provided. Set your API key using "Stripe.api_key = <api-key>". " I am using "Stripe.api_key = ENV['STRIPE_SECRET']" which is pulling from the .env file, which is of course in my .gitignore file. So it's not pushing up to AWS as intended. How do I get Stipe production ready, as least in terms of the api key? I am using "ENV['STRIPE_PUBLIC']" in the meta tag just like the video. I'm not getting an AWS error here, which confuses me as it getting the key from .env as well. Any help would be appreciated!

Reply

Hey James, are you using Figaro for the .env file?

Reply

Would love to see you optimize that controller.

Reply

Hope everyone is ok.
I have question about my rails app.
I get this error in heroku
Stripe::AuthenticationError (No API key provided. Set your API key using "Stripe.api_key = <api-key>". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email support@stripe.com if you have any questions.):
yet all is ok in localhost which I use c9.io account.
Does anyone has any idea what is going on?
if more info is needed, I gladly provid
thank you

Reply

Hey! Sounds like you're just missing your keys in the production environment. Make sure you put your live Stripe keys in your secrets.yml file and that should fix that problem for ya!

Reply

Hope all is fine.
I recieve this error
ExecJS::RuntimeError in Listings#index

I did the following
1. ExecJS::RuntimeError in Listings#indexs did not work
2. install gmes, exechs and therubyracer did not work.
3. try to find runtimes.rb and could not
4. I get rid of //= require_tree . error goes away but after awhile it comes back
Could anyone help me to fix it?

Reply

I am learning so much from this Episode! One thing, after putting my secret/public keys in my environments/development.rb as recommended at 29:34ish, I get an uninitialized constant ActionView::CompiledTemplates::STRIPE_PUBLIC error trying to access the subscriptions#new page. Is this a common problem? It seems like I must be doing something simple wrong...

Reply

Hey Liz! :D

I would say, try restarting your Rails app. If you make a change in any of your config files, you generally have to restart your Rails server so it can get the new changes. The rest of the code auto-reloads when you make a change but this stuff does not.

Reply

https://uploads.disquscdn.c... Just so everyone is aware.. The card details that Stripe returns in the form around 47:22 have been changed by stripe they are now:
exp_month
exp_year
brand

Ive added a photo with the updated values incase anyone hits a snag retrieving data.

Happy Floundering :)

Reply
Charles Williams Charles Williams

I am writing this comment because of something that took me a long time to figure out that might save people a lot of frustration if they run into same issue. My app has a custom made login system and doesn't use devise, but everything else was the same as this tutorial and I kept getting an error "the customer has no attached payment source. I figured out the javascript was not loading properly unless I reloaded the page. Using Rails 5 and Turbolinks 5 in my subscription.js.coffee file instead of putting jquery -> I put $(document).on "turbolinks:load", -> and it made the form submit and load the coffeescript properly. It is a known issue that turbolinks doesn't always play well with javascript and there are many ways to get around this. I am an ametuer at best at rails/javascript so definitely do your own research as well.

Reply

Yep, this is because Turbolinks 5 works differently than the previous one where you could use jquery.turbolinks to enable all your standard jQuery -> code to work as expected. Thanks for sharing the reminder with everyone!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,969+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.