app/services/customer.ts) wraps the Stripe SDK’s customer API. It initializes a single Stripe client and exposes functions for customer lifecycle management. All functions are async and designed to run server-side inside React Router loaders and actions.
The Stripe client is initialized with a hardcoded test key in the source. Replace
sk_test_... with your actual key via an environment variable before deploying. See Environment configuration.Functions
createCustomer
Creates a new Stripe customer with the provided email and display name.
stripe.customers.create() with email and name, then returns the full Stripe.Customer object that Stripe resolves.
Parameters
The customer’s email address. Stripe uses this for receipts, invoice emails, and customer search.
The customer’s full display name. Shown in the Stripe Dashboard and on invoices.
Promise<Stripe.Customer>. Key fields on the resolved object:
Unique Stripe customer identifier, prefixed with
cus_. Store this in the session as customerId to identify the customer in subsequent API calls.The email address provided at creation time.
The display name provided at creation time.
Unix timestamp (seconds) when the customer was created.
true when the customer was created in live mode, false in test mode. Always false when using a sk_test_ key.app/routes/register.tsx calls createCustomer after validating the form, then stores the returned id in the session:
register action