Hello Chris! Thx for a great episode! So i noticed in this video that you updated some field on the current user to save the last 4 etc on the card. I was thinking that i could use that function to update other fields for the user as they subscribe to my service. I use pundit to setup a role based access to my app and i was successful in changing the role from demo to premium at the same time as they added a card and subscribe to my services but when i also try to update other fields it fails.. could the reason it fails be because of the way the form is built?
That form should work just fine for that. If they're submitting other information, for those fields you'll want to make sure they have the 'name' attribute so they get submitted (unlike the credit card fields). Aside from that, make sure you're permitting those extra params and that should probably do the trick.
So i need to name it with that ever the field it is under the user model? and then put what params in the controller to permitting,
Yep! Just like you would with a normal form. This one isn't really much different aside from it taking the credit card fields and handling them specially with JS. The JS will submit the form like normal, so your other fields will get treated just fine.
You can use the regular form field helpers like input_tag to make that easier.
I added form tags for the fields like this: "<%= text_field_tag :address1, current_user.address1, :class => "form-control" %> but i still get the "You must supply either a card, customer, or bank account to create a token." when i try to post the form.. and i'm not getting much in the console so i don't know what is breaking :)
Have you had the issue where the pay button doesn't respond until you either have reloaded the page or clicked it 2 or 3 times?
Nope, but might want to check to see if you've got JS errors or conflicts with Turbolinks.
I had same issue and its a simple fix.
ready = ->
the stripe functions go here
Awesome episodes Chris...got me through many huddles!! One question: How do I display the dates of the current billing period to the user on the Edit page? I would like to show the date when the current payment expires.
Thanks again Chris for this. For some reason my "Card update" is giving the following error:
"Invalid source object: must be a dictionary or a non-empty string. See API docs at https://stripe.com/docs"
I have exactly the same code as you do. When I inspect the element on this page it says:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Not sure why, but has anyone witnessed this issue? See screenshot for error message. Thanks.
First I would check to make sure that the user has a stripe_subscription_id saved in the record. You might be passing a nil in on accident.
Yes, the user has a stripe_subscription_id. In fact, cancellations and resubscriptions are fine, but the error comes in the card update.
Always something like that, cascading into a bug showing up elsewhere. :) Glad you got it fixed!
How easy is it to extend this so that if a payment does not succeed (say a renewal), the user's account is downgraded to basic (Free) account automatically?
Pretty simple. You'd need to basically listen for the subscription cancellation webhook to come across and then in there you can just move the user's plan over. The webhook will be your way of knowing that the last payment attempt failed and the user's paid subscription canceled. It'll just send a notification to your server and as long as you're listening for it, you can run the code to downgrade to the free plan. Make sense?
Check out this episode on the webhook stuff if you haven't already: https://gorails.com/episode...
Great tutorial. I wanted to pick your brain for a second. I followed your tutorial to the letter aside from using rails 5.0.2 and Bootstrap V4. For some reason when in the process of resubscribing a customer who needs to update to a new payment method using the "Use a different card" button, the hidden form only appears for a second and then disappears. I've checked my code against yours on Github and everything appears in order. If I click into one of the form fields before it disappears, the form will not go away but when I click on the submit button, the customers card is not updated. Any thoughts?
Hmm, hard to say. I would start by inspecting the HTML and then stepping through the JS code line by line and making sure those are working as expected. You'll figure it out pretty quickly if you break it down and find the spot that's not working like you want it.
Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.