Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62bd2319 authored by quddusc's avatar quddusc Committed by Android Git Automerger
Browse files

am 38b6d7a1: Merge "docs: Updated In-app Billing docs to support subscriptions...

am 38b6d7a1: Merge "docs: Updated In-app Billing docs to support subscriptions for V3." into jb-mr1-dev

# Via Android (Google) Code Review (1) and quddusc (1)
* commit '38b6d7a1':
  docs: Updated In-app Billing docs to support subscriptions for V3.
parents 6978d04b 38b6d7a1
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -80,6 +80,9 @@
              <span class="en">Reference</span></a></li>
              </ul>
      </li>
      <li><a href="<?cs var:toroot?>google/play/billing/billing_subscriptions.html">
              <span class="en">Subscriptions</span></a>
      </li>
      <li><a href="<?cs var:toroot?>google/play/billing/billing_best_practices.html">
              <span class="en">Security and Design</span></a>
      </li>
+35 −14
Original line number Diff line number Diff line
@@ -11,12 +11,13 @@ parent.link=index.html
    <li><a href="#producttypes">Product Types</a>
       <ol>
       <li><a href="#managed">Managed In-app Products</a><li>
       <li><a href="#subs">Subscriptions</a><li>
       </ol>
    </li>
    <li><a href="#purchase">Purchasing Items</a></li>
    <li><a href="#consume">Consuming Items</a>
    <li><a href="#consume">Consuming In-app Products</a>
       <ol>
       <li><a href="#consumetypes">Non-consumable and Consumable Items</a><li>
       <li><a href="#consumetypes">Non-consumable and Consumable In-app Products</a><li>
       <li><a href="#managingconsumables">Managing Consumable Purchases</a><li>
       </ol>
    </li>
@@ -40,11 +41,22 @@ parent.link=index.html

<h2 id="producttypes">Product Types</h2>
<p>You define your products using the Google Play Developer Console, including product type, SKU, price, description, and so on. For more information, see <a
href="{@docRoot}google/play/billing/billing_admin.html">Administering In-app Billing</a>. The Version 3 API only supports the managed in-app product type.</p>
href="{@docRoot}google/play/billing/billing_admin.html">Administering In-app Billing</a>. The Version 3 API supports managed in-app products and subscriptions.</p>
<h3 id="managed">Managed In-app Products</h3>
<p>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.</p>
<p>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 <a href="#consume">Consuming Items</a></p>

<h3 id="subs">Subscriptions</h3>
<p>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 <a href="{@docRoot}google/play/billing/billing_subscriptions.html">In-app Billing Subscriptions</a>.</p>
<p>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 <a href="{@docRoot}google/play/billing/billing_integrate.html#Subs">Implementing Subscriptions</a>.</p>
<p class="caution"><strong>Important</strong>: Unlike in-app products, 
subscriptions cannot be consumed.</p>

<h2 id="purchase">Purchasing Items</h2>

@@ -72,29 +84,38 @@ href="{@docRoot}google/play/billing/billing_admin.html">Administering In-app Bil
</p>
<p>To learn more about the Version 3 API calls and server responses, see <a href="{@docRoot}google/play/billing/billing_reference.html">In-app Billing Reference</a>.</p>

<h2 id="consume">Consuming Items</h2>
<p>You can use the consumption mechanism to track the user's ownership of in-app products.</p>
<p>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 item, that purchase is recorded in Google Play. Once an item is purchased, it is considered to be "owned". Items in the "owned" state cannot be purchased from Google Play. You must send a consumption request for the "owned" item before Google Play makes it available for purchase again. Consuming the item reverts it to the "unowned" state, and discards the previous purchase data.</p>
<h2 id="consume">Consuming In-app Products</h2>
<p>You can use the consumption mechanism to track the user's ownership of in-app 
products.</p>
<p>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.</p>
<div class="figure" style="width:420px">
<img src="{@docRoot}images/in-app-billing/v3/iab_v3_consumption_flow.png" id="figure2" height="300"/>
<p class="img-caption">
  <strong>Figure 2.</strong> The basic sequence for a consumption request.
