Skip to content

Documentation Enhancement: Explain Why Customer Creation Before Checkout is RecommendedΒ #35

@sergiojoker11

Description

@sergiojoker11

Issue Description

The current documentation recommends creating Stripe customers before creating checkout sessions, but doesn't provide the technical reasoning behind this recommendation. This creates confusion for developers who might be tempted to let Stripe handle customer creation automatically.

Missing Context

The documentation would benefit from explaining the specific technical challenges that arise when letting Stripe automatically create customers during checkout:

Technical Reasons for Pre-Creating Customers

1. Metadata Timing Issues

  • Problem: Metadata is only available in the checkout.session.completed webhook event
  • Issue: By the time checkout.session.completed fires, the customer.created event has already been processed
  • Result: The customer.created event arrives without any custom metadata, making it impossible to associate the customer with your application's domain objects at creation time

2. Limited Customer Identification Options

  • Problem: When Stripe auto-creates customers, the only reliable identifier available is the email address
  • Issue: Many applications have 1:n user-to-email relationships (users can have multiple emails, shared emails, etc.)
  • Result: Email-based customer matching becomes unreliable and can lead to incorrect customer associations

3. Loss of Control Over Customer Creation Logic

  • Problem: Stripe's automatic customer creation logic is opaque and may use factors beyond email (browser fingerprinting, cookies, etc.)
  • Issue: This can lead to unexpected customer creation behavior that doesn't align with your application's user model
  • Result: Inconsistent customer-to-user mapping and potential data integrity issues

Proposed Documentation Enhancement

The documentation should include a section explaining these technical considerations, helping developers understand:

  1. When to create customers (before checkout vs. automatic)
  2. Why pre-creation is recommended for most use cases
  3. How to properly handle the customer creation workflow
  4. What metadata and identification strategies work best

Example Workflow

// Recommended: Create customer first with metadata
const customer = await stripe.customers.create({
  email: user.email,
  metadata: {
    user_id: user.id,
    account_type: user.accountType,
    // Other domain-specific identifiers
  }
});

// Then create checkout session with customer
const session = await stripe.checkout.sessions.create({
  customer: customer.id,
  // ... other session config
});

This approach ensures that:

  • Customer creation events include proper metadata
  • Your webhook handlers can immediately associate customers with domain objects
  • You maintain full control over customer creation logic

Impact

Adding this explanation would help developers make informed architectural decisions and avoid common integration pitfalls that can be difficult to fix after implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions