Android:Google Play In-app Billing

Introduction
-----------------------------------------------------------------------------
AndroidではGoogle Playサービスを利用してアプリ内課金を比較的容易に導入できます.  
本稿ではビジネス戦略の1つ"アプリ内課金"にフォーカスした[Android Developers | Google Play In-app Billing](http://developer.android.com/google/play/billing/index.html)を翻訳し, サービス概略について学びます.  

Blog:[Yukiの枝折 Android:Google Play In-app Billing](http://yuki312.blogspot.jp/2014/08/androidgoogle-play-in-app-billing.html)

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で提供している. 

### New in In-App Billing

> - **Google Play Developer API**— The [Google Play Developer API][st1] allows you to perform a number of publishing and app-management tasks. It includes the functionality previously known as the _Purchase Status API_.
> - **In-app Billing Version 3**— The [latest version][st2] of In-app Billing features a synchronous API that is easier to implement and lets you manage in-app products and subscriptions more effectively.
> - **Subscriptions now supported in Version 3**— You can query and launch purchase flows for subscription items using the V3 API.
> - **Free trials**— You can now offer users a configurable [free trial period][st3] for your in-app subscriptions. You can set up trials with a simple change in the Developer Console—no change to your app code is needed.


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][ov1] 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][ov2] for more information on this and other topics.

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

### 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][ov3] of active devices).

In-app Billing Ver.3は最新のバージョンで, 殆どのAndroidデバイスに互換性を持つ.  
Ver.3はAndroid2.2以上, Google Play Ver.3.9.16以上で動作する([a vast majority][ov3] 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][ov4]
> 
> For details about other versions of In-app Billing, see the [Version Notes][ov5].

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

### 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][ov6].

課金アプリで商品の種類として_アプリ内商品_か_定期購読品_かを指定できる. 
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][ov7].

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

### 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][ov8] 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][ov8]サンプルは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][ov9].

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

### 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][ov10] at your earliest convenience.

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

> 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で購入リクエストを作成する際は, 引き続き管理されていない商品として扱われる. 


[ov1]: http://ec.europa.eu/justice/consumer-marketing/unfair-trade/unfair-practices/    "Unfair Commercial Practices Directive"
[ov2]: http://ec.europa.eu/consumers/enforcement/docs/common_position_on_online_games_en.pdf    "position of the EU consumer protection authorities"
[ov3]: http://developer.android.com/about/dashboards/index.html "a vast majority"
[ov4]: http://developer.android.com/google/play/billing/billing_subscriptions.html  "subscriptions"
[ov5]: http://developer.android.com/google/play/billing/versions.html   "Version Notes"
[ov6]: http://developer.android.com/google/play/billing/api.html#producttypes   "Learn more about the product types supported by In-app Billing Version 3"
[ov7]: http://developer.android.com/google/play/billing/billing_admin.html  "Administering In-app Billing"
[ov8]: http://developer.android.com/training/in-app-billing/preparing-iab-app.html#GetSample    "TrivialDrive sample for the Version 3 API"
[ov9]: http://developer.android.com/google/play/billing/billing_best_practices.html "Security and Design"
[ov10]: http://developer.android.com/google/play/billing/api.html   "In-app Billing Version 3"

---

> **License:**
>Portions of this page are modifications based on work created and [shared by the Android Open Source Project](http://code.google.com/policies.html) and used according to terms described in the [Creative Commons 2.5 Attribution License](http://creativecommons.org/licenses/by/2.5/).  

[blg0]: http://firespeed.org/diary.php?diary=kenz-1617  "Google Play In-app Billing （アプリ内課金） | Firespeed"
[blg1]: http://eggdev.mobaegg.com/search/label/In-App%20Billing%20v3    "EGG 開発ブログ | In-app Billing Version3 翻訳"
[blg2]: http://memopct.blogspot.jp/2013/05/google-play-in-app-billingoverview.html  "Google Play In-app Billingを訳してみる「Overview」 | システム・プログラム関連メモ"