Reminder: By Aug 31, 2025, all new apps and updates to existing apps must use Billing Library version 7 or newer. If you need more time to update your app, you can request an extension until Nov 1, 2025. Learn about Play Billing Library version deprecation.
Google Play には購入ライフサイクル イベントをモニタリングするリアルタイム デベロッパー通知(RTDN)が用意されています。また、定期購入とアプリ内購入用の Play Developer API を使用すると、このようなイベントに基づいて必要なアクションを実行できます。これらのツールを使用して強固な購入ライフサイクル管理システムを構築することにより、シームレスなユーザー エクスペリエンスを提供でき、購入と利用資格を効率的に管理できます。
リアルタイム デベロッパー通知クライアントを構築する
Google Play の課金システムで実行された購入は、そのライフサイクル全体を通して複数回にわたり利用資格の変更が行われる場合があります。このような変更をトリガーするアクションはさまざまで、次のようなものがあります。
アプリ内でユーザーが行うアクション。
Google Play ストア アプリからユーザーが行うアクション。
バックエンド システムから直接行われるアクション。
Google Play Console から自分が行うアクション。
次に例を示します。
ユーザーが Google Play ストアの定期購入センターで定期購入を解約する。
デベロッパーが Google Play Developer API を使用して定期購入の請求を延長する。
デベロッパーが Google Play Console から購入の払い戻しと利用資格の取り消しを行う。
Google Play Developer API を使用して手動で購入ステータスを確認することは可能ですが、定期的なチェックに依存することは、変更のトラッキング方法としては非常に非効率であり、エラーと遅延が発生しやすくなります。RTDN を使用すると、Google Play での購入のライフサイクル トラッキング ロジックを構築することなく、すぐに変更に対応できます。
このセクションでは、RTDN のクライアントを構築する方法について説明します。RTDN は Google Cloud Pub/Sub を使用して構築された機能で、ユーザーの利用資格のステータスが変更されると、バックエンドにインスタント通知を送信します。Pub/Sub システムは通知を送信するパブリッシャーと、その通知を受信するクライアントで構成されます。RTDN を実装すると、ユーザーの利用資格のステータスに対するすべての変更をリアルタイムでトラッキングして、迅速に対応できます。
RTDN パブリッシャー
Google Play のバックエンドは RTDN パブリッシャーとして機能します。アプリに RTDN をセットアップするには、準備するガイドの手順に沿って行います。この手順により、Google Play の課金システムがアプリの RTDN パブリッシャーとして機能できるようになります。このセットアップを完了するには、Google Cloud Platform Console をよく理解したうえで、基本的な Pub/Sub 構成を設定する必要があります。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# Purchase lifecycle and RTDNs\n\nWhen you sell digital products through your app, you must consider the entire\nuser experience. In-app integration lets you launch purchase flows and\nmanage the user experience, but it's crucial to keep your backend up-to-date on\nthe entitlements that users are purchasing. This is important for tracking\npurchases and managing other aspects of the user experience, such as\ncross-platform entitlements.\n\nTo monitor purchase lifecycle events and respond quickly to changes in user\nentitlements, you should build a purchase status management system in your\nbackend for both subscriptions and one-time purchases. This system ensures quick\nand secure purchase processing regardless of device status, maintains consistent\nuser entitlements across all platforms, and provides the ability to consult\npurchase history and entitlement data in your backend.\n\nGoogle Play offers [real-time developer notifications\n(RTDN)](/google/play/billing/rtdn-reference) to monitor purchase lifecycle\nevents, and the Play Developer APIs for [Subscriptions and In-App\nPurchases](https://developers.google.com/android-publisher#subscriptions) can be\nused to take necessary actions based on these events. By using these tools and\nbuilding a robust purchase lifecycle management system, you can provide a\nseamless user experience and manage purchases and entitlements efficiently.\n\nBuild a real-time developer notification client\n-----------------------------------------------\n\nPurchases made on Google Play's billing system can go through several entitlement\nchanges throughout their lifecycle. Various actions can trigger these changes,\nincluding the following:\n\n- Actions initiated by users in your app.\n- Actions initiated by users through the Play Store app.\n- Actions initiated directly from your backend systems.\n- Actions that you initiate through the Google Play Console.\n\nFor example:\n\n- A user canceling a subscription through the Play Store subscription center.\n- A developer deferring subscription billing using the Google Play Developer API.\n- A developer issuing a refund and revoking entitlement for a purchase through the Google Play Console.\n\nIt is crucial that your backend is aware of the different states a purchase can\ngo through and that it takes all necessary measures to adjust the entitlement\naccordingly in a timely manner.\n\nWhile it is possible to use the Google Play Developer API to check a purchase\nstatus manually, relying on periodic checks is a very inefficient way to track\nchanges and it's prone to errors and delays. RTDNs can help you respond to\nchanges immediately without having to build lifecycle tracking logic for your\nGoogle Play purchases.\n\nThis section discusses how to build a client for RTDNs. RTDN is a feature built\nusing Google Cloud Pub/Sub, which sends your backend an instant notification\nwhen a user's entitlement state changes. The Pub/Sub system consists of a\npublisher that sends notifications and a client that subscribes to those\nnotifications. By implementing RTDN, you can track all changes to the user's\nentitlement state in real time and respond to them promptly.\n\n### RTDN publisher\n\nGoogle Play's backend acts as the publisher for RTDNs. To set up RTDN for you\napp, follow the instructions in the [Setup](/google/play/billing/getting-ready)\nguide. These steps allow Google Play's billing system to act as the publisher for\nyour app's RTDNs. To complete this setup, you should familiarize yourself with\nthe Google Cloud Platform Console to set up a basic Pub/Sub configuration.\n\n### RTDN subscriber\n\nAfter setting up the publisher, you should prepare your backend to consume\nRTDNs. To do this, you need to build a client to receive Google Cloud Pub/Sub\nmessages. Your RTDN client's basic function consists of receiving instances of\n[`PubSubMessage`](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage),\neither through HTTPS requests in a registered endpoint or by using the [Cloud\nPub/Sub client\nlibraries](https://cloud.google.com/pubsub/docs/reference/libraries). See the\nPub/Sub documentation to learn about using a\n[push](https://cloud.google.com/pubsub/docs/push) or a\n[pull](https://cloud.google.com/pubsub/docs/pull) strategy, or the [RTDN setup\ndocumentation](/google/play/billing/getting-ready#create-sub) for guidelines on\nchoosing the strategy that works best for your needs.\n\nFor each message you receive, your backend should do the following:\n\n- Unpack the base-64-encoded `data` field, which contains the [RTDN\n object](/google/play/billing/rtdn-reference#encoding).\n- Trigger any required backend processes related to the entitlement change notified by the RTDN event.\n\nHandle purchase state transitions\n---------------------------------\n\nOne-time purchases and subscription purchases have different lifecycles based on\nthe different states and events that can affect them. Thanks to RTDN, you don't\nneed to build logic to confirm state transitions. All you need to do is define\nwhat happens when your backend receives each type of notification.\n| **Note:** For [pre-orders](/google/play/billing/multi-offer-one-time-product#pre-order), RTDN follows the same lifecycle as the one-time purchase.\n\nSee the following guides to learn more about these scenarios:\n\n- [One-time purchase lifecycle](/google/play/billing/lifecycle/one-time)\n- [Subscription purchase lifecycle](/google/play/billing/lifecycle/subscriptions)"]]