We've moved discussions to Discord

How to integrate with Stripe Checkout?

Ben Scheirman
I'm using Jumpstart to sell courses as a one time purchase. For this I'm using Stripe Checkout.

Jumpstart uses the Pay gem and assumes subscriptions and plans, which I don't have.

So when I complete a purchase, I see the web hooks delivered to my app, but Pay just ignores them  (presumably because they don't match up with a Billable model).

What would you recommend as a workaround for dealing with this?

(A) - Remove the Pay webhoook interaction and use my own instead
(B) - Or hook into Pay to enable features after a successful purchase from an Account?

Ideally I'd not stray too far from the upstream branch so that future merges aren't a nightmare. Thoughts welcome! 🙏🏼
Ben Scheirman
I was able to configure the appropriate hooks to set it up for my needs. There's still more that I'll need to change, but the initial hurdle is gone.

Basic steps (for anyone interested):

- New model CheckoutSession that has a token to allow me to associate the desired product w/ the callback. I create this, then create the Stripe Checkout Session & redirect
- Extend the ChargeSucceededExtension module like this:

module ChargeSucceededExtension
    def call(event)
      # We need to associate the Account with the stripe customer before Pay handles the charge,
      # otherwise it gets ignored.
      charge = event.data.object      
      account = Account
        .where(processor: nil, processor_id: nil)
        .with_owner_email(charge.billing_details.email)      

      if account
        account.update(processor: 'stripe', processor_id: charge.customer)
      end
      
      super
    end

    def notify_user(user, charge)
      Pay::UserMailer.receipt(user, charge).deliver_later
    end
  end

Finally need to handle a new event from Stripe (checkout.session.completed), which we can do with Stripe Event easily:

    StripeEvent.configure do |events|
      events.subscribe "checkout.session.completed", CheckoutSessionCompleted.new
    end

In this handler I look up the CheckoutSession by matching the token I generated with the client_reference_id in the stripe object.
Darren Smyth
Hi  Ben Scheirman

Just saw this. I've been doing the same thing. In the end I've decided not to use the Pay gem. The developer instructions on Stripe were pretty good and I have got minimal code needed to use the Checkout.

The hardest thing was getting all the events listened to and actioned but again the instructions for stripe-event were pretty good and there were some great google searches which were invaluable.

I now have a working Checkout with webhooks which will allow me to accept payment.
Ben Scheirman
I'm definitely familiar (having run a subscription business on Stripe for the past 8 years) -- but it was written so long ago that the idea of a drop-in solution seemed really appealing :)
Notifications
You’re not receiving notifications from this thread.