2014/08/24

Android:Selling In-app Products

Introduction

AndroidではGoogle Playサービスを利用してアプリ内課金を比較的容易に導入できます.
本稿ではビジネス戦略の1つ”アプリ内課金”にフォーカスしたAndroid Developers | Selling In-app Productsを翻訳し, その実装方法について学びます.

Selling In-app Products

In this class, you’ll learn how to perform common In-app Billing operations from Android applications.

本章では, アプリ内課金に関する共通のオペレーションについて記載する.

In-app billing is a service hosted on Google Play that lets you charge for digital content or for upgrades in your app. The In-app Billing API makes it easy for you to integrate In-app Billing into your applications. You can request product details from Google Play, issue orders for in-app products, and quickly retrieve ownership information based on users’ purchase history. You can also query the Google Play service for details about in-app products, such as local pricing and availability.

アプリ内課金はデジタルコンテンツやアプリの有料アップグレードの請求に利用できるGoogle Playのサービスである.
アプリ内課金APIは簡単にアプリケーションに組み込むことができる.
Google Playに商品の詳細をリクエストしたり, アプリ内商品のオーダを発行したり,
ユーザのアイテム購入履歴から所有者情報を復元したりもできる.
そして, アプリ内商品のローカル価格や有効性についての詳細をGoogle Playに問い合わせできる.

Google Play provides a checkout interface that makes user interactions with the In-app Billing service seamless, and provides a more intuitive experience to your users.

Google Playはシームレスな清算インタフェースをアプリ内課金サービスで提供し, より直感的なユーザ体験を提供する.

This class describes how to get started with the Version 3 API. To learn how to use the version 2 API, see Implementing In-App Billing (V2).

この投稿ではIn-app Billing APIのVer.3について記載する. Ver.2のAPIについて知りたい場合はImplementing In-App Billing (V2).を参照.

Preparing Your In-app Billing Application

Before you can start using the In-app Billing service, you’ll need to add the library that contains the In-app Billing Version 3 API to your Android project. You also need to set the permissions for your application to communicate with Google Play. In addition, you’ll need to establish a connection between your application and Google Play. You should also verify that the In-app Billing API version that you are using in your application is supported by Google Play.

アプリ内課金サービスを利用するためにはAndroidプロジェクトへIn-app Billing Ver.3 APIし,
Google Playと通信するためにパーミッションの定義を必要とする.
さらに, 使用するアプリ内課金のAPIバージョンが, 連携するGoogle Playでサポートされているかを確認する必要がある.

Download the Sample Application

In this training class, you will use a reference implementation for the In-app Billing Version 3 API called the TrivialDrive sample application. The sample includes convenience classes to quickly set up the In-app Billing service, marshal and unmarshal data types, and handle In-app Billing requests from the main thread of your application.

ここでは, In-app Billing API Ver.3 を使用するTrivialDriveサンプルアプリを例に実装方法を見る.
サンプルアプリは, In-app Billing serviceのセットアップがすぐにでき, 組織化および非組織化されたデータ種別, そしてアプリmainスレッドでIn-app Billingリクエストをハンドルする便利クラスを含んでいる.

To download the sample application:

  • Open the Android SDK Manager.
  • In the SDK Manager, expand the Extras section.
  • Select Google Play Billing Library.
  • Click Install packages to complete the download.

The sample files will be installed to <sdk>/extras/google/play_billing/.

サンプルアプリのダウンロード方法は次の通り.

  1. Android SDK Managerを起動
  2. SDK ManagerでExtrasセクションを展開
  3. Google Play Billing Libraryを選択
  4. Install packagesを選択してダウンロードする

サンプルは<sdk>/extras/google/play_billing/にダウンロードされる.

Add Your Application to the Developer Console

The Google Play Developer Console is where you publish your In-app Billing application and manage the various digital goods that are available for purchase from your application. When you create a new application entry in the Developer Console, it automatically generates a public license key for your application.

Google Play Developer Consoleはアプリ内課金アプリを公開し, アプリで購入可能な様々な商品の管理も行う.
Developer Consoleで新規にアプリ登録した場合は, 自動でパブリックライセンスキーが払い出される.

You will need this key to establish a trusted connection from your application to the Google Play servers. You only need to generate this key once per application, and don’t need to repeat these steps when you update the APK file for your application.

パブリックライセンスキーは, アプリとGoogle Play間でセキュア接続を確立するために必要になる.
このキーを生成するのは一度だけで. アプリアップデートの度に毎回生成し直す必要はない.

To add your application to the Developer Console:

  1. Go to the Google Play Developer Console site and log in. You will need to register for a new developer account, if you have not registered previously. To sell in-app items, you also need to have a Google Wallet merchant account.
  2. Click on Try the new design to access the preview version of the Developer Console, if you are not already logged on to that version.
  3. In the All Applications tab, add a new application entry.
    • Click Add new application.
    • Enter a name for your new In-app Billing application.
    • Click Prepare Store Listing.
  4. In the Services & APIs tab, find and make a note of the public license key that Google Play generated for your application. This is a Base64 string that you will need to include in your application code later.

Your application should now appear in the list of applications in Developer Console.

Developer Consoleにアプリを追加する:

  1. Google Play Developer Consoleにログインする. 開発用アカウントを持っていない場合は作成する.
    アプリ内商品を売るにはGoogle Wallet merchantアカウントが必要になる.
  2. プレビューバージョンのDeveloper Consoleにルグインしていない場合はTry the new designをクリック
  3. All Applicationタブから新しくアプリを登録
    - Add new applicationをクリック
    - In-app Billingアプリの名前を入力
    - Prepare Store Listingをクリック
  4. Service & APIsタブで, 生成されたパブリックライセンスキーをメモする.
    キーはBase64エンコードされた文字列で, 後でアプリに組み込む必要がある.

これでアプリがDeveloper Consoleのアプリ一覧に追加される.

Add the In-app Billing Library

To use the In-app Billing Version 3 features, you must add the IInAppBillingService.aidl file to your Android project. This Android Interface Definition Language (AIDL) file defines the interface to the Google Play service.

In-app Builling Ver.3 APIを使うためには, Google Playサービスのインターフェースを定義したIInAppBillingService.aidlをAndroidプロジェクトへ追加する.

You can find the IInAppBillingService.aidl file in the provided sample app. Depending on whether you are creating a new application or modifying an existing application, follow the instructions below to add the In-app Billing Library to your project.

サンプルアプリもIInAppBillingService.aidlを持っている.
In-app Billing Version 3 library追加の手順を, 新規アプリ作成する場合 or 既存アプリを変更する場合 それぞれで例示する.

New Project

To add the In-app Billing Version 3 library to your new In-app Billing project:

新規アプリ作成する場合:

  1. Copy the TrivialDrive sample files into your Android project.
  2. Modify the package name in the files you copied to use the package name for your project. In Eclipse, you can use this shortcut: right-click the package name, then select Refactor > Rename.
  3. Open the AndroidManifest.xml file and update the package attribute value to use the package name for your project.
  4. Fix import statements as needed so that your project compiles correctly. In Eclipse, you can use this shortcut: press Ctrl+Shift+O in each file showing errors.
  5. Modify the sample to create your own application. Remember to copy the Base64 public license key for your application from the Developer Console over to your MainActivity.java.
  1. TrivialDriveサンプルにあるファイルをプロジェクトにコピーする
  2. ファイル内のパッケージ名を自アプリのパッケージ名に置き換える
  3. AndroidManifest.xmlのパッケージ名をあなたのアプリのパッケージ名に置き換える
  4. 必要なクラスをimportし, エラーをとる
  5. MainActivity.javaに, Developer Consoleで払い出されたBase64パブリックライセンスキーに置き換える
Existing Project

To add the In-app Billing Version 3 library to your existing In-app Billing project:

既存プロジェクトに追加する場合:

  1. Copy the IInAppBillingService.aidl file to your Android project.
    • If you are using Eclipse: Import the IInAppBillingService.aidl file into your /src directory.
    • If you are developing in a non-Eclipse environment: Create the following directory /src/com/android/vending/billing and copy the IInAppBillingService.aidl file into this directory.
  2. Build your application. You should see a generated file named IInAppBillingService.java in the /gen directory of your project.
  3. Add the helper classes from the /util directory of the TrivialDrive sample to your project. Remember to change the package name declarations in those files accordingly so that your project compiles correctly.
  1. IInAppBillingService.aidlファイルをプロジェクトにコピーする
  2. プロジェクトをビルドし, /genに生成されたIInAppBillingService.javaファイルを確認する
  3. TriviaDriveサンプルの/utilディレクトリにあるヘルパークラスをプロジェクトにコピーしてパッケージ名を変更する(パッケージ名は適宜変更する)

Your project should now contain the In-app Billing Version 3 library.

これでアプリにIn-app Billing Ver.3 libraryが取り込まれる.

Set the Billing Permission

Your app needs to have permission to communicate request and response messages to the Google Play’s billing service. To give your app the necessary permission, add this line in your AndroidManifest.xml manifest file:

Google Playの課金Serviceと通信する為に必要なPermissionをAndroidManifest.xmlに定義する.

<uses-permission android:name="com.android.vending.BILLING" />

Initiate a Connection with Google Play

You must bind your Activity to Google Play’s In-app Billing service to send In-app Billing requests to Google Play from your application. The convenience classes provided in the sample handles the binding to the In-app Billing service, so you don’t have to manage the network connection directly.

アプリからGoogle Playへ課金リクエストを送るには, ActivityをGoogle Playの課金Serviceにバインドする必要がある.
サンプルにあるヘルパークラスが課金Serviceへのバインドを処理するため, ネットワーク接続をあなたが直接意識する必要はない.

To set up synchronous communication with Google Play, create an IabHelper instance in your activity’s onCreate method. In the constructor, pass in the Context for the activity, along with a string containing the public license key that was generated earlier by the Google Play Developer Console.

Google Playとの同期通信を準備するため, ActivityonCreateメソッドでIabHelperインスタンスを生成する.
コンストラクタにはContextとパブリックライセンスキーを渡す.

Security Recommendation: It is highly recommended that you do not hard-code the exact public license key string value as provided by Google Play. Instead, you can construct the whole public license key string at runtime from substrings, or retrieve it from an encrypted store, before passing it to the constructor. This approach makes it more difficult for malicious third-parties to modify the public license key string in your APK file.

Security Recommendation:
パブリックライセンスキーは実行時に部分文字列から構築して生成するか, 暗号化して管理し, ハードコーディングは避けるように.
これは悪意のある第三者によるAPKにあるライセンスキーの改竄をより困難にする.

