This is a great way to wire up stripe into rails. You saved me hours of trying to figure it out myself. A stripe checkout page up and running in under half an hour. Boom! Fantastic stuff as always, Chris. Thanks for making this super badass video!
Dude what an awesome guide! It would be nice to see an updated guide for the new version of Pay, but overall just combining this guide with the latest configuration docs worked wonderfully!
I just wanted to let anyone else know who was wondering, you can add the 'line items' with options - so you could do something like line_items: [ { price: "price_******", adjustable_quantity: { enabled: true, minimum: 1, maximum: 10 }, quantity: 1 }, { price: "price_**********", adjustable_quantity: { enabled: true, minimum: 1, maximum: 10 }, quantity: 1 } ] To add quantities or user adjustable quantities for example and multiple products at once. I couldn't find in the rails-pay gem docs how to do this, but you can use any of stripe (or I'm sure other services) options.
Hey, overall Amazing tutorial as always. but I am amazed without *success_url* & *cancel_url* how do you return your page on the success screen? any clue?!!
This is great, thank you! It could do with an update but I got it working in the end. Now to figure out how to change the user database record based on payment status..
@@GorailsTV Cheers. I've written the controller below which seems to work. Next I'll try to handle the billing section. class CheckoutController < ApplicationController before_action :authenticate_user! def show current_user.set_payment_processor :stripe current_user.payment_processor.customer @checkout_session = current_user.payment_processor.checkout( mode: "subscription", line_items: "price_0000", success_url: checkout_success_url, cancel_url: checkout_cancel_url ) end def success @session = Stripe::Checkout::Session.retrieve(params[:session_id]) @line_items = Stripe::Checkout::Session.list_line_items(params[:session_id]) current_user.set_payment_processor :stripe customer = current_user.payment_processor.customer # Get the subscription ID from the session subscription_id = @session.subscription subscription = Stripe::Subscription.retrieve(subscription_id) # Get the payment method ID from the subscription payment_method_id = subscription.default_payment_method payment_method = Stripe::PaymentMethod.retrieve(payment_method_id) # Attach the payment method to the customer if it's not already attached if payment_method.customer.nil? || payment_method.customer != customer.id Stripe::PaymentMethod.attach(payment_method_id, { customer: customer.id, }) end # Set the attached payment method as the customer's default payment method Stripe::Customer.update(customer.id, { invoice_settings: { default_payment_method: payment_method_id, }, }) # Proceed with the subscription current_user.payment_processor.subscribe(name: "default", plan: "price_0000") if current_user.payment_processor.subscribed? flash[:success] = "Payment registered" redirect_to root_path else flash[:warning] = "Payment was not successful. Please try again." redirect_to root_path end end def cancel flash[:warning] = "Payment was not successful. Please try again." redirect_to root_path ends end
Thanks Chris, i just wonder why if i have my listener off, pay doesnt register the entry. How can I have it all the time running? in production I mean?
In production your app is accessible to the internet, so you don't need the stripe CLI. Just in development when your app isn't accessible on the internet.
Nice video Chris, but one question. Regarding forms. Is posible to add this in a "new" method and then call "create" after payment succeed? Imagine for example that a customer is uploading a job and then is redirected to this Stripe checkout page. Thanks!
Hi Chris! Great video! One question... when current_user signed up, billing webhooks didn't create any records in Pay :: Charges. Is correct? I'm trying to create the following stream in STRIPE: signup > trial 30d > paid subscription
Sure, you can use any auth system you want. Devise is just the most well maintained. 👍 And you don't need a customer to use stripe checkout, pay just adds helpers for it.
This is a great way to wire up stripe into rails. You saved me hours of trying to figure it out myself.
A stripe checkout page up and running in under half an hour. Boom!
Fantastic stuff as always, Chris.
Thanks for making this super badass video!
That's amazing to hear! 🔥
Dude what an awesome guide! It would be nice to see an updated guide for the new version of Pay, but overall just combining this guide with the latest configuration docs worked wonderfully!
It's on my agenda 👍
This is awesome, Chris. Your channel should have at least 100k subscribers!
I agree with U Josias, am lucky to be one of the current subscribers
Hopefully some day soon!
You saved my day!!! thanks for the quality of your work
Thanks Chris. Great stuff as always
I just wanted to let anyone else know who was wondering, you can add the 'line items' with options - so you could do something like
line_items: [
{ price: "price_******",
adjustable_quantity: { enabled: true, minimum: 1, maximum: 10 },
quantity: 1 },
{ price: "price_**********",
adjustable_quantity: { enabled: true, minimum: 1, maximum: 10 },
quantity: 1 }
]
To add quantities or user adjustable quantities for example and multiple products at once. I couldn't find in the rails-pay gem docs how to do this, but you can use any of stripe (or I'm sure other services) options.
Pay just forwards along the options you pass it to Stripe, so you can just pass in the options like normal.
thanks man..integration was like butter. GoRails Go Smooth
😍
Thanks for this. Exactly what I needed.
This is bomb Chris. Thanks for this video
Thank you brother, great explanation and walkthrough. Thank you
hi great tutorial, is there anyway you could make an updated tutorial with connect implementation? Thanks so much
Hey, overall Amazing tutorial as always. but I am amazed without *success_url* & *cancel_url* how do you return your page on the success screen? any clue?!!
We default to the root url
@@GorailsTV ahh i see Thanks man !
This is great, thank you! It could do with an update but I got it working in the end. Now to figure out how to change the user database record based on payment status..
The best way I've found is to handle it on the redirect after Checkout completes. That way you're not relying on webhooks that could come in slowly.
@@GorailsTV Cheers. I've written the controller below which seems to work. Next I'll try to handle the billing section.
class CheckoutController < ApplicationController
before_action :authenticate_user!
def show
current_user.set_payment_processor :stripe
current_user.payment_processor.customer
@checkout_session = current_user.payment_processor.checkout(
mode: "subscription",
line_items: "price_0000",
success_url: checkout_success_url,
cancel_url: checkout_cancel_url
)
end
def success
@session = Stripe::Checkout::Session.retrieve(params[:session_id])
@line_items = Stripe::Checkout::Session.list_line_items(params[:session_id])
current_user.set_payment_processor :stripe
customer = current_user.payment_processor.customer
# Get the subscription ID from the session
subscription_id = @session.subscription
subscription = Stripe::Subscription.retrieve(subscription_id)
# Get the payment method ID from the subscription
payment_method_id = subscription.default_payment_method
payment_method = Stripe::PaymentMethod.retrieve(payment_method_id)
# Attach the payment method to the customer if it's not already attached
if payment_method.customer.nil? || payment_method.customer != customer.id
Stripe::PaymentMethod.attach(payment_method_id, {
customer: customer.id,
})
end
# Set the attached payment method as the customer's default payment method
Stripe::Customer.update(customer.id, {
invoice_settings: {
default_payment_method: payment_method_id,
},
})
# Proceed with the subscription
current_user.payment_processor.subscribe(name: "default", plan: "price_0000")
if current_user.payment_processor.subscribed?
flash[:success] = "Payment registered"
redirect_to root_path
else
flash[:warning] = "Payment was not successful. Please try again."
redirect_to root_path
end
end
def cancel
flash[:warning] = "Payment was not successful. Please try again."
redirect_to root_path
ends
end
@@GorailsTV turns out billing is all handled out of the box! Amazing gem, thank you!
Amazing content, thanks!
Man! You rock! Thank you so much
Thanks Chris, i just wonder why if i have my listener off, pay doesnt register the entry. How can I have it all the time running? in production I mean?
In production your app is accessible to the internet, so you don't need the stripe CLI. Just in development when your app isn't accessible on the internet.
@@GorailsTV Thanks! I'm a bit new to all of this! thanks for the reply and amazing videos you really helped me a lot!
That means a lot! I'm just happy to help!
How do you setup webhooks and signing secret in production?
Thank you for the interesting video
Interesting how much fee do 'Stripe' charge for handle payments
Nice video Chris, but one question. Regarding forms. Is posible to add this in a "new" method and then call "create" after payment succeed? Imagine for example that a customer is uploading a job and then is redirected to this Stripe checkout page. Thanks!
Hi Chris! Great video! One question... when current_user signed up, billing webhooks didn't create any records in Pay :: Charges. Is correct?
I'm trying to create the following stream in STRIPE: signup > trial 30d > paid subscription
Just make sure you're running background jobs if you do have Sidekiq or something like it enabled 👍
Great Tutorial! I am successfully creating subscriptions in Stripe but they aren't being saved in my database.. any ideas why??
Webhooks are required. Make sure you are running the Stripe CLI in development.
@@GorailsTV thank you for getting back to me! What about production? I am having the same issue on my live site.
@@zacwillis6585 Same thing. Make sure your webhooks are connected.
@@GorailsTV Ok. Is there documentation on how to set these up for production?
Does exist a solution without the gem Devise ? And take the name and email informations with the form of stripe checkout ? Thanks
Sure, you can use any auth system you want. Devise is just the most well maintained. 👍
And you don't need a customer to use stripe checkout, pay just adds helpers for it.
how do you customise the checkout button?
Just pass in locals to the partial. You can see it here: github.com/pay-rails/pay/blob/master/app/views/pay/stripe/_checkout_button.html.erb
the pay gem doesnt update the pay_charges table on postgres. Stripe says payment is successful. what am i missing? help would be great