2
4 Comments

For Subscriptions, do you have to listen to invoice events or have to store billing info?

So I'm trying to implement subscriptions via Stripe in my web app and I'm following along the docs and some example repos like this one - https://github.com/vercel/nextjs-subscription-payments

And in that repo, it stores the user's billing info in their DB.

I'm using Customer Portal so I don't think I need to store billing info correct?

Also in the docs it says to listen for invoice events - https://stripe.com/docs/billing/subscriptions/webhooks

But in the example repo, it only listens to

  'product.created',
  'product.updated',
  'price.created',
  'price.updated',
  'checkout.session.completed',
  'customer.subscription.created',
  'customer.subscription.updated',
  'customer.subscription.deleted'

So,

What do your webhooks need to listen to for subscriptions,

and what kind of data do you store in your database about your user? I would rather not store billing data if I could avoid it.

  1. 2
    def webhook
        event = webhook_event
        if event.type == 'checkout.session.completed'
          create_subscription(event.data.object)
        elsif event.type == 'customer.subscription.deleted'
          delete_subscription_and_send_feedback_email(event.data.object)
        elsif event.type == 'invoice.payment_succeeded'
          PayPartners.call(event.data.object)
        else
          render_400
        end
      end
    

    Pulled straight from my rails app controller's webhook endpoint. I use stripe checkout to create the subscriptions, and then the portal for subscription management. Only thing I store in my database is the stripe subscription ID (in a model called subscription which I create or destroy in response to the webhook events)

    1. 1

      Ah cool thanks for the answer! Cool that you're only storing the subscription ID, i'm storing some other info like status and date stuff but don't really have to I suppose.

  2. 2

    It really depends on the structure of your pricing and your app. Do you have multiple tiers where different tiers provide access to different features? Are all users paid, or do you have a freemium tier? A number of additional factors too.

    At the most basic level, you might be able to get away with just listening to

    'customer.subscription.created',
    'customer.subscription.updated',
    'customer.subscription.deleted'

    That will tell you when a subscription starts, has been renewed, and cancelled.

    But, you won't be able to do anything like notifying the user if the renewal fails, say due to an expired card. That's where the invoice hooks come in - if you want to say, "your renewal happens in 3 days", etc.

    In the vercel example, the product and price hooks are used where Stripe is the source of truth on products and pricing, and the products/prices are mirrored in your app. So you can go to Stripe's dashboard and create/change prices/products, and they gets pushed to your app.

    I believe, even if you're using the Billing Portal, when the user registers, you'll still need to call out to Stripe and create customer record, and an initial subscription (could be a "free" subscription, or whatever), because I don't think the Billing Portal works without an active subscription - it is for changing and cancelling subscriptions, not for the initial creation. I could be wrong, it's been a bit since I've worked with that.

    So, my suggestion is to wireframe/flowchart out the onboarding process, the renewal process, the upgrade/downgrade process, the cancellation process, and how/what your app needs to know about subscriptions. Once you've got that, you'll know what needs to be passed back and forth between Stripe and your app.

    1. 1

      Ah ok I think I got it now. Thanks so much for the detailed answer, it explained a lot!

Trending on Indie Hackers
I will promote your startup to 50K+ people 64 comments I made Session, a productivity timer that makes $5K/month in net profit, AMA! 21 comments I built an NFT Guide site. Feedback welcome! 15 comments I've teased this project for a while. Initial thoughts on this landing page? 12 comments Only 30 days! We finished a great Etsy products research tool 10 comments #1 on Product Hunt with an open-source project 8 comments