IabHelper mHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
   // ...
   String base64EncodedPublicKey;

   // compute your public key and store it in base64EncodedPublicKey
   mHelper = new IabHelper(this, base64EncodedPublicKey);
}

Next, perform the service binding by calling the startSetup method on the IabHelper instance that you created. Pass the method an OnIabSetupFinishedListener instance, which is called once the IabHelper completes the asynchronous setup operation. As part of the setup process, the IabHelper also checks if the In-app Billing Version 3 API is supported by Google Play. If the API version is not supported, or if an error occured while establishing the service binding, the listener is notified and passed an IabResult object with the error message.

次に、IabHelperstartSetupメソッドを呼んでServiceをバインドする. 非同期のセットアップが完了するとOnIabSetupFinishedListenerのメソッドが呼ばれる.
セットアップではIabHelperが, Google PlayのIn-app Billing Ver.3サポートをチェックする.
もしAPIがサポートされていなかったり, サービスのバインドが失敗した場合には, エラーメッセージを含んだIabResultオブジェクトがリスナーに通知される.

mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
   public void onIabSetupFinished(IabResult result) {
      if (!result.isSuccess()) {
         // Oh noes, there was a problem.
         Log.d(TAG, "Problem setting up In-app Billing: " + result);
      }            
         // Hooray, IAB is fully set up!  
   }
});

If the setup completed successfully, you can now use the mHelper reference to communicate with the Google Play service. When your application is launched, it is a good practice to query Google Play to find out what in-app items are owned by a user. This is covered further in the Query Purchased Items section.

セットアップが正常に完了したらGoogle Play Serviceと通信するmHelperが使用できる.
アプリ起動時にユーザの商品所有状態をチェックするのが良い方法である.
これについてはQuery Purchased Itemsで述べる.

Important: Remember to unbind from the In-app Billing service when you are done with your activity. If you don’t unbind, the open service connection could cause your device’s performance to degrade. To unbind and free your system resources, call the IabHelper’s dispose method when your Activity gets destroyed.

重要: Activity終了時に課金Serviceをアンバインドすること.
アンバインドを忘れてサービスとのコネクションを接続したままにすると端末のパフォーマンスが悪くなる.
アンバインドとシステムリソースを解放するにはIabHelperdisposeメソッドをActivity破棄時に呼び出すこと.

@Override
public void onDestroy() {
   super.onDestroy();
   if (mHelper != null) mHelper.dispose();
   mHelper = null;
}

Establishing In-app Billing Products for Sale

Before publishing your In-app Billing application, you’ll need to define the product list of digital goods available for purchase in the Google Play Developer Console.

課金アプリを公開する前に, Google Play Developer Consoleで販売できる商品のプロダクトリストを定義する.

Specify In-app Products in Google Play

From the Developer Console, you can define product information for in-app products and associate the product list with your application.

Developer Consoleで, アプリ内商品を定義してアプリと関連付ける.

To add new in-app products to your product list:

新しいin-appプロダクトをリストに追加する方法:

  1. Build a signed APK file for your In-app Billing application. To learn how to build and sign your APK, see Building Your Application for Release. Make sure that you are using your final (not debug) certificate and private key to sign your application.
  2. In the Developer Console, open the application entry that you created earlier.
  3. Click on the APK tab then click on Upload new APK. Upload the signed APK file to the Developer Console. Don’t publish the app yet!
  4. Navigate to the uploaded app listing, and click on In-app Products.
  5. Click on the option to add a new product, then complete the form to specify the product information such as the item’s unique product ID (also called its SKU), description, price, and country availability. Note down the product ID since you might need this information to query purchase details in your application later.
    Important: The In-app Billing Version 3 service only supports managed in-app products, so make sure that you specify that the purchase type is ‘Managed’ when you add new items to your product list in the Developer Console.
  6. Once you have completed the form, activate the product so that your application can purchase it.
    Warning: It may take up to 2-3 hours after uploading the APK for Google Play to recognize your updated APK version. If you try to test your application before your uploaded APK is recognized by Google Play, your application will receive a ‘purchase cancelled’ response with an error message “This version of the application is not enabled for In-app Billing.”
  1. 商用署名済みAPKを作成する. 商用署名ビルドについてはBuilding Your Application for Releaseを参照.
  2. Developer Consoleでアプリの登録画面を開く
  3. APKタブ > Upload new APKと進み, 署名済みAPKをアップロードする(まだ公開しないこと!)
  4. アップロードしたアプリのIn-app Productをクリック.
  5. 新しい商品を追加するためのoptionをクリック.
    商品情報(アイテムのユニークID(SKU), 説明, 価格, 利用できる国)をフォームに入力する. ユニークIDはこのあとのアプリでの購入情報の問い合わせに必要になるため書き留めておくこと.
    重要:
    In-app Billing Ver.3サービスは管理されたアプリ内商品のみをサポートする.
    Developer Consoleで新しい商品をプロダクトリストに追加した際には, 購入種別が”Managed”に指定されていることを確認すること.
  6. 登録が終わったら商品をアプリで購入することが可能になる.
    注意:
    APKはGoogle Playにアップしてから2-3時間後に有効化される場合がある.
    もし反映されるよりも前にテストすると, “purcase cancelled”, “This version of the application is not enabled for In-app Billing”のエラーが応答される.

Query Items Available for Purchase

You can query Google Play to programmatically retrieve details of the in-app products that are associated with your application (such as the product’s price, title, description, and type). This is useful, for example, when you want to display a listing of unowned items that are still available for purchase to users.

アプリと関係する商品情報(商品価格, タイトル, 説明, 種別)をプログラマブルにGoogle Playへ問い合わせることができる.
例えば, 未購入の商品を表示したい場合などに使用される.

Note: When making the query, you will need to specify the product IDs for the products explicitly. You can manually find the product IDs from the Developer Console by opening the In-app Products tab for your application. The product IDs are listed under the column labeled Name/ID.

Note: クエリにはどの商品かを特定するための商品IDが必要になる.
商品IDはDeveloper ConsoleのIn-app ProductsタブにあるName/IDラベルのカラムにリストされている.

To retrieve the product details, call queryInventoryAsync(boolean, List, QueryInventoryFinishedListener) on your IabHelper instance.

商品を検索するのに, IabHelperqueryInventoryAsync(boolean, List, QueryInventoryFinishedListener)メソッドが使える.

  1. The first input argument indicates whether product details should be retrieved (should be set to true).
  2. The List argument consists of one or more product IDs (also called SKUs) for the products that you want to query.
  3. Finally, the QueryInventoryFinishedListener argument specifies a listener is notified when the query operation has completed and handles the query response.
  1. 1つめの引数は商品情報を検索対象とするかどうか(検索する場合はtrueをセット)
  2. 引数Listは, 検索対象の商品ID(SKU)を指定
  3. 引数QueryInventoryFinishedListenerは, クエリ完了とその結果を受け取るためのリスナを指定する

If you use the convenience classes provided in the sample, the classes will handle background thread management for In-app Billing requests, so you can safely make queries from the main thread of your application.

もしサンプルにあるヘルパークラスを使用すれば, 課金リクエストをバックグラウンドで実行するのでメインスレッドからでも安全に呼び出せる.

The following code shows how you can retrieve the details for two products with IDs SKU_APPLE and SKU_BANANA that you previously defined in the Developer Console.

次はDeveloper Consoleであらかじめ定義したSKU_APPLESKU_BANANA, 2つの商品詳細を検索するコード.

List additionalSkuList = new List();
additionalSkuList.add(SKU_APPLE);
additionalSkuList.add(SKU_BANANA);
mHelper.queryInventoryAsync(true, additionalSkuList,
   mQueryFinishedListener);

If the query is successful, the query results are stored in an Inventory object that is passed back to the listener.

クエリが成功したらInventoryオブジェクトに結果が格納されてリスナーに通知される.

The following code shows how you can retrieve the item prices from the result set.

次のコードは結果セットから商品価格を取り出す方法.

IabHelper.QueryInventoryFinishedListener 
   mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
   public void onQueryInventoryFinished(IabResult result, Inventory inventory)   
   {
      if (result.isFailure()) {
         // handle error
         return;
       }

       String applePrice =
          inventory.getSkuDetails(SKU_APPLE).getPrice();
       String bananaPrice =
          inventory.getSkuDetails(SKU_BANANA).getPrice();

       // update the UI 
   }
}

Purchasing In-app Billing Products

Once your application is connected to Google Play, you can initiate purchase requests for in-app products. Google Play provides a checkout interface for users to enter their payment method, so your application does not need to handle payment transactions directly.

アプリとGoogle Playを接続すれば, アプリ内商品の購入リクエストを開始できる.
Google Playは支払い方法を指定できるチェックアウト用のインタフェースを提供するため, アプリは直接支払い処理を実装する必要がない.

When an item is purchased, Google Play recognizes that the user has ownership of that item and prevents the user from purchasing another item with the same product ID until it is consumed. You can control how the item is consumed in your application, and notify Google Play to make the item available for purchase again.

商品の支払いが完了した時, Google Playはユーザがその商品を所有したことを認識し, 同じIDの商品を購入できないようケアする.
アプリ内商品の消費はコントロールでき, 再び購入可能とするためにGoogle Playへ通知することができる.

You can also query Google Play to quickly retrieve the list of purchases that were made by the user. This is useful, for example, when you want to restore the user’s purchases when your user launches your app.

また, Google Playにユーザの購入履歴を問い合わせることができる.
例えば, アプリ起動時に購入履歴から商品の所有状態を復元するのに利用できる.

Purchase an Item

To start a purchase request from your app, call launchPurchaseFlow(Activity, String, int, OnIabPurchaseFinishedListener, String) on your IabHelper instance. You must make this call from the main thread of your Activity. Here’s an explaination of the launchPurchaseFlow method parameters:

アプリから購入リクエストを開始する時, IabHelperlaunchPurchaseFlow(Activity, String, int, OnIabPurchaseFinishedListener, String)を呼び出す. これはActivityのメインスレッドから呼ぶこと. launchPurchaseFlowメソッドのパラメータは下記の通り.

  • The first argument is the calling Activity.
  • The second argument is the product ID (also called its SKU) of the item to purchase. Make sure that you are providing the ID and not the product name. You must have previously defined and activated the item in the Developer Console, otherwise it won’t be recognized.
  • The third argument is a request code value. This value can be any positive integer. Google Play returns this request code to the calling Activity’s onActivityResult along with the purchase response.
  • The fourth argument is a listener that is notified when the purchase operation has completed and handles the purchase response from Google Play.
  • The fifth argument contains a ‘developer payload’ string that you can use to send supplemental information about an order (it can be an empty string). Typically, this is used to pass in a string token that uniquely identifies this purchase request. If you specify a string value, Google Play returns this string along with the purchase response. Subsequently, when you make queries about this purchase, Google Play returns this string together with the purchase details.
    Security Recommendation: It’s good practice to pass in a string that helps your application to identify the user who made the purchase, so that you can later verify that this is a legitimate purchase by that user. For consumable items, you can use a randomly generated string, but for non-consumable items you should use a string that uniquely identifies the user.
  • 第一引数は呼び出し元のActivity
  • 第二引数は購入アイテムの商品ID(SKU). 商品名ではなく商品IDとすること.
    商品は事前にDeveloper Consoleで定義しておかないと商品として認識されない.
  • 第三引数はリクエストコード. この値は正の数となる.
    Google Playは購入リクエストの応答(ActivityonActivityResult)で, このリクエストコードを返す
  • 第四引数は購入操作が完了し, Google Playからの応答をハンドルするリスナー
  • 第五引数は任意のヘッダ文字列(‘developer payload’), 注文の付加情報として使用できる(空文字でもよい)
    通常, 購入リクエストを識別するためのユニークID(token)が使用される.
    Google Playの購入レスポンスには, ここで指定した文字列が一緒に渡される.
    続いて, この購入情報を問い合わせる時, Google Playは購入情報の詳細と一緒にこの文字列を返す.
    Security Recommendation:
    この方法は誰の購入情報かを識別するのに良い方法となる.
    これにより, 後から商品購入の妥当性をチェックできる. 消耗品にはランダムなtokenを使い回すだろうが,
    永続的な商品の場合はユニークIDを使用すべきである.

The following example shows how you can make a purchase request for a product with ID SKU_GAS, using an arbitrary value of 10001 for the request code, and an encoded developer payload string.

次の例は, 商品IDがSKU_GAS, 任意のリクエストコード(10001), エンコードしたdeveloper payload文字列を指定したの商品購入リクエストを使用する方法である.

mHelper.launchPurchaseFlow(this, SKU_GAS, 10001,   
   mPurchaseFinishedListener, "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");

If the purchase order is successful, the response data from Google Play is stored in an Purchase object that is passed back to the listener.

もし購入オーダが成功すれば, Google Playからの応答データはPurchaseオブジェクトに格納されてリスナーに通知される.

The following example shows how you can handle the purchase response in the listener, depending on whether the purchase order was completed successfully, and whether the user purchased gas or a premium upgrade. In this example, gas is an in-app product that can be purchased multiple times, so you should consume the purchase to allow the user to buy it again. To learn how to consume purchases, see the [Consuming Products][t1_3c] section. The premium upgrade is a one-time purchase so you don’t need to consume it. It is good practice to update the UI immediately so that your users can see their newly purchased items.

次はリスナーで購入レスポンスをどのようにして処理するかを例示する.
レスポンスから購入した商品がgasなのかプレミアムアップグレードなのかで処理を分けている.
サンプルコードで, gasは複数回購入可能な商品であり, 再度購入できるよう消費させている.
どうやって購入した商品を消費させるかはConsuming Productsセクションで述べる.
プレミアムアップグレードは一度だけ購入できるアイテムであるため消費させない.
ユーザが購入できたことを認識できるよう, すぐにUIを更新するのが良い方法である.

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
   = new IabHelper.OnIabPurchaseFinishedListener() {
   public void onIabPurchaseFinished(IabResult result, Purchase purchase) 
   {
      if (result.isFailure()) {
         Log.d(TAG, "Error purchasing: " + result);
         return;
      }      
      else if (purchase.getSku().equals(SKU_GAS)) {
         // consume the gas and update the UI
      }
      else if (purchase.getSku().equals(SKU_PREMIUM)) {
         // give user access to premium content and update the UI
      }
   }
};

Security Recommendation: When you receive the purchase response from Google Play, make sure to check the returned data signature, the orderId, and the developerPayload string in the Purchase object to make sure that you are getting the expected values. You should verify that the orderId is a unique value that you have not previously processed, and the developerPayload string matches the token that you sent previously with the purchase request. As a further security precaution, you should perform the verification on your own secure server.

Security Recommendation: Google Playから支払いの応答を受けたとき, 返却されたPurchaseのsignature, orderId, developerPayloadが期待する値かチェックする(Man in the middle attackの防止). orderIdが過去に処理していないユニークな値であるか, developerPayloadtokenが購入リクエスト時のものと一致するか. 更に厳重に信頼できる自前のセキュアサーバであることが望ましい.

Query Purchased Items

Upon a successful purchase, the user’s purchase data is cached locally by Google Play’s In-app Billing service. It is good practice to frequently query the In-app Billing service for the user’s purchases, for example whenever the app starts up or resumes, so that the user’s current in-app product ownership information is always reflected in your app.

購入が成功すると, そのデータはGoogle Playのアプリ内課金サービスにローカルキャッシュされる.
アプリの開始時, 再開時にユーザ購入履歴をアプリ内課金サービスに頻繁に問い合わせすることは, アプリ内商品の所有情報を常に最新に保つのによい方法となる.

To retrieve the user’s purchases from your app, call queryInventoryAsync(QueryInventoryFinishedListener) on your IabHelper instance. The QueryInventoryFinishedListener argument specifies a listener that is notified when the query operation has completed and handles the query response. It is safe to make this call fom your main thread.

アプリからユーザ購入情報を復元するために, IabHelperqueryInventoryAsync(QueryInventoryFinishedListener)が使用できる. 引数QueryInventoryFinishedListenerはクエリ完了時に結果通知を受け取るリスナを指定する.
このメソッドはメインスレッドから呼び出すことができる.

mHelper.queryInventoryAsync(mGotInventoryListener);

If the query is successful, the query results are stored in an Inventory object that is passed back to the listener. The In-app Billing service returns only the purchases made by the user account that is currently logged in to the device.

クエリが成功したとき, Inventoryオブジェクトに結果が格納されリスナーに通知される.
アプリ内課金サービスは現在端末でログインされているユーザアカウントの購入のみを返却する.

IabHelper.QueryInventoryFinishedListener mGotInventoryListener 
   = new IabHelper.QueryInventoryFinishedListener() {
   public void onQueryInventoryFinished(IabResult result,
      Inventory inventory) {

      if (result.isFailure()) {
        // handle error here
      }
      else {
        // does the user have the premium upgrade?
        mIsPremium = inventory.hasPurchase(SKU_PREMIUM);        
        // update UI accordingly
      }
   }
};

Consume a Purchase

You can use the In-app Billing Version 3 API to track the ownership of purchased items in Google Play. Once an item is purchased, it is considered to be “owned” and cannot be purchased again from Google Play while in that state. You must send a consumption request for the item before Google Play makes it available for purchase again. All managed in-app products are consumable. How you use the consumption mechanism in your app is up to you. Typically, you would implement consumption for products with temporary benefits that users may want to purchase multiple times (for example, in-game currency or replenishable game tokens). You would typically not want to implement consumption for products that are purchased once and provide a permanent effect (for example, a premium upgrade).

In-app Billing Ver.3 APIはユーザがGoogle Playで購入した商品の所有情報を追跡するために使える.
商品を購入すると”owned(所有中)”とみなされ, この状態ではGoogle Playで再購入できなくなる.
再購入できるようにするには商品の消費リクエストをGoogle Playに送信しなくてはならない(Purchase(購入)とConsume(消費)は対の概念).
アプリ内商品は全て消費可能であるが, 消費メカニズムをどう使うかはアプリ次第となる.
通常, 一時的に役立つような商品(アプリ内通貨や補給物資)には消費を実装すべきで,
永続的な効果を持つ商品の場合(プレミアムアップグレードなど)は一度限りの購入で完結し, 消費は実装しない.

It’s your responsibility to control and track how the in-app product is provisioned to the user. For example, if the user purchased in-game currency, you should update the player’s inventory with the amount of currency purchased.

アプリ内商品をどう管理し, どう追跡してユーザに提供するかはアプリの責務である.
例えば, ユーザがゲーム内通貨を購入したとき, プレイヤーの資金にそれを追加すべきである.

Security Recommendation: You must send a consumption request before provisioning the benefit of the consumable in-app purchase to the user. Make sure that you have received a successful consumption response from Google Play before you provision the item.

Security Recommendation:
商品の消費を反映する前に, 消費リクエストを送信すべきである.
商品を提供する前に消費成功の応答をGoogle Playから受け取るように.

To record a purchase consumption, call consumeAsync(Purchase, OnConsumeFinishedListener) on your IabHelper instance. The first argument that the method takes is the Purchase object representing the item to consume. The second argument is a OnConsumeFinishedListener that is notified when the consumption operation has completed and handles the consumption response from Google Play. It is safe to make this call fom your main thread.

購入消費を記録するにはIabHelperconsumeAsync(Purchase, OnConsumeFinishedListener)メソッドを呼ぶ.
第一引数は消費するアイテムのPurchaseオブジェクトを指定する. 第二引数は消費処理が完了しGoogle Playから応答の通知を受け取るOnConsumeFinishedListenerを指定する.
これはメインメソッドから呼び出せる.

In this example, you want to consume the gas item that the user has previously purchased in your app.

ユーザが購入した商品”gas”を消費するサンプル.

mHelper.consumeAsync(inventory.getPurchase(SKU_GAS), 
   mConsumeFinishedListener);

The following example shows how to implement the OnConsumeFinishedListener.

OnConsumeFinishedListenerの実装サンプルは次の通り.

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
   new IabHelper.OnConsumeFinishedListener() {
   public void onConsumeFinished(Purchase purchase, IabResult result) {
      if (result.isSuccess()) {
         // provision the in-app purchase to the user
         // (for example, credit 50 gold coins to player's character)
      }
      else {
         // handle error
      }
   }
};

Check for Consumable Items on Startup

It’s important to check for consumable items when the user starts up your application. Typically, you would first query the In-app Billing service for the items purchased by the user (via queryInventoryAsync), then get the consumable Purchase objects from the Inventory. If your application detects that are any consumable items that are owned by the user, you should send a consumption request to Google Play immediately and provision the item to the user. See the TrivialDrive sample for an example of how to implement this checking at startup.

アプリ起動時に消耗品をチェックすること.
まず始めにユーザが購入済みの商品をアプリ内課金サービスへ問い合わせる(queryInventoryAsyncを経由して). そして, Inventoryから消費できるPurchaseオブジェクトを取得する.
もし消耗品をユーザが所有している場合, Google Playに消費リクエストを送り, ユーザに提供すること.
これらの実装はTriviaDriveサンプルの例が参考になる.


Testing Your In-app Billing Application