</p>
</div>
<p>To retrieve the list of product's owned by the user, your application sends a {@code getPurchases} call to Google Play. Your application can make a consumption request by sending a {@code consumePurchase} call. In the request argument, you must specify the item's unique {@code 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.</p>
<p>To retrieve the list of product's owned by the user, your application sends a {@code getPurchases} call to Google Play. Your application can make a consumption request by sending a {@code consumePurchase} call. In the request argument, you must specify the in-app product's unique {@code 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.</p>

<h3 id="consumetypes">Non-consumable and Consumable Items</h3>
<h3 id="consumetypes">Non-consumable and Consumable In-app Products</h3>
<p>It's up to you to decide if you want to handle your in-app products as non-consumable or consumable items.</p>
<dl>
<dt>Non-consumable Items</dt>
<dd>Typically, you would not implement consumption for items 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 item is a premium upgrade or a level pack.</dd>
<dd>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.</dd>
<dt>Consumable items</dt>
<dd>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 <em>provisioning</em> the in-app product. You are responsible for controlling and tracking how in-app products are provisioned to the users.
<p class="note"><strong>Important:</strong> Before provisioning the consumable item in your application, you must send a consumption request to Google Play and receive a successful response indicating that the consumption was recorded.</p>
<p class="note"><strong>Important:</strong> 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.</p>
</dd>
</dl>
<h3 id="managingconsumables">Managing consumable purchases in your application</h3>
<p>Here is the basic flow for purchasing a consumable item:</p>
<p>Here is the basic flow for purchasing a consumable in-app product:</p>
<ol>
<li>Launch a purchase flow with a {@code getBuyIntent} call</li>
<li>Get a response {@code Bundle}from Google Play indicating if the purchase completed successfully.</li>
@@ -102,10 +123,10 @@ href="{@docRoot}google/play/billing/billing_admin.html">Administering In-app Bil
<li>Get a response code from Google Play indicating if the consumption completed successfully.</li>
<li>If the consumption was successful, provision the product in your application.</li>
</ol>
<p>Subsequently, when the user starts up or logs in to your application, you should check if the user owns any outstanding consumable items; if so, make sure to consume and provision those items. Here's the recommended application startup flow if you implement consumable items in your application:</p>
<p>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:</p>
<ol>
<li>Send a {@code getPurchases} request to query the owned items for the user.</li>
<li>If there are any consumable items, consume the items by calling {@code 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.</li>
<li>Send a {@code getPurchases} request to query the owned in-app products for the user.</li>
<li>If there are any consumable in-app products, consume the items by calling {@code 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.</li>
<li>Get a response code from Google Play indicating if the consumption completed successfully.</li>
<li>If the consumption was successful, provision the product in your application.</li>
</ol>
+50 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ parent.link=index.html
       <li><a href="#Purchase">Purchasing an Item</a></li>
       <li><a href="#QueryPurchases">Querying Purchased Items</a></li>
       <li><a href="#Consume">Consuming a Purchase</a><li>
       <li><a href="#Subs">Implementing Subscriptions</a><li>
       </ol>
    </li>
  </ol>
@@ -176,7 +177,7 @@ if (response == 0) {
</pre>

<h3 id="Purchase">Purchasing an Item</h3>
<p>To start a purchase request from your app, call the {@code getBuyIntent} method on the In-app Billing service. Pass in to the method the In-app Billing API version (“3”), the package name of your calling app, the product ID for the item to purchase, the purchase type (“inapp”), and a {@code developerPayload} String. The {@code developerPayload} String is used to  specify any additional arguments that you want Google Play to send back along with the purchase information.</p>
<p>To start a purchase request from your app, call the {@code getBuyIntent} method on the In-app Billing service. Pass in to the method the In-app Billing API version (“3”), the package name of your calling app, the product ID for the item to purchase, the purchase type (“inapp” or "subs"), and a {@code developerPayload} String. The {@code developerPayload} String is used to  specify any additional arguments that you want Google Play to send back along with the purchase information.</p>

<pre>
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
@@ -238,7 +239,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
<p class="note"><strong>Security Recommendation:</strong> When you send a purchase request, create a String token that uniquely identifies this purchase request and include this token in the {@code developerPayload}.You can use a randomly generated string as the token. When you receive the purchase response from Google Play, make sure to check the returned data signature, the {@code orderId}, and the {@code developerPayload} String. For added security, you should perform the checking on your own secure server. Make sure to verify that the {@code orderId} is a unique value that you have not previously processed, and the {@code developerPayload} String matches the token that you sent previously with the purchase request.</p>

<h3 id="QueryPurchases">Querying for Purchased Items</h3>
<p>To retrieve information about purchases made by a user from your app, call the {@code getPurchases} method on the In-app Billing Version 3 service. Pass in to the method the In-app Billing API version (“3”), the package name of your calling app, and the purchase type (“inapp”).</p>
<p>To retrieve information about purchases made by a user from your app, call the {@code getPurchases} method on the In-app Billing Version 3 service. Pass in to the method the In-app Billing API version (“3”), the package name of your calling app, and the purchase type (“inapp” or "subs").</p>
<pre>
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
</pre>
@@ -273,8 +274,26 @@ if (response == 0) {
</pre>

<h3 id="Consume">Consuming a Purchase</h3>
<p>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 from Google Play. 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 equipment). You would typically not want to implement consumption for products that are purchased once and provide a permanent effect (for example, a premium upgrade).</p>
<p>To record a purchase consumption, send the {@code consumePurchase} method to the In-app Billing service and pass in the {@code purchaseToken} String value that identifies the purchase to be removed. The {@code purchaseToken} is part of the data returned in the {@code INAPP_PURCHASE_DATA} String by the Google Play service following a successful purchase request. In this example, you are recording the consumption of a product that is identified with the {@code purchaseToken} in the {@code token} variable.</p>
<p>You can use the In-app Billing Version 3 API to track the ownership of 
purchased in-app products in Google Play. Once an in-app product is purchased, 
it is considered to be "owned" and cannot be purchased from Google Play. You 
must send a consumption request for the in-app product before Google Play makes 
it available for purchase again.</p>
<p class="caution"><strong>Important</strong>: Managed in-app products are 
consumable, but subscriptions are not.</p>
<p>How you use the consumption mechanism in your app is up to you. Typically, 
you would implement consumption for in-app products with temporary benefits that 
users may want to purchase multiple times (for example, in-game currency or 
equipment). You would typically not want to implement consumption for in-app 
products that are purchased once and provide a permanent effect (for example, 
a premium upgrade).</p>
<p>To record a purchase consumption, send the {@code consumePurchase} method to 
the In-app Billing service and pass in the {@code purchaseToken} String value 
that identifies the purchase to be removed. The {@code purchaseToken} is part 
of the data returned in the {@code INAPP_PURCHASE_DATA} String by the Google 
Play service following a successful purchase request. In this example, you are 
recording the consumption of a product that is identified with the 
{@code purchaseToken} in the {@code token} variable.</p>
<pre>
int response = mService.consumePurchase(3, getPackageName(), token);
</pre>
@@ -282,6 +301,33 @@ int response = mService.consumePurchase(3, getPackageName(), token);
<p>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.</p>
<p class="note"><strong>Security Recommendation:</strong> 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.</p>

<h3 id="Subs">Implementing Subscriptions</h3>
<p>Launching a purchase flow for a subscription is similar to launching the 
purchase flow for a product, with the exception that the product type must be set 
to "subs". The purchase result is delivered to your Activity's 
{@link android.app.Activity#onActivityResult onActivityResult} method, exactly 
as in the case of in-app products.</p>
<pre>
Bundle bundle = mService.getBuyIntent(3, "com.example.myapp",
   MY_SKU, "subs", developerPayload);

PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
   // Start purchase flow (this brings up the Google Play UI).
   // Result will be delivered through onActivityResult().
   startIntentSenderForResult(pendingIntent, RC_BUY, new Intent(),
       Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
}
</pre>
<p>To query for active subscriptions, use the {@code getPurchases} method, again 
with the product type parameter set to "subs".</p>
<pre>
Bundle activeSubs = mService.getPurchases(3, "com.example.myapp",
                   "subs", continueToken);
</pre>
<p>The call returns a {@code Bundle} with all the active subscriptions owned by 
the user. Once a subscription expires without renewal, it will no longer appear 
in the returned {@code Bundle}.</p>



+35 −85

File changed.

Preview size limit exceeded, changes collapsed.

+4 −2
Original line number Diff line number Diff line
@@ -102,11 +102,13 @@ parent.link=index.html
  </tr>
  <tr>
    <td>{@code type}</td>
    <td>Value must be “inapp” for an in-app purchase type.</td>
    <td>Value must be “inapp” for an in-app product or "subs" for 
subscriptions.</td>
  </tr>
  <tr>
    <td>{@code price}</td>
    <td>Formatted price of the item, including its currency sign. The price does not include tax.</td>
    <td>Formatted price of the item, including its currency sign. The price 
does not include tax.</td>
  </tr>
  <tr>
    <td>{@code title}</td>
Loading