1. Customers
Documentation
  • Back to home
  • StripeKit
  • Installation
  • Getting Started
  • Choosing a Mode
  • Type Reference
  • Setup
    • Configuration
    • Timezones
    • Storage Adapter
    • Money and Currency
    • Error Handling
  • Stripe
    • Elements
  • Modules
    • Overview
    • Customers
      • Overview
      • List
      • Retrieve
      • Find or Create by Email
      • Create
      • Update
      • Sync
      • Delete
    • Payment Methods
      • Overview
      • Create Setup Intent
      • List
      • Attach
      • Detach
      • Set Default
      • Sync
    • Payments
      • Overview
      • Pay With Saved Method
      • Create
      • Retrieve
      • Confirm
      • Cancel
      • Sync
    • Checkout
      • Overview
      • Get
      • Create
      • Submit Fields
      • Apply Coupon
      • Mark Complete
    • Subscriptions
      • Overview
      • Create
      • Retrieve
      • Cancel
      • Resume
      • Toggle Collection Method
      • Update Fields
      • Apply Promotion Code
      • List By Customer
      • Find By Metadata
      • Sync
    • Invoices
      • Overview
      • Retrieve
      • List By Customer
      • List By Subscription
      • Pay With Saved Method
      • Void
      • Finalize
      • Sync
    • Coupons
      • Overview
      • Create
      • Validate
      • Apply To Subscription
      • List
      • Deactivate
    • Webhooks
      • Overview
      • Process
      • Events Reference
    • Sync
      • Overview
  1. Customers

Find or Create by Email

kit.customers.findOrCreateByEmail()#

Looks up a customer by email and returns it if one already exists; otherwise creates a new one. This is the method to use at the start of any flow where you don't yet know if the person has a Stripe customer, for example before starting a checkout or attaching a payment method.

Signature#

Lookup order#

1.
If a storage adapter is configured, calls findUserByEmail(email). If that returns a record with a stripeCustomerId, the matching customer is retrieved from Stripe via retrieve() and returned immediately.
2.
Otherwise, searches Stripe directly for a customer with that email and returns the first match, if any.
3.
If nothing is found, creates a new customer via create(), passing through extra and the resolved userId from your storage adapter, if any.

Parameters#

FieldTypeRequiredDescription
emailstringYesThe email address to look up or create.
extraCreateCustomerInputNoAny additional fields accepted by create() (name, phone, address, metadata, and so on), used only if a new customer needs to be created.

Example request#

Example response#

Same shape as create() / retrieve():

Errors#

Same as create() and retrieve(), depending on which path is taken.

Notes#

This method only ever creates one customer per email. If you call it twice in a row with the same email and no storage adapter, the second call finds the customer created by the first call via Stripe's own search, so you won't get duplicates.
Without a storage adapter, every call does a live search against Stripe's API before deciding whether to create. With a storage adapter, the first check is against your own database, which is faster and avoids relying on Stripe's search consistency.
Previous
Retrieve
Next
Create
Built with