To ensure that In-app Billing is functioning correctly in your application, you should test the test the application before you publish it on Google Play. Early testing also helps to ensure that the user flow for purchasing in-app items is not confusing or slow, and that users can see their newly purchased items in a timely way.

Google Playで公開する前にアプリ内課金が正しく動作しているかテストすること.
事前のテストで商品の購入フローが紛らわしいものでないか, 手間でないかを確認する.
そして, ユーザが新たに購入した商品をタイムリーに確認できることもテストする.

Test with Static Responses

Test your In-app Billing application with static responses by using Google Play’s reserved product IDs. By using reserved product IDs instead of actual product IDs, you can test the purchase flow without specifying an actual payment method or transferring money. To learn more about the reserved product IDs, see Testing In-app Billing.

Google Playで予約された商品IDを使った静的な応答でアプリの課金処理をテストできる.
予約された商品IDは本来の商品IDの代わりとなる.
これにより, 実際にお金を払うことなく購入テストが可能となる.
予約された商品IDについての詳細はTesting In-app Billingを参照.

Test with Your Own Product IDs

Because Google Play does not allow you to use your developer account to directly purchase in-app products that you have created yourself, you’ll need to create test acccounts under your developer account profile. To create a test account, simply enter a valid Google email address. Users with these test accounts will then be able to make in-app-billing purchases from uploaded, unpublished applications that you manage.

Google Playは開発用アカウントで直接商品を購入することを許可していないので, 購入テスト用のアカウントを作成する必要がある.
テストアカウントを作成するために有効なGmailアドレスを登録する.
テストアカウントを持つと, アップロードされた非公開状態のアプリでアプリ内課金をテストできるようになる.

To test your In-app Billing Version 3 application using your own product IDs:

自前の商品IDを使用してIn-app Billing Ver.3を使用した課金アプリをテストするには.

  1. In the Developer Console, add one or more tester accounts to the developer account that you are using to publish your application.
    a. Login to the Developer Console with your developer account.
    b. Click Settings > Account details, then in the License Testing section, add the Google email addresses for your tester accounts.
  2. Build a signed APK file for your In-app Billing application. To learn how to build and sign your APK, see Building Your Application for Release. Make sure that you are using your final (not debug) certificate and private key to sign your application.
  3. Make sure that you have uploaded the signed APK for your application to the Developer Console, and associated one or more in-app products with your application. You don’t need to publish the application on Google Play to test it.
    Warning: It may take up to 2-3 hours after uploading the APK for Google Play to recognize your updated APK version. If you try to test your application before your uploaded APK is recognized by Google Play, your application will receive a ‘purchase cancelled’ response with an error message “This version of the application is not enabled for In-app Billing.”
  4. Install the APK file to your physical test device by using the adb tool. To learn how to install the application, see Running on a Device. Make sure that:
    • Your test device is running on Android SDK Version 2.2 (API level 8) or higher, and is installed with Google Play client Version 3.9.16 or higher.
    • The android:versionCode and android:versionName attributes values in the AndroidManifest.xml of the application that you are installing matches the values of your APK in the Developer Console.
    • Your application is signed with the same certificate that you used for the APK that you uploaded to the Developer Console, before installing it on your device.
  5. Login to the test device by using a tester account. Test your In-app Billing application by purchasing a few items, and fix any issues that you encounter. To learn more about how you can perform large-scale testing of your In-app Billing app, see Test Purchases (In-app Billing Sandbox).
  1. Developer Consoleで1つ以上の購入テスト用アカウントを開発用アカウントに追加し, アプリを共有する
    a. Developer Consoleに開発用アカウントでログイン
    b. Settings > Accountの詳細をクリック, License Testingセクションに購入テスト用のGmailアドレスを追加
  2. 署名された課金アプリのAPKを作成. APKの署名方法についてはBuilding Your Application for Releaseを参照.
  3. Developer Consoleに署名されたアプリをアップロードする. そして, 1つ以上の商品をアプリに関連付ける.
    テストの為にGoogle Playにアプリを公開する必要はない.
  4. adbツールでテスト端末にAPKをインストールする. APKのインストールについてはRunning on a Deviceを参照. 次のことを確認すること:
    • デバイスのSDK Ver.が2.2(API Level8)以上であり, Google Play Ver.3.9.16以上であること
    • インストール前後のAPK署名がDeveloper ConsoleにアップロードされたAPKのものと同じであること
  5. テストデバイス上で購入テスト用アカウントでログインし, 課金アプリでいくつかの商品を購入し,
    テストして見つけた不具合を修正する. In-app Billingアプリの大規模テストについてはTest Purchases (In-app Billing Sandbox)を参照.

License:
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Android:Google Play In-App Subscriptions

Introduction

AndroidではGoogle Playサービスを利用してアプリ内課金を比較的容易に導入できます.
本稿ではビジネス戦略の1つ”アプリ内課金”にフォーカスしたAndroid Developers | Google Play In-App Subscriptionsを翻訳し, サブスクリプションについて学びます.

Google Play In-App Subscriptions

Subscriptions let you sell content, services, or features in your app with automated, recurring billing. You can easily adapt an existing In-app Billing implementation to sell subscriptions.

サブスクリプションはコンテンツ, サービス, 機能を定期的に自動で購入させるサービスであり, 簡単にアプリへ組み込める.

This document is focused on highlighting implementation details that are specific to subscriptions, along with some strategies for the associated billing and business models.

本稿では, サブスクリプションの詳細と課金戦略, ビジネスモデルにフォーカスする.

Overview of Subscriptions

A subscription is a product type offered in In-app Billing that lets you sell content, services, or features to users from inside your app with recurring monthly or annual billing. You can sell subscriptions to almost any type of digital content, from any type of app or game.

サブスクリプションはアプリ内課金商品の一種で, コンテンツ, サービス, 機能を毎月, 毎年といった単位で定期的に自動購入させるサービスである.
サブスクリプションはほとんどの商品に適用できる.

As with other in-app products, you configure and publish subscriptions using the Developer Console and then sell them from inside apps installed on Android devices. In the Developer console, you create subscription products and add them to a product list, then set a price and optional trial period for each, choose a billing interval (monthly or annual), and then publish. For more information about using the Developer Console, see Configuring Subscription Items.

他の商品と同じようにサブスクリプションもDeveloper Consoleで設定し, Androidにインストールされたアプリ内で販売される.
Developer Consoleでサブスクリプションを作成し, プロダクトリストに追加し, 価格を決めて, オプションでお試し期間を設定し, 自動課金される期間(毎月 or 毎年)を設定して公開する.
Developer Consoleについてのより詳細な情報はConfiguring Subscription Itemsを参照.

When users purchase subscriptions in your apps, Google Play handles all checkout details so your apps never have to directly process any financial transactions. Google Play processes all payments for subscriptions through Google Wallet, just as it does for standard in-app products and app purchases. This ensures a consistent and familiar purchase flow for your users.

ユーザによるサブスクリプションの購入にあたってはGoogle Playが勘定に関する処理を行うため, アプリがこれに関与する必要がない.
Google Playはサブスクリプションの支払い処理を通常の商品と同じくGoogle Walletを使用して行う.
購入のフローはアプリや, 他の商品購入時と一貫したものになる.

enter image description here

After users have purchase subscriptions, they can view the subscriptions and cancel them from the My Apps screen in the Play Store app or from the app’s product details page in the Play Store app. For more information about handling user cancellations, see Subscription Cancellation.

購入したサブスクリプションはGoogle Playのアプリ詳細画面か, マイストアから購読を停止することができる.
購読のキャンセルについてより詳細な情報はSubscription Cancellationを参照.

In adddition to client-side API calls, you can use the server-side API for In-app Billing to provide subscription purchasers with extended access to content (for example, from your web site or another service). The server-side API lets you validate the status of a subscription when users sign into your other services. For more information about the API, see Purchase Status API.

アプリ内課金のサブスクリプションについては, クライアントサイドAPIに加えてサーバサイドAPIも提供されている.
サーバサイドAPIはAndroid以外の独自サービスからも使用でき, サブスクリプションのステータスを取得することができる.

You can also build on your existing external subscriber base from inside your Android apps.

  • If you sell subscriptions on a web site, for example, you can add your own business logic to your Android app to determine whether the user has already purchased a subscription elsewhere, then allow access to your content if so or offer a subscription purchase from Google Play if not.
  • You can implement your own solution for sharing subscriptions across as many different apps or products as you want. For example, you could sell a subscription that gives a subscriber access to an entire collection of apps, games, or other content for a monthly or annual fee. To implement this solution, you could add your own business logic to your app to determine whether the user has already purchased a given subscription and if so, allow access to your content.

外部サービスで提供しているサブスクリプションを購入済みなユーザへの配慮.

  • Webサイトで独自のサブスクリプションを販売しているような場合, 独自のビジネスロジックをアプリに追加しユーザが既にサブスクリプションを購入済みであるかどうかを確認する. 購入済みであるなら独自コンテンツを提供するし, そうでないならGoogle Playから購入させる.
  • 異なるアプリや商品を跨いでサブスクリプションを共有するために独自のソリューションを実装できる.
    例えば, 月額or年額の手数料を払えばアプリやゲームのコレクションを自由に遊べるサブスクリプションを売りたいとする.
    これを実現するためには, アプリにユーザが既にサブスクリプションを購入済みかどうかを判断するビジネスロジックを組み込み, その上でコンテンツにアクセスさせる.

In general the same basic policies and terms apply to subscriptions as to standard in-app products, however there are some differences. For complete information about the current policies and terms, please read the policies document.

To learn about the minimum system requirements for subscriptions, see the Version Notes.

サブスクリプションについての基本的なポリシーや条件は, 標準のアプリ内商品にも同じことが言える.
細部では異なる部分もあるので, 詳細はpolicies documentを参照.

サブスクリプションについての最小要件についてはVersion Notesを参照.

Configuring Subscription Items

To create and manage subscriptions, use the Developer Console to set up a product list for the app then configure these attributes for each subscription product:

  • Purchase Type: always set to Subscription
  • Subscription ID: An identifier for the subscription
  • Publishing State: Unpublished/Published
  • Language: The default language for displaying the subscription
  • Title: The title of the subscription product
  • Description: Details that tell the user about the subscription
  • Price: USD price of subscription per recurrence
  • Recurrence: monthly or yearly
  • Additional currency pricing (can be auto-filled)

For details on how to add and configure products in the Developer Console, see Administering In-app Billing.

サブスクリプションの作成と管理について, アプリで使用できるようにDeveloper Consoleを使って商品リストをセットアップする.
作成, 管理にあたりサブスクリプションの設定項目には次がある:

  • 購入種別: 常にSubscriptionを設定する
  • サブスクリプションID: サブスクリプションの識別子
  • 公開状態: 公開/非公開
  • 言語: サブスクリプションを表示する際のデフォルト言語設定
  • タイトル: サブスクリプションのタイトル
  • 説明: サブスクリプションについての説明文
  • デフォルト価格: USD価格(毎月or毎年単位で支払う額)
  • 支払い間隔: 月単位 or 年単位
  • 追加の価格(USDから価格オートフィルされます)

Developer Consoleでの商品設定について詳細な情報はAdministering In-app Billingを参照.

Subscription pricing

When you create a subscription in the Developer Console, you can set a price for it in any available currencies. Each subscription must have a non-zero price. You can price multiple subscriptions for the same content differently — for example you could offer a discount on an annual subscription relative to the monthly equivalent.

Important: To change the price of a subscription, you can publish a new subscription product ID at a new price, then offer it in your app instead of the original product. Users who have already purchased will continue to be charged at the original price, but new users will be charged at the new price.

Developer Consoleでサブスクリプションを作成するときに(その時有効な通貨で)価格を設定できるが, どのサブスクリプションも有料である必要がある.
1つのサブスクリプションに対して異なる価格を設定できる. 例えば, 購読期間に応じて, 月毎に課金額を割引くようなサービスで使える.

Important: サブスクリプションの価格を変更すると, 新しい価格設定のサブスクリプションIDが払い出され, オリジナルの商品と置き換えられる.
価格変更前にこれを購入していたユーザはオリジナル価格が引き継がれ, 価格変更後にこれを購入したユーザは変更後の価格が反映される.

User billing

In the Developer Console, you can configure subscription products with automated recurring billing at either of two intervals:

  • Monthly — Google Play bills the customer’s Google Wallet account at the time of purchase and monthly subsequent to the purchase date (exact billing intervals can vary slightly over time)
  • Annually — Google Play bills the customer’s Google Wallet account at the time of purchase and again on the same date in subsequent years.

Developer Consoleでサブスクリプションの支払い間隔として次の2つが設定できる.

  • 毎月 — Google Playは商品を購読しているユーザのGoogle Walletアカウントに対して毎月請求する.
    (厳密にいうと, 請求される間隔は正確に一ヶ月とはならないかもしれない)
  • 毎年 — Google Playは商品を購読しているユーザのGoogle Walletアカウントに対して毎年請求する.
    (翌年の同月日となる)

Billing continues indefinitely at the interval and price specified for the subscription. At each subscription renewal, Google Play charges the user account automatically, then notifies the user of the charges afterward by email. Billing cycles will always match subscription cycles, based on the purchase date.

Over the life of a subscription, the form of payment billed remains the same — Google Play always bills the same form of payment (such as credit card or by Direct Carrier Billing) that was originally used to purchase the subscription.

サブスクリプションの支払い間隔と価格設定は無期限で反映される. サブスクリプションが更新されたり, 自動請求されるとユーザにemailで通知される. サブスクリプションを購入した日付を基準に, 請求される

購読中の支払い方法(クレジットカードや直接支払など)は変わらない. Google Playはサブスクリプション購入時と同じ請求を常に行う.

When the subscription payment is approved by Google Wallet, Google Play provides a purchase token back to the purchasing app through the In-app Billing API. Your apps can store the token locally or pass it to your backend servers, which can then use it to validate or cancel the subscription remotely using the Purchase Status API.

Google Walletによりサブスクリプションの支払いが承認された時, In-app Billing APIを介してGoogle Playから購入Tokenが返される.
購入Tokenはローカルに保存するかバックエンドサーバに送信し, 外部からPurchase Status APIを使用してサブスクリプションを有効にしたり停止したりすることができる.

If a recurring payment fails (for example, because the customer’s credit card has become invalid), the subscription does not renew. How your app is notified depends on the In-app Billing API version that you are using:

  • With In-app Billing Version 3, the failed or expired subscription is no longer returned when you call getPurchases.
  • With In-app Billing Version 2, Google Play notifies your app at the end of the active cycle that the purchase state of the subscription is now “Expired”.

クレジットカードが失効される等して定期支払が失敗するとサブスクリプションは更新されなくなる.
これがどうやってアプリに通知されるかは使用しているIn-app Billing APIのバージョンに依存する.

  • Ver.3を使用している場合, 期限切れや失敗した場合はgetPurchasesは商品を返さない.
  • Ver.2を使用している場合, Google Playは購入状態が”Expired”になった時にアプリへ通知される.

Recommendation: Include business logic in your app to notify your backend servers of subscription purchases, tokens, and any billing errors that may occur. Your backend servers can use the server-side API to query and update your records and follow up with customers directly, if needed.

Recommendation: バックエンドサーバを使っているならサブスクリプションの購入, Token, 発生する可能性のあるエラーを通知するようビジネスロジックを組み込んでおく.
バックエンドサーバはサーバサイドAPIを使用して直接ユーザに問い合わせたり, 情報更新したり, 追跡することができる.

Free trials

In the Developer Console, you can set up a free trial period that lets users try your subscription content before buying it. The trial period runs for the period of time that you set and then automatically converts to a full subscription managed according to the subscription’s billing interval and price.

To take advantage of a free trial, a user must “purchase” the full subscription through the standard In-app Billing flow, providing a valid form of payment to use for billing and completing the normal purchase transaction. However, the user is not charged any money, since the initial period corresponds to the free trial. Instead, Google Play records a transaction of $0.00 and the subscription is marked as purchased for the duration of the trial period or until cancellation. When the transaction is complete, Google Play notifies users by email that they have purchased a subscription that includes a free trial period and that the initial charge was $0.00.

Developer Consoleではコンテンツ購入前に無料のお試し期間を設定できる. お試し期間が満了すると, 自動で有料のサブスクリプションに移行される.

お試し期間を利用するには, フルサブスクリプションを通常の購入フローを通して”購入”しなければならない.
ただし, 試用期間内であれば料金を請求されずGoogle Playは0ドルの取引を記録して試用期間であることをマークする.
取引が完了するとGoogle Playはユーザに購入済みのサブスリクプションがある旨とそれが無料期間中であり取引0ドルであることを通知する.

When the trial period ends, Google Play automatically initiates billing against the credit card that the user provided during the initial purchase, at the amount set for the full subscription, and continuing at the subscription interval. If necessary, the user can cancel the subscription at any time during the trial period. In this case, Google Play marks the subscription as expired immediately, rather than waiting until the end of the trial period. The user has not paid for the trial period and so is not entitled to continued access after cancellation.

お試し期間が終わるとフルサブスクリプションが購入されたとして改めて自動で請求を行う.
必要であればお試し期間をキャンセルすることができるが, キャンセルするとお試し期間は満了となる.
お試し期間にキャンセルすると, それ以降アクセスさせなくする.

You can set up a trial period for a subscription in the Developer Console, without needing to modify or update your APK. Just locate and edit the subscription in your product list, set a valid number of days for the trial (must be 7 days or longer), and publish. You can change the period any time, although note that Google Play does not apply the change to users who have already “purchased” a trial period for the subscription. Only new subscription purchases will use the updated trial period. You can create one free trial period per subscription product.

お試し期間はAPKを更新することなくDeveloper Consoleで設定できる.
商品リストから対象のサブスクリプションを見つけ出し, お試し期間となる日数(期間は7日かそれ以上とすること)を入力し公開する. お試し期間はいつでも変更できる. ただし, すでに購入されているものに対しては変更が適用されない.

Subscription publishing

When you have finished configuring your subscription product details in the Developer Console, you can publish the subscription in the app product list.

Developer Consoleでサブスクリプションの設定が完了したら商品リストに公開できる.

In the product list, you can add subscriptions, in-app products, or both. You can add multiple subscriptions that give access to different content or services, or you can add multiple subscriptions that give access to the same content but for different intervals or different prices, such as for a promotion. For example, a news outlet might decide to offer both monthly and annual subscriptions to the same content, with annual having a discount. You can also offer in-app purchase equivalents for subscription products, to ensure that your content is available to users of older devices that do not support subscriptions.

プロダクトリストにはサブスクリプションかアプリ内商品, または両方を追加できる. 異なるコンテンツまたはサービスとして複数のサブスクリプションを追加するもよし, 同じコンテンツでも異なる価格と支払い間隔を持たせるもよし.
たとえばプロモーションのために, 月額制と年額制の2本を用意して年額の方が割引率を高くするような場合に使える.
また, サブスクリプションをサポートしない古い端末向けにアプリ内課金を使って通常商品を代用することもある.

After you add a subscription or in-app product to the product list, you must publish the product before Google Play can make it available for purchase. Note that you must also publish the app itself before Google Play will make the products available for purchase inside the app.

Important: You can remove the subscription product from the product list offered in your app to prevent users from seeing or purchasing it.

サブスクリプションかアプリ内商品を商品リストに追加した後, Google Playで購入できるようになる前にそれを公開する必要がある.
ただ, アプリ内商品を作成するには事前にアプリを登録しておく必要がある.

Important: サブスクリプションを見えなくしたり購入できなくしたりするために, プロダクトリストからサブスクリプションを削除することができる.

Subscription Cancellation

Users can view the status of all of their subscriptions and cancel them if necessary from the My Apps screen in the Play Store app. Currently, the In-app Billing API does not provide support for programatically canceling subscriptions from inside the purchasing app.

ユーザはPley Storeにあるマイアプリ画面からすべてのサブスクリプションを閲覧, キャンセルできる.
現在, In-app Billing APIはアプリからプログラマブルにサブスクリプションを解除する手段を備えていない.

When the user cancels a subscription, Google Play does not offer a refund for the current billing cycle. Instead, it allows the user to have access to the cancelled subscription until the end of the current billing cycle, at which time it terminates the subscription. For example, if a user purchases a monthly subscription and cancels it on the 15th day of the cycle, Google Play will consider the subscription valid until the end of the 30th day (or other day, depending on the month).

ユーザがサブスクリプションを解除しても, Google Playは払い戻し請求をサポートしていない. 代わりに, 支払ったサブスクリプション期間が満了するまでキャンセル後でもコンテンツにアクセスできる.
(たとえば15日に購読停止しても30日まではアクセスできる)

In some cases, the user may contact you directly to request cancellation of a subscription. In this and similar cases, you can use the server-side API to query and directly cancel the user’s subscription from your servers.

他には販売者に購読停止のリクエストを直接連絡する方法やサーバサイドAPIを使用してサーバから直接購読停止させることもできる

Important: In all cases, you must continue to offer the content that your subscribers have purchased through their subscriptions, for as long any users are able to access it. That is, you must not remove any subscriber’s content while any user still has an active subscription to it, even if that subscription will terminate at the end of the current billing cycle. Removing content that a subscriber is entitled to access will result in penalties. Please see the policies document for more information.

Important: 全てのケースにおいて, サブスクリプションを購入したユーザがアクセスし得る限りコンテンツを提供し続けること.
コンテンツの削除はアクセス権をもったユーザへペナルティを科すことになる. より多くの情報はpolicies documentを参照.

App uninstallation

When the user uninstalls an app that includes purchased subscriptions, the Play Store app will notify the user that there are active subscriptions. If the user chooses to continue with the uninstallation, the app is removed and the subscriptions remain active and recurring billing continues. The user can return to cancel the associated subscriptions at any time in the My Apps screen of the Play Store app. If the user chooses to cancel the uninstallation, the app and subscriptions remain as they were.

購入済みのサブスクリプションを含んだアプリをアンインストールした場合は, Play Store アプリはユーザに有効なサブスクリプションの存在を伝える. それでもユーザがアンインストールを継続した場合, アプリは削除されサブスクリプションはアクティブなまま残り, 定期支払も継続される.
この後, サブスクリプションを停止したい場合はPlay Storeの”マイアプリ”から行う. アンインストールをキャンセルした場合はアプリもサブスクリプションもそのままの状態で残る.

Refunds

With subscriptions, Google Play does not provide a refund window, so users will need to contact you directly to request a refund.

If you receive requests for refunds, you can use the server-side API to cancel the subscription or verify that it is already cancelled. However, keep in mind that Google Play considers cancelled subscriptions valid until the end of their current billing cycles, so even if you grant a refund and cancel the subscription, the user will still have access to the content.

Important: Partial refunds for canceled subscriptions are not available at this time.

Google Playは払い戻し機能と画面を提供していないので, 必要であれば直接販売者に連絡する必要がある.

払い戻しのリクエストを受けた場合は, サーバサイドAPIを使ってサブスクリプションを停止することができる.
しかし, Google Playは購読停止しても一定期間はユーザにアクセスを許していることに留意すること.

Important サブスクリプションの部分的な払い戻しは現時点でサポートされない.

Payment Processing and Policies

In general, the terms of Google Play allow you to sell in-app subscriptions only through the standard payment processor, Google Wallet. For purchases of any subscription products, the transaction fee is the same as the transaction fee for application purchases (30%).

サブスクリプションはGoogle Walletを通して販売することができる. サブスクリプション購入の手数料はアプリ販売と同じ30%となる.

Apps published on Google Play that are selling subscriptions must use In-app Billing to handle the transaction and may not provide links to a purchase flow outside of the app and Google Play (such as to a web site).

For complete details about terms and policies, see the policies document.

Google Playでアプリを公開してサブスクリプションを販売したならば, In-app Billingを使用すること.
Google Playの外で購入させることはできない.

Subscription order numbers

To help you track transactions relating to a given subscription, Google Wallet provides a base Merchant Order Number for all recurrences of the subscription and denotes each recurring transaction by appending an integer as follows:
12999556515565155651.5565135565155651 (base order number)
12999556515565155651.5565135565155651..0 (initial purchase orderID)
12999556515565155651.5565135565155651..1 (first recurrence orderID)
12999556515565155651.5565135565155651..2 (second recurrence orderID)

Google Walletは全てのサブスクリプションに販売者オーダ番号にインクリメンタルIDを付与して取引の追跡を助けます.
12999556515565155651.5565135565155651 (base order number)
12999556515565155651.5565135565155651..0 (initial purchase orderID)
12999556515565155651.5565135565155651..1 (first recurrence orderID)
12999556515565155651.5565135565155651..2 (second recurrence orderID)

Google Play provides the order number as the value of the orderId field of the INAPP_PURCHASE_DATA JSON field (in V3) or the PURCHASE_STATE_CHANGED intent (in V2).

Google Playが提供するオーダ番号をJSONのIN_APP_PURCHASE_DATAにあるorderIdフィールドから取得できる(Ver.3), Ver.2の場合はIntentのPURCHASE_STATE_CHANGEDとなる.

Purchase Verification Strategies

In a typical scenario, your app verifies the order status for new purchases to ensure that they are valid before granting access to the purchased content.

To verify a purchase, the app passes the purchase token and other details up to your backend servers, which verifies them directly with Google Play using the Purchase Status API. If the backend server determines that the purchase is valid, it notifies the app and grants access to the content.

Keep in mind that users will want the ability to use your app at any time, including when there may be no network connection available. Make sure that your approach to purchase verification accounts for the offline use-case.

通常, コンテンツへのアクセス権を付与する前に, 購入商品の注文内容を検証する.

注文を検証するために, 購入Tokenとその他の詳細な情報をバックエンドサーバに送り, Purchase Status APIを使ってGoogle Playへ直接アクセスする.

忘れてはいけないことに, ユーザはネットワーク接続できない場合がある.
ネットワーク接続ができない状態でもコンテンツが利用できるよう配慮すること.
オフラインでのユースケースを確認すること.

Google Play Android Developer API

Google Play offers an HTTP-based API that lets you remotely query the validity of a specific subscription at any time or cancel a subscription. The API is designed to be used from your backend servers as a way of securely managing subscriptions, as well as extending and integrating subscriptions with other services.

For complete information, see Purchase Status API.

Google Playはサブスクリプションをいつでも検証あるいはキャンセルできるようHTTP-baseのAPIを提供している.
APIはバックエンドサーバから使用されることを想定して安全に設計されている.

より詳しい情報はPurchase Status APIを参照.


License:
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

2014/08/22

Android:In-app Billing Version3

Introduction

AndroidではGoogle Playサービスを利用してアプリ内課金を比較的容易に導入できます.
本稿ではビジネス戦略の1つ”アプリ内課金”にフォーカスしたAndroid Developers | In-app Billing Version 3を翻訳し, In-app Billing Ver.3 APIについて学びます.

In-app Billing Version 3

The In-app Billing Version 3 API makes it easier for you to integrate In-app Billing into your applications. The features in this version include improved synchronous purchase flow, APIs to let you easily track ownership of consumable goods, and local caching of in-app purchase data.

In-app Billing Ver.3 APIを使うことでアプリ内課金の仕組みをアプリに組み込めます.
このバージョンでは, 過去Verから更に改善された購入フロー, 商品所有情報を追跡するAPI, アプリ内課金情報のローカルキャッシュ機能が含まれる.

Product Types

You define your products using the Google Play Developer Console, including product type, SKU, price, description, and so on. For more information, see Administering In-app Billing. The Version 3 API supports managed in-app products and subscriptions.

Google Play Developer Consoleで定義した商品には, 商品種別, SKU, 価格等が含まれる.
より詳細な情報はAdministering In-app Billingを参照.
Ver.3 APIはアプリ内商品の管理と定期購読をサポートする.

Managed In-app Products

Managed in-app products are items that have their ownership information tracked and managed by Google Play. When a user purchases a managed in-app item, Google Play stores the purchase information for each item on a per-user basis. This enables you to later query Google Play at any time to restore the state of the items a specific user has purchased. This information is persistent on the Google Play servers even if the user uninstalls the application or if they change devices.

Google Playはユーザが購入した商品の所有情報を追跡する.
商品を購入すると, ユーザ毎の購入情報が記録される.
これにより, 特定ユーザの購入履歴から商品の所有状態をいつでも復元できる.
この情報はGoogle Playサーバに保管されており, アプリのアンインストールや端末変更でも引き続き利用(復元)できる.

If you are using the Version 3 API, you can also consume managed items within your application. You would typically implement consumption for items that can be purchased multiple times (such as in-game currency, fuel, or magic spells). Once purchased, a managed item cannot be purchased again until you consume the item, by sending a consumption request to Google Play. To learn more about in-app product consumption, see Consuming Items

Ver.3 APIを使用すると, 商品の消費についても管理できる.
商品の消費は複数回購入できる商品(ゲーム内通貨, ポーション, 魔法の書など)で実装されるのが一般的.
一度商品を購入すると, Google Playに消費リクエストを送信して商品を消費するまで同じ商品は購入できなくなる.
商品の消費についてより詳細な情報はConsuming Itemsを参照.

Subscriptions

A subscription is a product type offered in In-app Billing that lets you sell content, services, or features to users from inside your app with recurring monthly or annual billing. You can sell subscriptions to almost any type of digital content, from any type of app or game. To understand how subscriptions work, see In-app Billing Subscriptions.

定期購読はアプリ内のコンテンツ, サービス, または機能を毎月or毎年定期的に購読(課金)させる支払い形態の一種である.
アプリやゲームからデジタルコンテンツを定期購読販売できる.

With the Version 3 API, you can use the same purchase flow for buying subscriptions and retrieving subscription purchase information as with in-app products. For a code example, see Implementing Subscriptions.

Important: Unlike in-app products, subscriptions cannot be consumed.

Ver.3 APIでは定期購読の購入に同じ支払いフローを使用し, アプリ内商品と同じように定期購読の購入履歴から復元できる.
コードのサンプルはImplementing Subscriptionsを参照.

Important: Google Playで管理されない商品や定期購読は対象外.

Purchasing Items

A typical purchase flow with the Version 3 API is as follows:

Ver.3 APIを使用した購入フロー:

The basic sequence for a purchase request.
[The basic sequence for a purchase request.]

  1. Your application sends a isBillingSupported request to Google Play to determine that the target version of the In-app Billing API that you are using is supported.
  2. When your application starts or user logs in, it’s good practice to check with Google Play to determine what items are owned by the user. To query the user’s in-app purchases, send a getPurchases request. If the request is successful, Google Play returns a Bundle containing a list of product IDs of the purchased items, a list of the individual purchase details, and a list of the signatures for the purchases.
  3. Usually, you’ll want to inform the user of the products that are available for purchase. To query the details of the in-app products that you defined in Google Play, your application can send a getSkuDetails request. You must specify a list of product IDs in the query request. If the request is successful, Google Play returns a Bundle containing product details including the product’s price, title, description, and the purchase type.
  4. If an in-app product is not owned by the user, you can initiate a purchase for it. To start a purchase request, your application sends a getBuyIntent request, specifying the product ID of the item to purchase, along with other parameters. You should record the product ID when you create a new in-app product in the Developer Console.
    1. Google Play returns a Bundle that contains a PendingIntent which you application uses to start the checkout UI for the purchase.
    2. Your application launches the pending intent by calling the startIntentSenderForResult method.
    3. When the checkout flow finishes (that is, the user successfully purchases the item or cancels the purchase), Google Play sends a response Intent to your onActivityResult method. The result code of the onActivityResult has a result code that indicates whether the purchase was successful or canceled. The response Intent contains information about the purchased item, including a purchaseToken String that is generated by Google Play to uniquely identify this purchase transaction. The Intent also contains the signature of the purchase, signed with your private developer key.

