Create a subscription with the customer, price, optional trial, discount, and return URLs. Use an idempotency key so a network retry cannot create a second subscription.
Grant access after the subscription or first invoice is confirmed. Handle renewal, payment failure, cancellation, pause, resume, and trial-ending events.
Create a customer-portal session so customers can update payment details, review invoices, change plans, pause service, or cancel according to your policy.