Skip to content
Create account
or
Sign in
The Stripe Docs logo
/
Ask AI
Create account
Sign in
Get started
Payments
Revenue
Platforms and marketplaces
Money management
Developer resources
APIs & SDKsHelp
Overview
Billing
OverviewAbout the Billing APIs
Subscriptions
    Overview
    How subscriptions work
    Get started
    Quickstart
    Plan an integration
    Build an integration
    Use cases
    About subscriptions
    Enable billing mode
    Configure subscription events
    Entitlements
    Subscription invoices
    Subscription schedules
    Recurring pricing models
    Strong Customer Authentication (SCA)
    Set up subscriptions
    Configure collection methods
    Embed a pricing table
    Set billing cycles
    Manage subscriptions
    Migrate subscriptions to Stripe
    Set product or subscription quantities
    Mixed interval subscriptions
    Backdate subscriptions
    Set trial periods
    Handle subscriptions with deferred payment
    Apply coupons
    Modify subscriptions
    Manage subscription payment methods
    Analytics
    Manage subscriptions on iOS
Invoicing
Usage-based billing
Quotes
Customer management
Billing with other products
Revenue recovery
Automations
Test your integration
Tax
Overview
Use Stripe tax
Manage compliance
Reporting
Overview
Select a report
Configure reports
Reports for multiple accounts
Reports API
Revenue recognition
Data
Overview
Query business data
Sigma
Data Pipeline
Import external data
United States
English (United Kingdom)
HomeRevenueSubscriptions

Manage subscriptions on iOSPrivate preview

Accept recurring payments and manage entitlements with the BillingSDK for iOS.

Accept subscription payments, let customers manage their subscriptions and manage Entitlements directly in your iOS app with the BillingSDK for iOS. The SDK provides prebuilt UI components to display buy buttons, present the customer portal and check entitlements to gate premium features.

Before you begin

To use the BillingSDK for iOS, you’ll need:

  • A back end server to create Customer Sessions
  • A Stripe account with access to the private preview
  • iOS 15.0 or later and macOS 12.0 or later
  • Xcode 15.0 or later

What you’ll build

This guide shows you how to:

  • Set up a server endpoint to create Customer Sessions
  • Install and configure the BillingSDK for iOS
  • Display buy buttons for subscription purchases
  • Check entitlements to gate premium features
  • Present the customer portal for subscription management
  • Handle errors and manage session state

You can find a complete example app in the BillingSDK for iOS repository.

Set up your back end
Server

Create a server endpoint that generates Customer Sessions for authenticated users. These sessions securely authenticate your iOS app with Stripe’s billing APIs.

Create a customer session endpoint

The endpoint needs to:

  1. Verify that the user is authenticated
  2. Create or retrieve the Stripe Customer ID for the user
  3. Create a Customer Session with the required components enabled
  4. Return the session details to your app

Here’s an example implementation:

Response format

The endpoint must return these fields for successful authentication:

FieldTypeDescription
clientSecretstringThe Customer Session secret used to authenticate the SDK
expiresAtnumberExpiry timestamp in seconds since epoch
customerstringThe Stripe Customer ID

When authentication fails, return HTTP 401 to trigger the SDK’s unauthenticated state.

Install and configure the SDK
iOS

The BillingSDK for iOS provides a native iOS experience for subscription management and feature access control.

Add the SDK to your project

During private preview, install the BillingSDK package:

  1. Open your project in Xcode
  2. Select File → Add Package Dependencies
  3. Type https://github.com/stripe-samples/billing-ios-sdk into the Search or Enter Package URL field
  4. Select BillingSDK and click Add Package

Configure the SDK

Initialise the SDK in a shared class to handle the BillingSDK setup and authentication:

Note

The SDK handles thread safety internally – you can safely call its methods from any thread.

Set up the Customer Session provider

Add the authentication method to your billing manager:

Note

The BillingSDK automatically calls your session provider whenever it needs to authenticate with Stripe. When the provider returns nil, the SDK enters an unauthenticated state.

Display subscription buy buttons
iOS

Buy buttons provide a prebuilt UI element to let customers purchase subscriptions. Each button is linked to a specific product and price in your Stripe account.

Create buy buttons in the Dashboard

Follow this guide to create buy buttons in the Dashboard. If you plan to use the entitlement checking functionality, ensure that the products you’ve created have Entitlements attached to them.

Display a buy button

Note

Buy buttons work even when users aren’t authenticated. The SDK creates a new Stripe Customer during purchase if needed.

Check and validate entitlements
iOS

Entitlements let you control access to premium features based on a customer’s active subscriptions.

Check a specific entitlement

Verify if a user has access to a specific feature:

Get all active entitlements

Retrieve all entitlements the customer has access to:

Listen for entitlement changes

Set up a listener to be notified when entitlements change:

Note

When no session is present, getActiveEntitlements() returns an empty array.

Present the customer portal
iOS

The customer portal lets subscribers manage their subscriptions, payment methods and billing information.

Show the customer portal

Present the portal when users need to manage their subscription:

Warning

The customer portal requires an active authenticated session. If the user isn’t logged in, the SDK throws an .unauthenticated error.

External redirection (optional)

You can also open the portal in a browser:

Session management
iOS

Session management

Reset the SDK when users sign out to clear session data and caches:

Test your integration

During development, use your sandbox API keys and sandbox Customer IDs to avoid creating real charges.

Testing scenarios

Test these common scenarios:

ScenarioSteps
New subscription purchasePresent a buy button to a new user
Subscription managementUse the customer portal to change plans
Entitlement verificationCheck a premium feature with hasEntitlement
Error handlingTest with invalid keys or expired sessions
Sign out flowVerify billing.reset() clears cached data

See also

  • Entitlements
  • Configure the customer portal
  • How subscriptions work
Was this page helpful?
YesNo
  • Need help? Contact Support.
  • Check out our changelog.
  • Questions? Contact Sales.
  • LLM? Read llms.txt.
  • Powered by Markdoc