Search code examples
next.jsstripe-paymentssupabase

Need some advice on differentiating between subscriptions using Stripe


In stripe I have 2 products. Monthly subscription ($50 for beginner). Monthly subscription ($70 for advanced).

The user (a parent) can complete a form "Add student to courses". The result is creating tabs with content specific for each kid they sign up to classes. If the user pays a subscription for each kid, in my supabase "subscriptions" table, a column student_id will be populated with the student's id that is the foreign key to a students table. So the parent can have multiple subscriptions for each of his/her kids.

Problem: Let's say both kids are beginners for the classes. If I go to stripe customer portal from the parent's page, I will have 2 subscriptions, both named "Monthly subscription".

How can I differentiate between the 2? Something like "Monthly Subscription for Hannah" and "Monthly Subscription for Paul", or maybe add a description or a tag with their names, idk. I'm stuck...

It looks like I can only create one customer portal, but then all I can see are 2 subscriptions "Monthly Subscription"


Solution

  • So if you tell me that your Subscriptions are created using Stripe Checkout, then you have a perfect solution.
    If not, you still have a solution, but is awkward enough...

    If you create your Checkout Session from the backend, then you can just use this code to create variable Products with a custom name:

     const session = await stripe.checkout.sessions.create({
       success_url: 'https://example.com/success',
       line_items: [
         {
            price_data: {
              unit_amount: amount,
              currency: 'usd',
              recurring: {interval:'month'},
              product_data: {name: 'Monthly Subscription for Hannah'}
            },
            quantity: 1,
         },
       ],
       mode: 'subscription',
       subscription_data:{
         metadata: {
           'user_id':"foo", 
           'student_id':"bar:
         }
       }
     });
    

    Result: enter image description here

    Unless I misunderstood your issue, this would be exactly what you want:

    • The integration is simple, UI is similar to the billing portal.
    • The Products are showing precisely how you want them to be.
    • Those ad-hoc Prices and Products only apply to this Subscription, they can't be used for another Customer/Subscription, and won't be cluttering your Stripe account.

    If you're not using Stripe Checkout, then it's not as good, because you can't create those ad-hoc Products. You can create ad-hoc Prices, but that's no good for you, because what's displayed on the billing portal is the Product.name, nothing to do with the Price.
    Ultimately, if you don't use Checkout, then you'll need to create each Product individually (e.g. with name='Subscription for Hannah) before making your Subscription for it.