Provide subscription management on iOS with a customer portal page
Set up a customer portal and open it in a browser from your app.
In some countries, you can link to an external website to accept payments for in-app digital goods, including subscriptions, on iOS. This guide describes how to configure a customer portal for subscription management and redirect your customers to it from your app.

Link out of app to manage subscriptions and payment methods
作成する内容
注
This guide only describes subscription management. If you’re setting up subscription purchases, see Accept payments for digital goods on iOS with a prebuilt payment page.
このガイドでは以下の方法を説明します。
- Set up a customer portal page that customers can use to manage subscriptions
- Use universal links to redirect users back to your app from the customer portal
- Monitor webhooks to update your customer’s subscription status
対象範囲外の内容
This guide demonstrates how to set up a Stripe customer portal and link to it from your app. It doesn’t cover:
- Subscription purchases: To use Stripe Checkout to sell in-app goods and subscriptions, see Accept payments for digital goods on iOS with a prebuilt payment page.
- User authentication: If you don’t have an existing authentication provider, you can use a third-party provider, such as Sign in with Apple or Firebase Authentication.
- Native in-app purchases: To implement in-app purchases using StoreKit, visit Apple’s in-app purchase guide.
ポータルを設定
First, you need to register for a Stripe account.
Before you integrate the customer portal, use the Dashboard to define what your users can do with the portal. Choose your settings for sandboxes and live mode, based on your product and price catalog.
よくある間違い
Stripe Connect でカスタマーポータルを使用している場合は、連結アカウントではなく、プラットフォームのカスタマーポータルを設定してください。
If you want to create multiple portal configurations for different sets of customers (or if you’re a Connect platform and want to manage configurations for your connected accounts), you can do so using the API:
商品カタログを設定する
If you allow customers to upgrade, downgrade, or change the quantities of their subscriptions, you must also set a product catalog. This includes the products and prices that your customers can upgrade or downgrade to, and the subscriptions they can update quantities on. See how to create a product for more details about creating products and prices. If you’re using the customer portal for invoicing only, you don’t need to set a product catalog.
ポータルには、商品カタログの以下の属性が表示されます。
- Product name and description—These attributes are editable in the Dashboard and API.
- Quantity restrictions per product—These attributes are editable in the Dashboard.
- Price amount, currency, and billing interval—These attributes are fixed, and you can only set them when you create them in the Dashboard and API.
納税者番号の収集を有効にする
If you use Stripe Tax to automatically collect taxes for subscriptions or invoices, you can let customers set and update their tax IDs in the customer portal. Stripe Billing adds the tax IDs to the customers’ invoices. To allow customers to set their tax IDs, go to the Customer portal settings and toggle on Tax ID. For more information, see how customer tax IDs work with subscriptions and invoices.
Stripe Tax の設定、継続支払いの税金の徴収、カスタムの決済フローでの税金の徴収、およびラインアイテムと請求書の税率の設定の方法についてご紹介します。
プレビューしてテストする
As you configure your settings, click Preview to preview the portal. This launches a read-only version of the portal that lets you see how your customers might manage their subscriptions and billing details.
設定を保存したらポータルを起動し、サンドボックスで顧客を使用してテストすることができます。ダッシュボードで顧客に移動し、アクションをクリックして、カスタマーポータルを開くを選択します。
You can only preview the portal as a read-only version when your Dashboard is in a sandbox. If you can’t preview and test the portal, check your settings to make sure that your configuration is saved in a sandbox. For previewing and testing to work, you also need to have edit permissions in the Dashboard.
Stripe を設定するサーバー側
サーバー側
Next, install the Stripe CLI. The CLI provides the webhook testing that you need.
その他のインストールオプションについては、Stripe CLI を使ってみるをご覧ください。
クライアント側
Stripe iOS SDK はオープンソースです。詳細なドキュメントが提供されており、iOS 13 以降をサポートするアプリと互換性があります。
注
SDK の最新リリースおよび過去バージョンの詳細については、GitHub の Releases (リリース) ページをご覧ください。リポジトリのリリースをウォッチして、新しいリリースの公開時に通知を受け取ることも可能です。
また、SDK が Stripe への API コールを実行できるように、公開可能キーを設定する必要もあります。すぐに開始するには、導入中にクライアント側でこれをハードコード化できますが、本番環境ではサーバーから公開可能キーを取得します。
// Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys STPAPIClient.shared.publishableKey =
"pk_test_TYooMQauvdEDq54NiTphI7jx"
ポータルセッションを作成するサーバー側
When a customer wants to make changes to their subscription, generate a URL for the portal page using their Stripe customer ID through the portal session API.
ユニバーサルリンクを設定するクライアント側サーバー側
Universal links allow the customer portal to deep link into your app. To configure a universal link:
- ドメインに
apple-app-site-association
ファイルを追加します。 - アプリに Associated Domains エンタイトルメントを追加します。
- Add a fallback page for your portal redirect URLs.
関連ドメインを定義する
Add a file to your domain at .well-known/apple-app-site-association to define the URLs your app handles. Prepend your App ID with your Team ID, which you can find on the Membership page of the Apple Developer Portal.
{ "applinks": { "apps": [], "details": [ { "appIDs": [ "A28BC3DEF9.com.example.MyApp1", "A28BC3DEF9.com.example.MyApp1-Debug" ], "components": [ { "/": "/checkout_redirect*", "comment": "Matches any URL whose path starts with /checkout_redirect" } ] } ] } }
警告
このファイルは、MIME タイプ application/json
で提供する必要があります。curl -I
を使用してコンテンツタイプを確認します。
curl -I https://example.com/.well-known/apple-app-site-association
詳細については、関連ドメインのサポートに関する Apple のページを参照してください。
アプリに Associated Domains エンタイトルメントを追加する
- アプリのターゲットの、Signing & Capabilities (署名とケイパビリティ) ウィンドウを開きます。
- + ケイパビリティ をクリックし、関連ドメイン を選択します。
- Add an entry for
applinks:example.
to the Associated Domains list.com
ユニバーサルリンクの詳細については、Apple の Universal Links for Developers (開発者のためのユニバーサルリンク) (英語) ページをご覧ください。
iOS は、apple-app-site-association
ファイルで定義された URL へのリンクをインターセプトしますが、リダイレクトでアプリを開くことができないケースが発生することがあります。
Make sure to create a fallback page at your return_
. For example, you can define a custom URL scheme for your app and use it to link back in case the universal link fails.
Open the customer portal in Safariクライアント側
Add a button to open the customer portal in your app. This button:
- Calls your server-side endpoint to create a portal session.
- Returns the portal page URL to the client.
- Opens the URL in Safari.
import Foundation import SwiftUI import StoreKit struct SubscriptionManagementView: View { @EnvironmentObject var myBackend: MyServer var body: some View { // Check if payments are blocked by Parental Controls on this device. if !SKPaymentQueue.canMakePayments() { Text("Payments are disabled on this device.") } else { Button { myBackend.createCustomerPortalSession { url in UIApplication.shared.open(url, options: [:], completionHandler: nil) } } label: { Text("Manage subscriptions") }.onOpenURL { url in // Handle the universal link from the customer portal. // Implement any necessary behavior, such as refreshing the customer's subscription status. } } } }
Handle changes to customer subscription statusサーバー側
When customers make changes to their subscription status through the customer portal, Stripe sends you webhooks, such as customer.
, customer.
, and customer.
. For a full list of events and information about them, see Using webhooks with subscriptions. Make sure you handle all events necessary to accurately monitor the statuses of the subscriptions you’ve configured.
For testing purposes, you can monitor events in the Dashboard or using the Stripe CLI. For production, set up a webhook endpoint and subscribe to appropriate event types. If you don’t know your STRIPE_
key, click the webhook link in the Dashboard to view it.