1
3 Comments

Should I keep track of paying customers in my own DB when using Stripe?

Putting together a minimal example of one-time payment for access to a digital product (e.g. "pay $100, you get unlimited access to this version of the app for life"). Thinking about using the Stripe API, specifically Payments.

The flow I was thinking of:

  • User logs in
  • If user hasn't already paid, they see a payment form
  • If user has already paid, they see/can use the product
  • User logs out

Initially thought to just keep track of who's paid in my own database (i.e. Stripe API returns with acknowledgement of a successful payment). But then I thought I might be reinventing something the Stripe API might have: a way to query for existing customers. 🤔

Curious what solutions you might have come up with!

  1. 2

    You might want to keep a simple table with the following:

    UserID
    StripeChargeID
    Timestamp
    Value

    I say this because you can eliminate a call/dependency on Stripe if you plan on letting the user see their Payment History on your site.

    Anything else in detail should probably be a call to Stripe at that point.

    If you don't plan on ever showing this information, a column called StripeChargeID could suffice, if NULL a user hasn't paid ... if it's populated you it's because you made a charge and you can query Stripe with this value to look up details if needed.

  2. 1

    Thanks for the replies/answers!

    Definitely seems obvious now that I should track either the charges or just an "is paying customer" field in my own DB. I think I fell into over-engineering it (i.e. "in the abstract, this information already exists. duplicating it is inelegant").

    Funny how just asking the question helped me think about it, but immediately after asking I saw that having my DB as the source-of-truth puts more control into my hands. I'll deal with the "DB is out of sync with Stripe" case when (read: if) it ever happens.

  3. 1

    You’ll have to store the Stripe customer ID returned from Stripe to retrieve any data on a customer from the Stripe API.

    And if they have a Stripe customer ID, then you know they have paid, so there’s really no reason to query Stripe unless you want more data on the customer.

    It could really be as simple as storing a Boolean value in a database for whether they have paid or not (if you want to keep things simple).

  4. 2

    This comment was deleted 4 years ago