Stripe Checkout in Rails with the Pay gem

Поделиться
HTML-код
  • Опубликовано: 17 янв 2025

Комментарии • 45

  • @MatthewTrussell
    @MatthewTrussell 3 года назад +8

    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!

    • @GorailsTV
      @GorailsTV  3 года назад +3

      That's amazing to hear! 🔥

  • @shawndeprey
    @shawndeprey 3 года назад +5

    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!

    • @GorailsTV
      @GorailsTV  3 года назад +5

      It's on my agenda 👍

  • @pointerish
    @pointerish 3 года назад +4

    This is awesome, Chris. Your channel should have at least 100k subscribers!

    • @galiwangoanan5082
      @galiwangoanan5082 3 года назад +3

      I agree with U Josias, am lucky to be one of the current subscribers

    • @GorailsTV
      @GorailsTV  3 года назад +2

      Hopefully some day soon!

  • @MrTahitiSeb
    @MrTahitiSeb 3 года назад +3

    You saved my day!!! thanks for the quality of your work

  • @AxelHawker
    @AxelHawker 3 года назад +3

    Thanks Chris. Great stuff as always

  • @TheGdesplin
    @TheGdesplin Год назад +1

    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.

    • @GorailsTV
      @GorailsTV  Год назад +1

      Pay just forwards along the options you pass it to Stripe, so you can just pass in the options like normal.

  • @avinashmishra7735
    @avinashmishra7735 3 года назад +1

    thanks man..integration was like butter. GoRails Go Smooth

  • @UsefulProgrammer
    @UsefulProgrammer 3 года назад +1

    Thanks for this. Exactly what I needed.

  • @eydaimon
    @eydaimon 3 года назад +2

    This is bomb Chris. Thanks for this video

  • @FranciscoHernandez-ij3kd
    @FranciscoHernandez-ij3kd 3 года назад +1

    Thank you brother, great explanation and walkthrough. Thank you

  • @neverforget1575
    @neverforget1575 2 года назад +1

    hi great tutorial, is there anyway you could make an updated tutorial with connect implementation? Thanks so much

  • @RonakBhattRz
    @RonakBhattRz 3 года назад +1

    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?!!

    • @GorailsTV
      @GorailsTV  3 года назад +1

      We default to the root url

    • @RonakBhattRz
      @RonakBhattRz 3 года назад

      @@GorailsTV ahh i see Thanks man !

  • @Optimvs_Princeps
    @Optimvs_Princeps Год назад

    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
      @GorailsTV  Год назад

      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.

    • @Optimvs_Princeps
      @Optimvs_Princeps Год назад

      @@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

    • @Optimvs_Princeps
      @Optimvs_Princeps Год назад

      @@GorailsTV turns out billing is all handled out of the box! Amazing gem, thank you!

  • @MailsonMonteiro77
    @MailsonMonteiro77 3 года назад +3

    Amazing content, thanks!

  • @sidalidev
    @sidalidev 3 года назад +1

    Man! You rock! Thank you so much

  • @sebastianrossi7833
    @sebastianrossi7833 3 года назад +2

    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?

    • @GorailsTV
      @GorailsTV  3 года назад +3

      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.

    • @sebastianrossi7833
      @sebastianrossi7833 3 года назад +2

      @@GorailsTV Thanks! I'm a bit new to all of this! thanks for the reply and amazing videos you really helped me a lot!

    • @GorailsTV
      @GorailsTV  3 года назад +1

      That means a lot! I'm just happy to help!

  • @wuliwong
    @wuliwong Год назад

    How do you setup webhooks and signing secret in production?

  • @ppavelcars
    @ppavelcars 3 года назад

    Thank you for the interesting video
    Interesting how much fee do 'Stripe' charge for handle payments

  • @polgasullnavarro1721
    @polgasullnavarro1721 2 года назад

    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!

  • @jcmdev
    @jcmdev 3 года назад

    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

    • @GorailsTV
      @GorailsTV  3 года назад

      Just make sure you're running background jobs if you do have Sidekiq or something like it enabled 👍

  • @zacwillis6585
    @zacwillis6585 3 года назад

    Great Tutorial! I am successfully creating subscriptions in Stripe but they aren't being saved in my database.. any ideas why??

    • @GorailsTV
      @GorailsTV  3 года назад

      Webhooks are required. Make sure you are running the Stripe CLI in development.

    • @zacwillis6585
      @zacwillis6585 3 года назад

      @@GorailsTV thank you for getting back to me! What about production? I am having the same issue on my live site.

    • @GorailsTV
      @GorailsTV  3 года назад

      @@zacwillis6585 Same thing. Make sure your webhooks are connected.

    • @zacwillis6585
      @zacwillis6585 3 года назад

      @@GorailsTV Ok. Is there documentation on how to set these up for production?

  • @blackswansurfing4405
    @blackswansurfing4405 3 года назад

    Does exist a solution without the gem Devise ? And take the name and email informations with the form of stripe checkout ? Thanks

    • @GorailsTV
      @GorailsTV  3 года назад +1

      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.

  • @Christopher8827
    @Christopher8827 3 года назад

    how do you customise the checkout button?

    • @GorailsTV
      @GorailsTV  3 года назад +1

      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

  • @hoochill
    @hoochill 2 года назад

    the pay gem doesnt update the pay_charges table on postgres. Stripe says payment is successful. what am i missing? help would be great