The following document provides technical reference information for the following:
- Google Play Server Response Codes for In-app Billing
- In-app Billing Interface Parameters
- In-app Billing Broadcast Intents
Google Play Server Response Codes for In-app Billing
The following table lists all of the server response codes that are sent from Google Play to
your application. Google Play sends these response codes asynchronously as
response_code extras in the
broadcast intent. Your application must handle all of these response codes.
||0||Indicates that the request was sent to the server successfully. When this code is returned in
response to a
||1||Indicates that the user pressed the back button on the checkout page instead of buying the item.|
||2||Indicates that the network connection is down.|
||3||Indicates that in-app billing is not available because the
||4||Indicates that Google Play cannot find the requested item in the application's product
list. This can happen if the product ID is misspelled in your
||5||Indicates that an application is trying to make an in-app billing request but the application has not declared the com.android.vending.BILLING permission in its manifest. Can also indicate that an application is not properly signed, or that you sent a malformed request, such as a request with missing Bundle keys or a request that uses an unrecognized request type.|
||6||Indicates an unexpected server error. For example, this error is triggered if you try to purchase an item from yourself, which is not allowed by Google Checkout.|
In-app Billing Service Interface
The following section describes the interface for Google Play's in-app billing service. The
interface is defined in the
IMarketBillingService.aidl file, which is included with the
in-app billing sample
The interface consists of a single request method
sendBillingRequest(). This method
takes a single
Bundle parameter. The Bundle parameter includes several key-value
pairs, which are summarized in table 2.
||Yes||The type of billing request you are making with the
||1||Yes||The version of Google Play's in-app billing service you are using. The current version is 1.|
||A valid package name.||Yes||The name of the application that is making the request.|
||Any valid product identifier.||Required for
||The product ID of the item you are making a billing request for. Every in-app item that you sell using Google Play's in-app billing service must have a unique product ID, which you specify on the Google Play publisher site.|
||A number used once. Your application must generate and send a nonce with each
||Any valid array of
||An array of notification identifiers. A notification ID is sent to your application in an
||No||A developer-specified string that can be specified when you make a
BILLING_REQUEST key can have the following values:
This request verifies that the Google Play application supports in-app billing. You usually send this request when your application first starts up. This request is useful if you want to enable or disable certain UI features that are relevant only to in-app billing.
This request sends a purchase message to the Google Play application and is the foundation of in-app billing. You send this request when a user indicates that he or she wants to purchase an item in your application. Google Play then handles the financial transaction by displaying the checkout user interface.
This request retrieves the details of a purchase state change. A purchase state change can occur when a purchase request is billed successfully or when a user cancels a transaction during checkout. It can also occur when a previous purchase is refunded. Google Play notifies your application when a purchase changes state, so you only need to send this request when there is transaction information to retrieve.
This request acknowledges that your application received the details of a purchase state change. That is, this message confirms that you sent a
GET_PURCHASE_INFORMATIONrequest for a given notification and that you received the purchase information for the notification.
This request retrieves a user's transaction status for managed purchases (see Choosing a Purchase Type for more information). You should send this message only when you need to retrieve a user's transaction status, which is usually only when your application is reinstalled or installed for the first time on a device.
Every in-app billing request generates a synchronous response. The response is a
Bundle and can include one or more of the following keys:
This key provides status information and error information about a request.
This key provides a
PendingIntent, which you use to launch the checkout activity.
This key provides you with a request identifier, which you can use to match asynchronous responses with requests.
Some of these keys are not relevant to certain types of requests. Table 3 shows which keys are returned for each request type.
|Request Type||Keys Returned||Possible Response Codes|
In-app Billing Broadcast Intents
The following section describes the in-app billing broadcast intents that are sent by the Google
Play application. These broadcast intents inform your application about in-app billing actions
that have occurred. Your application must implement a
receive these broadcast intents, such as the
BillingReceiver that's shown in the in-app
This broadcast intent contains a Google Play response code, and is sent after you make an
in-app billing request. A server response code can indicate that a billing request was successfully
sent to Google Play or it can indicate that some error occurred during a billing request. This
intent is not used to report any purchase state changes (such as refund or purchase information).
For more information about the response codes that are sent with this response, see Google Play Response Codes for In-app Billing. The sample application
assigns this broadcast intent to a constant named
longrepresenting a request ID. A request ID identifies a specific billing request and is returned by Google Play at the time a request is made.
intrepresenting the Google Play server response code.
This response indicates that a purchase has changed state, which means a purchase succeeded, was
canceled, or was refunded. This response contains one or more notification IDs. Each notification ID
corresponds to a specific server-side message, and each messages contains information about one or
more transactions. After your application receives an
IN_APP_NOTIFY broadcast intent,
you send a
GET_PURCHASE_INFORMATION request with the notification IDs to retrieve the
message details. The sample application assigns this broadcast intent to a constant named
Stringrepresenting the notification ID for a given purchase state change. Google Play notifies you when there is a purchase state change and the notification includes a unique notification ID. To get the details of the purchase state change, you send the notification ID with the
This broadcast intent contains detailed information about one or more transactions. The
transaction information is contained in a JSON string. The JSON string is signed and the signature
is sent to your application along with the JSON string (unencrypted). To help ensure the security of
your in-app billing messages, your application can verify the signature of this JSON string. The
sample application assigns this broadcast intent to a constant named
Stringrepresenting the signed JSON string.
Stringrepresenting the signature.
Note: Your application should map the broadcast intents and extras
to constants that are unique to your application. See the
Consts.java file in the
sample application to see how this is done.
The fields in the JSON string are described in the following table (see table 4):
|nonce||A number used once. Your application generates the nonce and sends it with the
|notificationId||A unique identifier that is sent with an
|orderId||A unique order identifier for the transaction. This corresponds to the Google Checkout Order ID.|
|packageName||The application package from which the purchase originated.|
|productId||The item's product identifier. Every item has a product ID, which you must specify in the application's product list on the Google Play publisher site.|
|purchaseTime||The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970).|
|purchaseState||The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2 (refunded).|
|developerPayload||A developer-specified string that contains supplemental information about an order. You can
specify a value for this field when you make a