FlutterフローでStripeの支払いを受け付ける
Stripe のサブスクリプションを、フロー&ペイウォールビルダーで作成したフローから販売できます。フローには Stripe の価格が表示され、ボタンをタップすると Stripe の PaymentSheet がフロー上に開きます。支払い完了後、Stripe が Adapty に通知します。Adapty はユーザーにアクセスレベルを付与し、収益をフロー、プレースメント、A/B テストのバリアントに紐付けます。対面イベントのメンバーシップ、クラスパス、定期配送など、アプリの外でユーザーが利用するサービスのサブスクリプションを販売する場合に活用してください。実世界のサービスのプランを App Store プロダクトとして販売している場合は、同じフローに Stripe を追加して別の支払い手段として提供することもできます。
App Storeはデジタルコンテンツと機能に対してアプリ内課金を必須としており(ガイドライン 3.1.1)、Google Playも同様にその課金システムを必須としています(お支払いポリシー)。Stripeによるアプリ内決済は、物理的な商品や、ユーザーがアプリ外で消費するサービス向けです(ガイドライン 3.1.3(e))。Google Playでは、ジムの会員権や生イベントのチケットなど、こうした購入にその課金システムを使用することは認められていません。
仕組み
- アプリはバックエンドから Stripe の価格情報を取得し、それをカスタムタグとしてフローに渡してフローを表示します。
- ユーザーがフロー内のボタンをタップすると、そのボタンがカスタムアクションをトリガーし、アプリがアクション ID を受け取ります。
- アプリはバックエンドに Stripe サブスクリプションの作成を依頼します。バックエンドはユーザーの ID とフローのバリエーション ID をサブスクリプションのメタデータに追加します。
- アプリはフローの上に PaymentSheet を表示し、ユーザーがサブスクリプションの最初の請求書を支払います。
- Stripe が Adapty に Webhook を送信します。Adapty はユーザーの ID を持つプロファイルにアクセスレベルを付与し、購入をフローのバリアントに紐付けます。
- アプリはフローを閉じ、プロファイルにアクセスレベルが付与されるまで待機します。
始める前に
以下を確認してください:
-
StripeをAdaptyアプリに連携する: テストモードと本番モードそれぞれで、StripeをAdaptyに接続するの手順に従ってください。Profile creation behaviorは**Use customer_user_id from metadata (default)**のままにしておいてください。
-
プランごとにStripeのプロダクトと価格を作成する: 月次・年次などの定期課金価格でStripeにプロダクトを作成してください。
-
Stripeの価格ごとにAdaptyプロダクトを作成する: StripeのプロダクトIDと価格IDをAdatyプロダクトに追加し、そのプランで解除されるアクセスレベルを割り当ててください。アクセスレベルはアプリ内のデジタル機能ではなく、アクティブなメンバーシップなどのサービス利用権を表します。Adaptyプロダクトがない場合、Adaptyは購入を記録しません。
-
Adapty Flutter SDK 4.0.0以降: Stripeに接続したAdatyアプリのキーでSDKを有効化してください。AdaptyはそのアプリのStripe Webhookのみを受信します。ユーザーを識別する際はカスタマーユーザーIDを使用し、このフローはログイン済みかつ識別済みのユーザーにのみ表示してください。AdaptyはこのIDを使って、アクセスレベルを付与するプロファイルを特定します。
SDK 4.4以降、フローはiOS 16以降が必要です。iOS 15では、
AdaptyUI().createFlowView()とAdaptyUIFlowPlatformViewがAdaptyErrorCode.platformNotSupportedエラーを返します。アプリがこのエラーを受け取った場合は、フローの代わりに独自のコンテンツ(カスタムペイウォールなど)を表示してください。 -
アプリに
flutter_stripeパッケージを導入し、そのREADMEに従ってAndroidとiOSの設定を行います。Androidでは、flutter_stripeはFlutterFragmentActivityを継承したMainActivityと、Theme.AppCompatを継承したテーマが必要です。 -
Stripeのシークレットキー、またはCustomerとSubscriptionの書き込み権限を持つ制限付きキーを使ってStripe APIを呼び出せるバックエンドが必要です。Adapty用に生成した制限付きキーは再利用しないでください。そのキーはAdaptyのものであり、バックエンドに必要な書き込み権限がありません。キーはサーバー上に保管してください。
フローにStripeの価格を表示する
フローはカスタムタグを通じてStripeの価格を表示します。カスタムタグとは、フローの読み込み時にアプリがフローに渡すテキスト値です。Adaptyはカスタムタグの値をフォーマットしないため、“$29.00”のようにユーザーに表示される形式で各価格を渡してください。
- フロー & ペイウォールビルダーで、各価格に対してString 変数を作成します(例:
stripe_monthly_priceとstripe_annual_price)。Value comes from outside the app を選択し、各変数の Initial value に現在の価格を設定してください。アプリが価格を読み込めない場合、ユーザーにはこの初期値が表示されるため、初期値は Stripe の価格と同じ値にしておいてください。 - 各タグをテキスト要素に挿入します(例:プランボタンのラベルなど)。
- アプリ内でフローを読み込む前に、バックエンドから価格を取得します。
AdaptyUIFlowPlatformViewのcustomTagsパラメーターに価格を渡します。
以下の関数はフローを読み込み、Stripe の価格を使ってカスタムタグを構築します。また、バックエンドが Stripe サブスクリプションにフローの variationId を書き込むため、フロー自体も返します。フローの表示方法は フローから PaymentSheet を開く を参照してください。
typedef StripeFlow = ({AdaptyFlow flow, Map<String, String> customTags});
Future<StripeFlow> loadStripeFlow() async {
// If the prices fail to load, the flow shows the tags' initial values
final prices = await Backend.fetchPrices().catchError((Object _) => <String, String>{});
final flow = await Adapty().getFlow(placementId: 'YOUR_PLACEMENT_ID');
return (
flow: flow,
customTags: {
'stripe_monthly_price': ?prices['monthly'],
'stripe_annual_price': ?prices['annual'],
},
);
}Backend は、バックエンドでサブスクリプションを作成するで作成したバックエンドのエンドポイント用クライアントです。
PaymentSheetを開くボタンの追加
Stripeプランを販売する各ボタンは、カスタムアクションをトリガーします。アプリはそのアクションIDを受け取り、対応するプランのPaymentSheetを開きます。
- フロー & ペイウォールビルダーで、各Stripeプラン用のボタンを追加します。
- 各ボタンに Custom Action アクションを割り当て、
buy_stripe_monthlyやbuy_stripe_annualなどのアクションIDを入力します。 - フローを公開し、プレースメントに追加します。
あなたのアプリは各アクション ID をプランにマッピングします。フローはアクションと共にアプリにデータを送信しないため、アクション ID でプランを識別する必要があります。
Stripe を App Store プロダクトの追加決済手段として追加する
この設定は、アプリ外で消費される物理的な商品やサービスのプランにのみ使用してください(ガイドライン 3.1.3(e))。対面イベントのメンバーシップなどが該当します。デジタルコンテンツや機能については、ウェブペイウォールを通じた別の決済方法を提供してください。
これはiOSのみの設定です。Google PlayはGoogle Playの課金システムを物理的な商品やサービスに使用することを認めていないため(支払いポリシー)、Androidではこれらのプランの販売はStripeのみで行ってください。
フローにはApp Storeのプロダクトが通常通り表示され、「他の方法で支払う」などのリンクをタップするとPaymentSheetが開きます。App Store購入ボタンはそのままの状態で引き続き機能します。
- リンクに Custom Action アクションを割り当て、
pay_with_stripeなどのアクション ID を設定します。 - フロー内の各 App Store プロダクトに対して、同じプランの Stripe price を作成します。
- アプリ内で、各 App Store プロダクト ID を対応する Stripe プランにマッピングします。
- ユーザーが選択したプロダクトを保存します。フローは各選択を
AdaptyUIFlowPlatformViewのonDidSelectProductコールバックに報告します。フロー & ペイウォールビルダーで作成したフローは、デフォルトでは選択されたプロダクトを報告しないため、ビルダーで選択済みに設定したプロダクトから開始してください。A/B テストのバリアントによって選択されるプロダクトが異なる場合は、各バリアントのデフォルトプロダクトを保存してください。 onDidPerformActionがpay_with_stripeを受け取ったら、保存したプロダクトの Stripe プランを引数として、フローから PaymentSheet を開く の_payAndCloseを呼び出します。
フローにはストアフロントごとに異なる App Store の価格が表示されますが、PaymentSheet では Stripe の価格が請求されます。ユーザーがタップする前に Stripe の価格を表示するには、カスタムタグとして渡し、各プランのカードに表示します(例:「またはカードで月額 $29.00」)。カスタムタグの値はフローが開いている間は変わらないため、1 つのリンクで選択中のプランの価格を表示することはできません。
バックエンドでサブスクリプションを作成する
PaymentSheetは、バックエンドが作成したStripeオブジェクトに対して支払いを行います。このガイドでは、バックエンドがStripeのサブスクリプションを作成し、PaymentSheetがそのサブスクリプションの初回請求書の支払いを処理します。バックエンドはサブスクリプションのメタデータに2つのキーを設定します:
customer_user_id: AdaptyにおけるユーザーのカスタマーユーザーID。Adaptyはこのプロファイルにアクセスレベルを付与します。variation_id: アプリがバックエンドに送信するフローのバリエーションID。Adaptyはこのフローのバリアント、そのプレースメント、およびA/B テストに対して収益を紐づけます。
サブスクリプションや請求書を紐付けずに単独で作成したPaymentIntentの支払いはAdaptyに記録されません。ユーザーが支払っても、アクセスレベルは付与されません。
カスタムタグのフォーマット済み価格を返すエンドポイントと、PaymentSheetに必要な値を返しながらサブスクリプションを作成するエンドポイントの2つを作成します。2つ目のエンドポイントはサブスクリプションを作成する前に、同じプランに二重課金されないようユーザーにアクティブなサブスクリプションがないことを確認します。
この例では、Node.jsのESモジュール(package.jsonに"type": "module"を設定)、Express、およびバージョン18以降のstripeライブラリを使用しています。dbはご自身のデータベースに置き換えてください。
const app = express();
app.use(express.json());
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const prices = {
monthly: 'price_...', // your Stripe price IDs
annual: 'price_...',
};
// Prices for the custom tags, such as { "monthly": "$29.00", "annual": "$249.00" }.
// You can cache the response.
app.get('/prices', async (req, res) => {
try {
const result = {};
for (const [plan, priceId] of Object.entries(prices)) {
const price = await stripe.prices.retrieve(priceId);
// Assumes a currency with two decimal places. Format for your users' locale.
result[plan] = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: price.currency.toUpperCase(),
}).format(price.unit_amount / 100);
}
res.json(result);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Could not load prices' });
}
});
app.post('/subscriptions', async (req, res) => {
// req.user comes from your authentication middleware. Its ID is the same
// customer user ID that your app passes to Adapty.identify().
const customerUserId = req.user.id;
// variationId affects only attribution, so the backend doesn't need to trust it
const { plan, variationId } = req.body;
if (!prices[plan]) {
return res.status(400).json({ error: 'Unknown plan' });
}
try {
// One Stripe customer per user, stored in your database
let customerId = await db.getStripeCustomerId(customerUserId);
if (!customerId) {
const customer = await stripe.customers.create({ metadata: { customer_user_id: customerUserId } });
customerId = customer.id;
await db.saveStripeCustomerId(customerUserId, customerId);
}
// Don't sell a second subscription to a user who already has one
for (const status of ['active', 'trialing', 'past_due']) {
const existing = await stripe.subscriptions.list({ customer: customerId, status, limit: 1 });
if (existing.data.length > 0) {
return res.status(409).json({ error: 'You already have a subscription' });
}
}
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{ price: prices[plan] }],
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
metadata: {
customer_user_id: customerUserId,
variation_id: variationId,
},
expand: ['latest_invoice.confirmation_secret'],
});
res.json({
subscriptionId: subscription.id,
clientSecret: subscription.latest_invoice.confirmation_secret.client_secret,
publishableKey: process.env.STRIPE_PUBLISHABLE_KEY,
});
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Could not create the subscription' });
}
});
app.listen(process.env.PORT ?? 3000);payment_behavior: 'default_incomplete' を使用すると、サブスクリプションは最初の支払いを待機します。ユーザーが PaymentSheet で支払いを完了すると、Stripe がサブスクリプションを有効化します。ユーザーが支払いをせずに PaymentSheet を閉じた場合、Stripe は約23時間後にサブスクリプションを失効させ、Adapty はそれを記録しません。Stripe の完全なセットアップについては、Stripe ドキュメントの Build a subscriptions integration を参照してください。
コードはクライアントシークレットを latest_invoice.confirmation_secret から読み取ります。これには Stripe API バージョン 2025-03-31.basil 以降が必要です。stripe ライブラリはバージョン 18 からこのバージョンを使用します。ライブラリを使わずに Stripe API を呼び出す場合は、Stripe-Version ヘッダーを設定してください。それより古い API バージョンを使用する場合は、latest_invoice.payment_intent を展開し、代わりに payment_intent.client_secret を読み取ってください。
アプリ内で2つのエンドポイントを呼び出します。バックエンドの要件に従い、各リクエストにユーザーの認証情報を付与してください。この例では http パッケージを使用します:
class Subscription {
const Subscription({
required this.subscriptionId,
required this.clientSecret,
required this.publishableKey,
});
factory Subscription.fromJson(Map<String, dynamic> json) => Subscription(
subscriptionId: json['subscriptionId'] as String,
clientSecret: json['clientSecret'] as String,
publishableKey: json['publishableKey'] as String,
);
final String subscriptionId;
final String clientSecret;
final String publishableKey;
}
class BackendException implements Exception {
const BackendException(this.message);
final String message;
@override
String toString() => message;
}
abstract final class Backend {
static const baseUrl = 'https://YOUR_BACKEND';
static Future<Map<String, String>> fetchPrices() async {
final json = await _send(http.get(Uri.parse('$baseUrl/prices')));
return (json as Map<String, dynamic>).cast<String, String>();
}
static Future<Subscription> createSubscription({
required String plan,
required String variationId,
}) async {
final json = await _send(http.post(
Uri.parse('$baseUrl/subscriptions'),
headers: {
'Content-Type': 'application/json',
// add your authentication header
},
body: jsonEncode({'plan': plan, 'variationId': variationId}),
));
return Subscription.fromJson(json as Map<String, dynamic>);
}
static Future<Object?> _send(Future<http.Response> request) async {
final response = await request;
if (response.statusCode != 200) {
// Use the backend's message when the response has one
String? message;
try {
message = (jsonDecode(response.body) as Map<String, dynamic>)['error'] as String?;
} catch (_) {}
throw BackendException(message ?? 'The server returned HTTP ${response.statusCode}.');
}
return jsonDecode(response.body);
}
}フローからPaymentSheetを開く
フロー内のボタンがカスタムアクションをトリガーすると、アプリはPaymentSheetを開き、支払いが成功するとフローを閉じます。
- カスタムアクション ID をプランに対応付けます。バックエンドの応答待ちや PaymentSheet の表示中は、タップ・フローの閉じるボタン・リンクを無視してください。これにより、1 回のタップで 1 つのサブスクリプションが作成されます。
- バックエンドにサブスクリプションをリクエストし、プランとフローの
variationIdを渡します。 - フローの上に PaymentSheet を表示し、結果を処理します。
- Completed:フローを閉じます。閉じた後、アクセスレベルの付与を待ちます。
- Canceled:何もしません。ユーザーはフローに留まり、別のプランを選択できます。
- Failed:埋め込みフローの上に Flutter ダイアログでエラーを表示します。
view.showDialogは埋め込みフローでは機能しません。ユーザーはフローに留まり、再試行できます。
- フローの閉じるアクション・URL を開くアクション、および Android のシステム Back ボタンを処理します。
onDidPerformActionが設定されている場合、SDK はこのフローの URL を自動で開きません。フローを閉じるにはウィジェットを削除してください。埋め込みフローではview.dismiss()は機能しません。
この文はMDXドキュメントのフラグメントではなく、翻訳対象のコンテンツが含まれていません。翻訳するMDXフラグメントを提供してください。
class StripeCheckout {
// Custom action IDs from the flow, mapped to your backend's plan keys
static const plans = {
'buy_stripe_monthly': 'monthly',
'buy_stripe_annual': 'annual',
};
bool _isPaying = false;
bool get isPaying => _isPaying;
/// Opens PaymentSheet for a plan over the flow. Returns `true` when the user paid.
Future<bool> pay(
String plan,
AdaptyUIFlowView view, {
required Future<void> Function(String message) showError,
}) async {
if (_isPaying) return false;
_isPaying = true;
try {
final subscription = await Backend.createSubscription(
plan: plan,
variationId: view.variationId,
);
Stripe.publishableKey = subscription.publishableKey;
// The URL scheme that you register in your iOS app
Stripe.urlScheme = 'your-app';
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: subscription.clientSecret,
merchantDisplayName: 'YOUR_BUSINESS_NAME',
// For payment methods that redirect to another app, such as bank apps
returnURL: 'your-app://stripe-redirect',
),
);
await Stripe.instance.presentPaymentSheet();
return true;
} on StripeException catch (e) {
if (e.error.code == FailureCode.Canceled) return false; // the user stays on the flow
await showError(e.error.localizedMessage ?? e.error.message ?? 'Unknown error');
return false;
} catch (e) {
await showError(e.toString());
return false;
} finally {
_isPaying = false;
}
}
}iOSでは、PaymentSheetは別のアプリを開く決済方法での支払い後、リターンURLを通じてアプリに戻ります。StripeドキュメントのリターンURLの設定に記載されているように、アプリのios/Runner/Info.plistにURLスキームを登録してください。Stripe.urlSchemeとreturnURLには同じスキームを使用します。iOSがこのURLでアプリを開くと、flutter_stripeがそのURLをStripeに渡します。アプリのInfo.plistでFlutterDeepLinkingEnabledをtrueに設定している場合は、ディープリンクハンドラーでStripeにURLを渡してください:
// In your deep-link handler, for URLs with your scheme
Future<void> handleStripeRedirect(Uri uri) async {
await Stripe.instance.handleURLCallback(uri.toString());
}Android では、PaymentSheet はリターン URL なしでアプリに戻ります。
フローを表示し、そのアクションを StripeCheckout に渡します。フローは AdaptyUIFlowPlatformView ウィジェットを使って独自のルートにレンダリングし、onDidPerformAction でアクションを処理します。フローはFlutterルート内のウィジェットであるため、PaymentSheetの結果はフローが開いている間にアプリに届きます。フローを閉じるには、ルートをポップします。
class StripeFlowPage extends StatefulWidget {
const StripeFlowPage({super.key, required this.stripeFlow});
final StripeFlow stripeFlow;
@override
State<StripeFlowPage> createState() => _StripeFlowPageState();
}
class _StripeFlowPageState extends State<StripeFlowPage> {
final _checkout = StripeCheckout();
bool _hasAppeared = false;
bool _isClosing = false; // the route closes after the payment
bool get _isBusy => _checkout.isPaying || _isClosing;
/// Pops the route. The screen receives `true` when the user paid.
void _close({bool paid = false}) {
if (_isClosing || !mounted) return;
_isClosing = true;
Navigator.of(context).pop(paid);
}
void _onAction(AdaptyUIFlowView view, AdaptyUIAction action) {
switch (action) {
case CloseAction():
case AndroidSystemBackAction():
if (_isBusy) return;
_close();
case OpenUrlAction(:final url, :final openIn):
if (_isBusy) return;
AdaptyUI().openUrl(url, openIn: openIn).ignore();
case CustomAction(:final action):
final plan = StripeCheckout.plans[action];
if (plan == null || _isBusy) return;
_payAndClose(plan, view);
}
}
Future<void> _payAndClose(String plan, AdaptyUIFlowView view) async {
if (await _checkout.pay(plan, view, showError: _showError)) _close(paid: true);
}
/// Shows the error over the flow
Future<void> _showError(String message) async {
if (!mounted) return;
await showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: const Text("The payment didn't go through"),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('OK'),
),
],
),
);
}
@override
Widget build(BuildContext context) {
// Android's Back button can pop the route instead of reaching the flow
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) {
if (!didPop && !_isBusy) _close();
},
child: Scaffold(
// Keeps the flow's close button out of the Android status bar.
// On iOS, the flow applies the safe area itself.
body: SafeArea(
top: Platform.isAndroid,
bottom: Platform.isAndroid,
child: AdaptyUIFlowPlatformView(
flow: widget.stripeFlow.flow,
customTags: widget.stripeFlow.customTags,
onDidAppear: (_) => _hasAppeared = true,
onDidPerformAction: _onAction,
onDidReceiveError: (view, error) {
debugPrint('Flow error: $error');
// The widget stays empty when it can't show the flow.
// The flow keeps working after other errors, so keep PaymentSheet open.
if (!_hasAppeared && !_isBusy) _close();
},
),
),
),
);
}
}アプリが AdaptyUI().setFlowsEventsObserver でオブザーバーを設定している場合、そのオブザーバーはこのフローのイベントも受け取ります。Stripe のアクションは onDidPerformAction のみで処理してください。
画面内でフローを読み込み、そのルートをプッシュします:
class MembershipScreen extends StatefulWidget {
const MembershipScreen({super.key});
@override
State<MembershipScreen> createState() => _MembershipScreenState();
}
class _MembershipScreenState extends State<MembershipScreen> {
bool _isLoadingFlow = false;
Future<void> _showStripeFlow() async {
if (_isLoadingFlow) return;
_isLoadingFlow = true;
try {
final stripeFlow = await loadStripeFlow();
if (!mounted) return;
final paid = await Navigator.of(context).push<bool>(
MaterialPageRoute(builder: (_) => StripeFlowPage(stripeFlow: stripeFlow)),
);
if (paid == true) await _unlockAfterPayment();
} on AdaptyError catch (e) {
// handle the error
} catch (e) {
// handle the error
} finally {
_isLoadingFlow = false;
}
}
Future<void> _unlockAfterPayment() async {
final hasAccess = await waitForAccess();
if (!mounted) return;
if (hasAccess) {
// unlock the service
} else {
// tell the user that the payment is processing, and how to reach your support
}
}
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: _showStripeFlow,
child: const Text('Become a member'),
);
}
}フローが App Store または Google Play のプロダクトも販売している場合は、フローイベントを処理する で説明されているように、AdaptyUIFlowPlatformView の購入コールバックでそれらの購入を処理してください。
支払い後にアクセスを解放する
支払い完了後、Adapty は Stripe の Webhook を受信し、数秒以内にアクセスレベルを付与します。SDK はプロファイルを1分に1回更新するため、アクセスレベルが有効になるまでプロファイルをリクエストし続けてください。
Future<bool> waitForAccess() async {
for (var attempt = 0; attempt < 20; attempt++) {
try {
final profile = await Adapty().getProfile();
if (profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive == true) return true;
} catch (_) {
// try again
}
await Future<void>.delayed(const Duration(seconds: 3));
}
return false;
}通常、アクセスレベルは数秒以内に有効になります。60秒経過しても有効にならない場合は、Stripeのウェブフック設定でAdaptyウェブフックエンドポイントへの配信状況を確認してください。
支払い後にウェルカム画面などの確認画面を表示するには、アクセスレベルが有効になったタイミングでアプリ側から表示してください。また、確認画面を2つ目のフローとして作成し、専用のプレースメントに追加して、最初のフローが閉じた後に表示することもできます。この設定方法については、購入結果への対応をご覧ください。
ユーザーがサブスクリプションを管理できるようにする
Stripeのサブスクリプションは、ユーザーのApp StoreやGoogle Playのサブスクリプション一覧には表示されません。ユーザーがキャンセルや支払い方法の変更を行えるようにするには、たとえばアカウント画面など、アプリ内にStripeカスタマーポータルを開くボタンを追加してください。バックエンドがユーザーのStripeカスタマー向けにポータルセッションを作成し、そのURLを返します。
ユーザーがキャンセルすると、StripeがAdaptyに通知し、Adaptyはアクセスレベルを更新します。即時キャンセルと期間終了時のキャンセルをAdaptyがどのように扱うかについては、キャンセルをご覧ください。
インテグレーションのテスト
Stripe のテストモードを使用して、Adapty アプリに接続します:
- Stripeに接続したAdaptyアプリのAdapty SDKキーを使って、アプリを起動します。
- フローを開きます。ボタンにはカスタムタグの初期値ではなく、アプリが渡した価格が表示されるはずです。
- Stripeプランのボタンをタップします。PaymentSheetで、Stripeのテストカード
4242 4242 4242 4242、未来の有効期限、任意のCVCを使って支払いを行います。 - フローが閉じ、数秒以内にプロファイルのアクセスレベルがアクティブになることを確認します。
- Adapty ダッシュボードでEvent Feedを開きます。購入イベントには
store:stripe、フローのflow_idとflow_name、アプリが送信したvariationIdと同じ値のflow_variation_id、そしてプレースメントIDがdeveloper_idに含まれているはずです。Stripe購入の場合、variation_idはflow_variation_idと同じ値になります。
テストモードの購入には Sandbox 環境が設定されます。イベントフィードやプロファイルには表示されますが、アナリティクスやフローの指標には表示されません。これらは本番環境の購入のみを集計します。
購入が Adapty に表示されない場合は、アプリが Stripe に接続された Adapty アプリの SDK キーを使用しているか、Stripe の価格に対応する Adapty プロダクトが存在するか、サブスクリプションのメタデータに customer_user_id が含まれているかを確認してください。詳細は Stripe インテグレーションガイドのトラブルシューティングを参照してください。
制限事項
- フローはStripeの結果を受け取りません: Stripeの支払いが成功・キャンセル・失敗した後、フローは別の画面に遷移できません。アプリがフローを閉じて、次の画面を表示します。
- カスタムタグの価格はテキストです: フローはアプリが渡したカスタムタグの値をそのまま表示し、週あたりの価格や割引などの他の値を計算しません。それぞれの値を個別のタグとして渡してください。
- カスタムタグの値はフローが開いている間は固定です: 新しい価格を表示するには、フローを再度読み込んでください。