Home > Enterprise >  Firebase. Stripe. How to check a particular user on paid subscription?
Firebase. Stripe. How to check a particular user on paid subscription?

Time:11-15

Currently, I can check only current user on paid subscription using:

import { auth } from "../../firebase";

export async function isUserPremium() {
    await auth.currentUser?.getIdToken(true)

    const decodedToken = await auth.currentUser?.getIdTokenResult()

    return decodedToken?.claims?.stripeRole ? true : false;
}

But I want to check particular one, if I have his email and uid, is that possible?

CodePudding user response:

If you have a Stripe customer ID, you can list all subscriptions for that customer like this:

const subscriptions = await stripe.subscriptions.list({
  customer: "cus_xxx",
});

If you only have the customer email, then you first need to retrieve the customer (see code below) and then list all subscriptions for that customer (see code above).

const customers = await stripe.customers.list({
  email: "[email protected]",
});
  • Related