Sync Stripe subscription status to your Firebase users

By General Input

The moment a customer's Stripe subscription changes, we update their Firebase user record so their paid access always matches their real billing status.

Integrations

  • Stripe
  • Firebase

Type

Deterministic Code

Categories

  • Finance
  • Engineering

This is a deterministic field-mapping sync that keeps a Firebase (Firestore) user record in step with a customer's real Stripe billing state. Use a webhook trigger: run this workflow whenever Stripe reports that a subscription was updated or canceled (the customer.subscription.updated and customer.subscription.deleted events). From the incoming event, read the subscription id and the Stripe customer id.

Call Stripe "Retrieve Subscription" with that subscription id to fetch the authoritative current state: the subscription status, the plan (from the price or product on the subscription's first line item), and the current period end (a Unix timestamp). Always re-retrieve the subscription rather than trusting the numbers in the event payload, so the record reflects the very latest state.

Locate the matching user document with Firebase "Run Firestore Query" against the users collection, filtering where the stored Stripe customer id field equals the customer id from the event. Take the first matching document and note its full document path.

Update that document with Firebase "Update Firestore Document", patching only the billing fields: subscriptionStatus (the Stripe status such as active, past_due, or canceled), plan (the price or product identifier), and currentPeriodEnd (convert the Unix timestamp from Stripe into an RFC3339 timestamp for Firestore). Use an update mask so the rest of the user document is left untouched.

Let me configure the collection that holds users, the field on that document that stores the Stripe customer id used for matching, and the exact field names to write (for example subscriptionStatus, plan, and currentPeriodEnd). If no matching user document is found for the customer, log that and skip rather than creating a new record.

Related prompts

Explore more prompts
Let support send one-off Loops emails without an engineerCustomer lifecycle inspector for Loops, Stripe and PostHogMonth-end Stripe finance pack, stored and shared in SlackRank your Intercom queue by what each customer pays youCatch the trials quietly dying before the card gets chargedWork every open Stripe dispute from one chargeback war roomLook up any customer's support, billing and CRM in one pageInvestor update studio that builds your board deck monthlySell and invoice Ghost newsletter sponsor slots in one boardSupport console that pairs Gladly chats with orders and refunds