Create a Customer Create a Stripe customer record and attach it to a Firebase user.

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access


*Enrollment provides full access to this course (and updates) for life.

Get or Create a Stripe Customer

file_type_typescript customers.ts
 * Gets the exsiting Stripe customer or creates a new record
export async function getOrCreateCustomer(userId: string, params?: Stripe.CustomerCreateParams) {

    const userSnapshot = await db.collection('users').doc(userId).get();

    const { stripeCustomerId, email } =;

    // If missing customerID, create it
    if (!stripeCustomerId) {
        // CREATE new customer
        const customer = await stripe.customers.create({
            metadata: {
                firebaseUID: userId
        await userSnapshot.ref.update({ stripeCustomerId: });
        return customer;
    } else {
        return await stripe.customers.retrieve(stripeCustomerId) as Stripe.Customer;



Ask questions via GitHub below OR chat on Slack #questions