To learn more about the Version 3 API calls and server responses, see In-app Billing Reference.

  1. 使用するIn-app Billing APIのバージョンがサポートされているかGoogle Playに問い合わせる(isBillingSupported)
  2. ユーザの購入情報を取得(getPurchases)する.
    購入情報はBundleに詰めて返され, 商品ID, 購入詳細, 購入署名それぞれがリストで返される.
    購入情報を取得するタイミングとしてアプリ起動時やログイン時を推奨する.
  3. ユーザに商品を訴求するために商品詳細を取得(getSkuDetails)する.
    取得リクエストには商品IDを指定する.
    商品詳細はBundleに詰めて返され, 商品価格, タイトル, 説明, 購入種別が含まれる.
  4. ユーザが商品を所有していない場合に購入フローを開始(getBuyIntent)できる. パラメータには商品IDを指定する. Developer Consoleで作成した商品のIDは記録しておくこと.
    1. getBuyIntentで返却されるBundleには購入手続きを開始するためのPendingIntentが含まれている.
    2. アプリはstartIntentSenderForResultメソッドを呼び出してIntent起動する.
    3. 支払いフローが完了(購入完了 or 購入キャンセル)するとGoogle Playは購入結果をIntentに詰めてonActivityResultメソッドを呼ぶ.
      onActivityResultの結果コードは購入の成功/失敗を示す. Intentには購入情報(商品情報や購入トランザクションを一意に識別するpurchaseTokenの文字列)が含まれる.
      Intentには開発者の秘密鍵で署名された購入証明書も含まれる.

Ver.3 APIとサーバレスポンスについてのより詳細な情報はIn-app Billing Referenceを参照.

Consuming In-app Products

You can use the consumption mechanism to track the user’s ownership of in-app products.

In Version 3, all in-app products are managed. This means that the user’s ownership of all in-app item purchases is maintained by Google Play, and your application can query the user’s purchase information when needed. When the user successfully purchases an in-app product, that purchase is recorded in Google Play. Once an in-app product is purchased, it is considered to be “owned”. In-app products in the “owned” state cannot be purchased from Google Play. You must send a consumption request for the “owned” in-app product before Google Play makes it available for purchase again. Consuming the in-app product reverts it to the “unowned” state, and discards the previous purchase data.

ユーザの商品所持状態を追跡するために, 消費メカニズムを使用する.

Ver.3ではGoogle Playによって全ての商品や購入情報が管理されており, 必要に応じてこれらの情報を問い合わせることができる. ユーザの購入情報はGoogle Playに記録される.
一度商品を購入し”所持状態”になると, 消費リクエストをGoogle Playに送信するまで同じ商品を購入することはできない. 商品が消費されると”未所持状態”に戻り, 以前の購入データは破棄される.

The basic sequence for a consumption request.
[The basic sequence for a consumption request.]

To retrieve the list of product’s owned by the user, your application sends a getPurchases call to Google Play. Your application can make a consumption request by sending a consumePurchase call. In the request argument, you must specify the in-app product’s unique purchaseToken String that you obtained from Google Play when it was purchased. Google Play returns a status code indicating if the consumption was recorded successfully.

ユーザが所持する商品リストを取得するにはgetPurchasesメソッドを, 商品を消費するにはconsumePurchaseメソッドを呼び出す. メソッド引数には商品の購入完了時にGoogle Playから払い出される商品の識別文字列purchaseTokenを指定する.

Non-consumable and Consumable In-app Products

It’s up to you to decide if you want to handle your in-app products as non-consumable or consumable items.

商品種別を非消費系とするか消費系とするかは開発者が自由に設定できる.

Non-consumable Items
Typically, you would not implement consumption for in-app products that can only be purchased once in your application and provide a permanent benefit. Once purchased, these items will be permanently associated to the user’s Google account. An example of a non-consumable in-app product is a premium upgrade or a level pack.
非消費系の商品
非消費系の商品は, 一度購入すれば永続的に効果が持続するため通常選択されない.
一度購入された非消費系の商品は購入ユーザのGoogleアカウントに紐づく. 実装されるケースとしてはアプリのプレミアムアップグレードやレベルパックのような商品に適用できる.
Consumable items
In contrast, you can implement consumption for items that can be made available for purchase multiple times. Typically, these items provide certain temporary effects. For example, the user’s in-game character might gain life points or gain extra gold coins in their inventory. Dispensing the benefits or effects of the purchased item in your application is called provisioning the in-app product. You are responsible for controlling and tracking how in-app products are provisioned to the users.
Important: Before provisioning the consumable in-app product in your application, you must send a consumption request to Google Play and receive a successful response indicating that the consumption was recorded.
消費系の商品
非消費系の商品とは対照的に, 消費系の商品は同じ商品を複数回購入できるように消費を実装します.
消費系商品の効果は通常一時的なものになる. 例えば, ゲームのポーションや課金によるゲーム内通貨の追加など.
購入商品の利益や効果を分配することを商品の供給と呼ぶ. 開発者は商品がユーザに供給されているかを追跡し制御する責務を負う.
Important: アプリで消費系商品を供給する前に, 必ず消費リクエストをGoogle Playに投げて消費リクエストの成功(消費が正しく記録されたことも意味する)を受け取ること.

Managing consumable purchases in your application

Here is the basic flow for purchasing a consumable in-app product:

  1. Launch a purchase flow with a getBuyIntent call
  2. Get a response Bundle from Google Play indicating if the purchase completed successfully.
  3. If the purchase was successful, consume the purchase by making a consumePurchase call.
  4. Get a response code from Google Play indicating if the consumption completed successfully.
  5. If the consumption was successful, provision the product in your application.

消費系商品を購入する基本フロー:

  1. getBuyIntentを呼び出し, 購入基本フローを開始する
  2. 購入が成功するとGoogle Playからレスポンスを受け取りBundleを取得する
  3. 購入が完了したらconsumePurchaseで商品を消費する
  4. 消費が完了したかどうかを示すレスポンスコードを取得する
  5. 消費が成功したならば, 商品を供給する

Subsequently, when the user starts up or logs in to your application, you should check if the user owns any outstanding consumable in-app products; if so, make sure to consume and provision those items. Here’s the recommended application startup flow if you implement consumable in-app products in your application:

続いて, アプリケーションを起動するかログインするかの時, 消費していない商品があるならこれを消費, 供給する.
次はアプリ起動時に推奨される消費のフローである:

  1. Send a getPurchases request to query the owned in-app products for the user.
  2. If there are any consumable in-app products, consume the items by calling consumePurchase. This step is necessary because the application might have completed the purchase order for the consumable item, but stopped or got disconnected before the application had the chance to send a consumption request.
  3. Get a response code from Google Play indicating if the consumption completed successfully.
  4. If the consumption was successful, provision the product in your application.
  1. getPurchasesリクエストを送り, ユーザが所有する商品を問い合わせる
  2. 消費系の商品があったならば, consumePurchaseで商品を消費する. このステップは商品を購入したにも関わらず消費処理が未完了となっている可能性に備えて必要となる.
  3. Google Playから消費リクエストの成功レスポンスを受け取る
  4. 消費リクエストが成功していたならば商品の共有を行う

Local Caching

Because the Google Play client now caches In-app Billing information locally on the device, you can use the Version 3 API to query for this information more frequently, for example through a getPurchases call. Unlike with previous versions of the API, many Version 3 API calls will be serviced through cache lookups instead of through a network connection to Google Play, which significantly speeds up the API’s response time.

Ver.3 APIを使用している場合, Google Playクライアントはアプリ内課金の情報をデバイスローカルにキャッシュしている. これにより, getPurchasesなど情報の問い合わせ速度がネットワーク接続を必要としないため, 過去APIバージョンより格段に応答速度が改善し, 問い合わせの頻度を多くすることを可能とする.


License:
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

2014/08/20

Android:Google Play In-app Billing

Table of contents

Introduction

AndroidではGoogle Playサービスを利用してアプリ内課金を比較的容易に導入できます.
本稿ではビジネス戦略の1つ”アプリ内課金”にフォーカスしたAndroid Developers | Google Play In-app Billingを翻訳し, サービス概略について学びます.

Google Play In-app Billing

In-app Billing is a Google Play service that lets you sell digital content from inside your applications. You can use the service to sell a wide range of content, including downloadable content such as media files or photos, virtual content such as game levels or potions, premium services and features, and more. You can use In-app Billing to sell products as

  • Standard in-app products (one-time billing), or
  • Subscriptions, (recurring, automated billing)

In-app BillingはGoogle Playのサービスを通して, アプリ内部でデジタルコンテンツを販売できるアプリ内課金サービスである.
音楽,動画,写真といったダウンロード可能なコンテンツ, ゲームのレベルやポーションといった仮想コンテンツ, プレミアムサービスや特別な機能など販売できるコンテンツは多岐に渡る.
アプリ内課金サービスでの販売形態には次の2点がある.

-スポット課金(その場限りの請求, こちらが標準的である)
-定期購読(繰り返し自動課金)

When you use the in-app billing service to sell an item, whether it’s an in-app product or a subscription, Google Play handles all checkout details so your application never has to directly process any financial transactions. Google Play uses the same checkout backend service as is used for application purchases, so your users experience a consistent and familiar purchase flow.

アプリ内課金サービスを使って商品を売る時, スポット課金か定期購読どちらでもGoogle Playはアプリが直接決済処理に関わる必要が無いよう肩代わりする.
決済フローについてはアプリ購入時のそれと同じものを使用するため, 馴染みあるユーザ体験を提供する.

Any application that you publish through Google Play can implement In-app Billing. No special account or registration is required other than a Google Play Developer Console account and a Google Wallet merchant account.

Google Playで公開されるアプリのほとんどでアプリ内課金の実装が可能である.
アプリ内課金の実装に, Google Play Developer ConsoleアカウントとGoogle Wallet merchantアカウント以外のアカウントは不要.

To help you integrate in-app billing into your application, the Android SDK provides a sample application that demonstrates how to sell standard in-app products and subscriptions from inside an app.

アプリにアプリ内課金を統合するための助けとして, スポット課金と定期購読の方法をデモンストレーションするサンプルアプリをAndroid SDKで提供している.

In-app Billing Overview

This documentation describes the fundamental In-app Billing components and features that you need to understand in order to add In-app Billing features into your application.

