Home > Net >  How can I change the payment status to "paid" after a customer paid with stripe?
How can I change the payment status to "paid" after a customer paid with stripe?

Time:06-09

So I am working on a web app and am a little confused... I am trying to change the payment status of a booking after the customer paid successfully over stripe checkout. Basically, change booking.paid to true after the checkout is successful. I tried some things but I seem to be stuck. Thank you for any help :)

Here is my checkout controller:

class CheckoutController < ApplicationController

  def create
    product = Listing.find(params[:listing_id])
    booking = Booking.find(params[:id])
    duration = (booking.end_date - booking.start_date).to_i   1
    @session = Stripe::Checkout::Session.create({
      payment_method_types: ['card'],
      line_items: [{
        name: product.name,
        amount: product.price * 100,
        currency: "gbp",
        quantity: duration
      }],
      mode: 'payment',
      success_url: bookings_url,
      cancel_url: bookings_url
    })
    respond_to do |format|
      format.js
    end
  end
end

CodePudding user response:

I recommend leveraging Stripe Webhooks to inform your internal system when a Checkout Session succeeds. You’ll want to listen for event, checkout.session.completed.

Here’s a helpful guide that walks through fulfilling orders after a customer pays with Stripe Checkout.

  • Related