ペイウォールイベントの処理
このガイドでは、購入・復元・プロダクト選択・ペイウォールのレンダリングに関するイベント処理を説明します。ボタン操作(ペイウォールを閉じる、リンクを開くなど)の実装も必要です。詳細はボタンアクションの処理ガイドをご覧ください。
ペイウォールビルダーで設定されたペイウォールは、購入や復元のために追加コードは不要です。ただし、アプリが応答できるいくつかのイベントが生成されます。これらのイベントには、ボタン操作(閉じるボタン、URL、プロダクト選択など)や、ペイウォール上で行われた購入関連のアクションへの通知が含まれます。以下でこれらのイベントへの対応方法を説明します。
このガイドは、Adapty SDK v3.3.0 以降が必要な新しいペイウォールビルダーのペイウォール専用です。
Adapty SDK がモバイルアプリにどのように統合されているか、実際の例を見てみませんか?ペイウォールの表示、購入処理、その他の基本機能を含む完全なセットアップを実演しているサンプルアプリをご覧ください。
イベントの処理
モバイルアプリ内のペイウォール画面で発生するプロセスを制御・監視するには、AdaptyPaywallsEventsListener インターフェースを実装します。
using UnityEngine;
using AdaptySDK;
public class PaywallEventsHandler : MonoBehaviour, AdaptyPaywallsEventsListener
{
void Start()
{
Adapty.SetPaywallsEventsListener(this);
}
// Implement all required interface methods below
}
ユーザーが生成するイベント
ペイウォールの表示
ペイウォールビューが画面に表示されたときに呼び出されます。
iOS では、ユーザーがペイウォール内のウェブペイウォールボタンをタップして、インアプリブラウザでウェブペイウォールが開いたときにも呼び出されます。
public void PaywallViewDidAppear(AdaptyUIPaywallView view) { }
ペイウォールの非表示
ペイウォールビューが画面から閉じられたときに呼び出されます。
iOS では、ペイウォールからインアプリブラウザで開いたウェブペイウォールが画面から消えたときにも呼び出されます。
public void PaywallViewDidDisappear(AdaptyUIPaywallView view) { }
プロダクト選択
プロダクトが購入対象として選択されたとき(ユーザーまたはシステムによる)に呼び出されます。
public void PaywallViewDidSelectProduct(
AdaptyUIPaywallView view,
string productId
) { }
イベント例(クリックして展開)
{
"productId": "premium_monthly"
}購入開始
ユーザーが購入プロセスを開始したときに呼び出されます。
public void PaywallViewDidStartPurchase(
AdaptyUIPaywallView view,
AdaptyPaywallProduct product
) { }
イベント例(クリックして展開)
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"localizedPrice": "$9.99",
"price": 9.99,
"currencyCode": "USD"
}
}購入成功・キャンセル・保留
購入が成功した場合、ユーザーが購入をキャンセルした場合、または購入が保留中になった場合に、このメソッドが呼び出されます。ユーザーによるキャンセルや保留中の支払い(保護者の承認が必要な場合など)は、PaywallViewDidFailPurchase ではなくこのメソッドをトリガーします。
public void PaywallViewDidFinishPurchase(
AdaptyUIPaywallView view,
AdaptyPaywallProduct product,
AdaptyPurchaseResult purchasedResult
) { }
イベント例(クリックして展開)
// Successful purchase
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"localizedPrice": "$9.99",
"price": 9.99,
"currencyCode": "USD"
},
"purchaseResult": {
"type": "Success",
"profile": {
"accessLevels": {
"premium": {
"id": "premium",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
}
}
}
}
// Cancelled purchase
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"localizedPrice": "$9.99",
"price": 9.99,
"currencyCode": "USD"
},
"purchaseResult": {
"type": "UserCancelled"
}
}
// Pending purchase
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"localizedPrice": "$9.99",
"price": 9.99,
"currencyCode": "USD"
},
"purchaseResult": {
"type": "Pending"
}
}その場合は画面を閉じることをお勧めします。
購入失敗
エラーにより購入が失敗した場合に、このメソッドが呼び出されます。StoreKit/Google Play Billing のエラー(支払い制限、無効なプロダクト、ネットワーク障害)、トランザクション検証の失敗、システムエラーが含まれます。なお、ユーザーによるキャンセルはキャンセル結果として PaywallViewDidFinishPurchase をトリガーし、保留中の支払いはこのメソッドをトリガーしません。
public void PaywallViewDidFailPurchase(
AdaptyUIPaywallView view,
AdaptyPaywallProduct product,
AdaptyError error
) { }
イベント例(クリックして展開)
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"localizedPrice": "$9.99",
"price": 9.99,
"currencyCode": "USD"
},
"error": {
"code": "purchase_failed",
"message": "Purchase failed due to insufficient funds",
"details": {
"underlyingError": "Insufficient funds in account"
}
}
}復元開始
ユーザーが復元プロセスを開始したときに呼び出されます。
public void PaywallViewDidStartRestore(AdaptyUIPaywallView view) { }
復元成功
購入の復元が成功したときに呼び出されます。
public void PaywallViewDidFinishRestore(
AdaptyUIPaywallView view,
AdaptyProfile profile
) { }
イベント例(クリックして展開)
{
"profile": {
"accessLevels": {
"premium": {
"id": "premium",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
},
"subscriptions": [
{
"vendorProductId": "premium_monthly",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
]
}
}ユーザーが必要な accessLevel を持っている場合は、画面を閉じることをお勧めします。確認方法については、サブスクリプションのステータスを参照してください。
復元失敗
購入の復元が失敗したときに呼び出されます。
public void PaywallViewDidFailRestore(
AdaptyUIPaywallView view,
AdaptyError error
) { }
イベント例(クリックして展開)
{
"error": {
"code": "restore_failed",
"message": "Purchase restoration failed",
"details": {
"underlyingError": "No previous purchases found"
}
}
}ウェブ支払いナビゲーション完了
購入のためにウェブペイウォールを開こうとした後(成功・失敗に関わらず)、このメソッドが呼び出されます。
public void PaywallViewDidFinishWebPaymentNavigation(
AdaptyUIPaywallView view,
AdaptyPaywallProduct product,
AdaptyError error
) { }
パラメータ:
product: ウェブペイウォールが開かれた(または開こうとした)プロダクトerror: ウェブペイウォールが正常に開いた場合はnull、失敗した場合はAdaptyError
イベント例(クリックして展開)
// Successful navigation
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"localizedPrice": "$9.99",
"price": 9.99,
"currencyCode": "USD"
},
"error": null
}
// Failed navigation
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"localizedPrice": "$9.99",
"price": 9.99,
"currencyCode": "USD"
},
"error": {
"code": "wrong_param",
"message": "Current method is not available for this product",
"details": {
"underlyingError": "Product not configured for web purchases"
}
}
}データ取得とレンダリング
プロダクト読み込みエラー
プロダクトの読み込みに失敗し、AdaptyError が提供されたときに呼び出されます。初期化時にプロダクト配列を渡さなかった場合、AdaptyUI はサーバーから必要なオブジェクトを自動的に取得します。この処理が失敗した場合、AdaptyUI はこのメソッドを呼び出してエラーを報告します。
public void PaywallViewDidFailLoadingProducts(
AdaptyUIPaywallView view,
AdaptyError error
) { }
イベント例(クリックして展開)
{
"error": {
"code": "products_loading_failed",
"message": "Failed to load products from the server",
"details": {
"underlyingError": "Network timeout"
}
}
}レンダリングエラー
インターフェースのレンダリング中にエラーが発生し、AdaptyError が提供されたときに呼び出されます。
public void PaywallViewDidFailRendering(
AdaptyUIPaywallView view,
AdaptyError error
) { }
イベント例(クリックして展開)
{
"error": {
"code": "rendering_failed",
"message": "Failed to render paywall interface",
"details": {
"underlyingError": "Invalid paywall configuration"
}
}
}通常の状況ではこのようなエラーは発生しないはずです。もし遭遇した場合はお知らせください。