本章はアプリ内課金を導入するにあたって理解しておく必要のある基本的なコンポーネントと機能について記載する.

Note: Ensure that you comply with applicable laws in the countries where you distribute apps. For example, in EU countries, laws based on the Unfair Commercial Practices Directive prohibit direct exhortations to children to buy advertised products or to persuade their parents or other adults to buy advertised products for them. See the position of the EU consumer protection authorities for more information on this and other topics.

Note:
アプリを配布する際には, 必ずその国の法律に従うこと.
例えば, EU諸国では消費者に対する商業上の不公正行為に関する消費者保護法Unfair Commercial Practices Directive(UCPD)を採用しており, 子供を対象とした広告や, 親(他の大人含め)を説得させて購入させる(押し売りやミスリーディングを誘う)ような行為は禁止されている.
これに関するより詳細な情報はposition of the EU consumer protection authoritiesを参照.

In-app Billing API

Your application accesses the In-app Billing service using an API that is exposed by the Google Play app that is installed on the device. The Google Play app then conveys billing requests and responses between your application and the Google Play server. In practice, your application never directly communicates with the Google Play server. Instead, your application sends billing requests to the Google Play application over interprocess communication (IPC) and receives responses from the Google Play app. Your application does not manage any network connections between itself and the Google Play server.

アプリ内課金サービスへのアクセスは端末にインストールされているGoogle PlayのAPIを使用する. アプリとGoogle Playサーバ間の決済処理はGoogle Playアプリが橋渡しを担うため, アプリが直接Google Playサーバと直接通信する必要がなく, ネットワークコネクションを管理する必要がない.
アプリとGoogle Playアプリはプロセス間通信(IPC)で決済リクエストを送信し, レスポンスを受信する.

In-app Billing can be implemented only in applications that you publish through Google Play. To complete in-app purchase requests, the Google Play app must be able to access the Google Play server over the network.

アプリ内課金はGoogle Playで公開されているアプリでのみ使用できる.
商品の購入は, Google PlayアプリがGoogle Playサーバとの通信をもって完結する.

In-app billing Version 3 is the latest version, and maintains very broad compatibility across the range of Android devices. In-app Billing Version 3 is supported on devices running Android 2.2 or higher that have the latest version of the Google Play store installed (a vast majority of active devices).

In-app Billing Ver.3は最新のバージョンで, 殆どのAndroidデバイスに互換性を持つ.
Ver.3はAndroid2.2以上, Google Play Ver.3.9.16以上で動作する(a vast majority of active devices).

Version 3 features

  • Requests are sent through a streamlined API that allows you to easily request product details from Google Play, order in-app products, and quickly restore items based on users’ product ownership
  • Order information is synchronously propagated to the device on purchase completion
  • All purchases are “managed” (that is, Google Play keeps track of the user’s ownership of in-app products). The user cannot own multiple copies of an in-app item; only one copy can be owned at any point in time
  • Purchased items can be consumed. When consumed, the item reverts to the “unowned” state and can be purchased again from Google Play
  • Provides support for subscriptions

For details about other versions of In-app Billing, see the Version Notes.

  • Ver.3はGoogle Playにある商品情報のリクエスト, アプリ内商品の注文や, 商品所有情報からアイテムリストを復元するのに最適化されたAPIを提供する.
  • 注文情報は購入完了時に各端末と同期される
  • 購入情報は全て管理されている(つまりGoogle Playはユーザのアプリ内商品の所有状態を追跡している). ユーザは同じ商品のコピーを複数持つことはできず, 1つしか所持できない仕組みである.
  • 購入した商品は消費できる. 商品を消費すると所有状態ではなくなり, 再び商品を購入できるようになる.
  • Ver.3は定期購読をサポートする

In-app Products

In-app products are the digital goods that you offer for sale from inside your application to users. Examples of digital goods includes in-game currency, application feature upgrades that enhance the user experience, and new content for your application.

アプリ内商品はアプリ内で提供されるデジタル商品である.
例えばゲーム内通貨や, アプリ機能を拡張するアップグレードや, アプリ向け新コンテンツなどがこれに含まれる.

You can use In-app Billing to sell only digital content. You cannot use In-app Billing to sell physical goods, personal services, or anything that requires physical delivery. Unlike with priced applications, once the user has purchased an in-app product there is no refund window.

アプリ内課金はデジタルコンテンツにのみ対応し, 物理的な物の売買や配送, 個人サービスについては扱わない. また, アプリ購入の時とは異なり商品の返品画面は用意されない.

Google Play does not provide any form of content delivery. You are responsible for delivering the digital content that you sell in your applications. In-app products are always explicitly associated with one and only one app. That is, one application cannot purchase an in-app product published for another app, even if they are from the same developer.

Google Playは商品について, 任意の配信方法を許可していない. 商品はアプリ内で販売する必要がある. また, アプリ内商品はアプリと対で管理される.
そのため, たとえ同じ開発者のアプリであっても商品(情報含め)を共有することはできない.

Product types

In-app Billing supports different product types to give you flexibility in how you monetize your application. In all cases, you define your products using the Google Play Developer Console.

アプリ内課金は異なる種類の商品に対応し, アプリのマネタイズに柔軟に対応できる.
全てのケースで, 全ての商品をGoogle Play Developer Consoleで定義する.

You can specify these types of products for your In-app Billing application — managed in-app products and subscriptions. Google Play handles and tracks ownership for in-app products and subscriptions on your application on a per user account basis. Learn more about the product types supported by In-app Billing Version 3.

課金アプリで商品の種類としてアプリ内商品定期購読品かを指定できる.
Google Playはアプリのユーザアカウント毎に双方を処理し, 所有状態を追跡する.

Google Play Developer Console

The Developer Console is where you can publish your In-app Billing application, and manage the various in-app products that are available for purchase from your application.

Developer Consoleはアプリを公開し, アプリで購入可能な商品を管理する場所である.

You can create a product list of digital goods that are associated with your application, including items for one-time purchase and recurring subscriptions. For each item, you can define information such as the item’s unique product ID (also called its SKU), product type, pricing, description, and how Google Play should handle and track purchases for that product.

アプリに紐づくスポット購入と定期購読されるデジタル商品のプロダクトリストを作成できる. どちらも, 商品のユニーク商品ID(SKUと呼ばれる), 商品種別, 価格, 説明を定義し, Google Playにどのように扱わせて, 商品購入を追跡させるかを定義できる.
(SKU: Stock Keeping Unit. 最小管理単位)

You can also create test accounts to authorize access for testing applications that are unpublished.

アプリをテストするために, テストアカウントを作成し公開前のアプリでテストすることができる.

To learn how to use the Developer Console to configure your in-app products and product list, see Administering In-app Billing.

Developer Consoleでアプリ内商品とプロダクトリストを設定する方法についてはAdministering In-app Billingを参照.

Google Play Purchase Flow

Google Play uses the same checkout backend service as is used for application purchases, so your users experience a consistent and familiar purchase flow.

Google Playの決済フローはアプリ購入時のそれと同じものを使用するため, 馴染みあるユーザ体験を提供する.

Important: You must have a Google Wallet merchant account to use the In-app Billing service on Google Play.

重要:
Google Playでアプリ内課金サービスを利用するにはGoogle Wallet merchantアカウントが必要になる.

To initiate a purchase, your application sends a billing request for a specific in-app product. Google Play then handles all of the checkout details for the transaction, including requesting and validating the form of payment and processing the financial transaction.

決済を始めるにあたり, アプリは特定商品の決済リクエストを送信する.
Google Playは決済リクエスト, 決済フォームのバリデート, 金融決済処理を含む全ての決済処理をハンドリングする.

When the checkout process is complete, Google Play sends your application the purchase details, such as the order number, the order date and time, and the price paid. At no point does your application have to handle any financial transactions; that role is provided by Google Play.

決済処理が完了した時, Google Playは注文番号, 注文日時, 支払い金額といった決済情報の詳細をアプリに通知する.
この決済処理の中でアプリが意識するべき所ははく, Google Playが全てを肩代わりする.

Sample Application

To help you integrate In-app Billing into your application, the Android SDK provides a sample application that demonstrates how to sell in-app products and subscriptions from inside an app.

アプリにアプリ内課金を統合するための助けとして, スポット課金と定期購読の方法をデモンストレーションするサンプルアプリをAndroid SDKで提供している.

The TrivialDrive sample for the Version 3 API sample shows how to use the In-app Billing Version 3 API to implement in-app product and subscription purchases for a driving game. The application demonstrates how to send In-app Billing requests, and handle synchronous responses from Google Play. The application also shows how to record item consumption with the API. The Version 3 sample includes convenience classes for processing In-app Billing operations as well as perform automatic signature verification.

TrivialDrive sample for the Version 3 APIサンプルはIn-app Billing Version3 APIを使用し, ドライビングゲームを通してスポット課金と定期購読の決済方法を紹介する.
また, Google Playからの同期レスポンスの捌き方について実演する.
サンプルはAPIで商品の消費がどのように記録されるかも示す.
Ver.3のサンプルは課金処理のための便利クラスと自動署名検証機能も持っている.

Recommendation: Make sure to obfuscate the code in your application before you publish it. For more information, see Security and Design.

Recommendation: アプリを公開する際にはソースコードを難読化すること.
より詳細な情報はSecurity and Designを参照.

Migration Considerations

If you have an existing In-app Billing implementation that uses Version 2 or earlier, it is strongly recommended that you migrate to In-app Billing Version 3 at your earliest convenience.

もしVer.2でアプリ課金を実装しているものが既にあるならIn-app Billing Version 3への移行を強く推奨する.

If you have published apps selling in-app products, note that:

もし, すでにアプリ内商品を販売している場合は, 次のことに留意する:

  • Managed items and subscriptions that you have previously defined in the Developer Console will work with Version 3 as before.
  • Unmanaged items that you have defined for existing applications will be treated as managed products if you make a purchase request for these items using the Version 3 API. You do not need to create a new product entry in Developer Console for these items, and you can use the same product IDs to purchase these items. They will still continue to be treated as unmanaged items if you make a purchase request for them using the Version 2 or earlier API.
  • Ver.2の頃, Developer Consoleで定義した商品や定期購読はVer.3でも同じように扱われる
  • 既にあるアプリで定義された管理されていない商品は, Ver.3のAPIを使用すると管理された商品として扱われる. これらのアイテムをDeveloper Consoleで新たに作成する必要はなく, 同じ商品IDを使ってこれらを購入することができる. これらの商品はVer.2(またはそれ以前)のAPIで購入リクエストを作成する際は, 引き続き管理されていない商品として扱われる.

License:
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.