Introduction
The In App Purchase is based on the Google Play API Version 3. The singular goal being to limit the number of changes required by an app developer having already implemented google API to subsequently use this API.
The changes explained in this article are required to migrate your in app purchase capability from Google Play to this API.
InAppBillingService Binding Action
-
Change the following action used to bind the InAppBillingService.BIND for IPC calls in any code references (Defined in Consts.java in the billing example)
-
com.android.vending.billing.InAppBillingService.BIND to com.environment_name.vending.billing.InAppBillingService.BIND
-
-
Replace the InAppBillingService.aidl file provided by Google with the appropriate file for your environment.
Example
Based on the Google Play API Version 3 example application, TrivialDrive, an updated IabHelper would look like the following starting on line 265:
Intent serviceIntent = new Intent("com.environment_name.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.environment_name.estore"); if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) { // service available to handle that Intent mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); }
Update the public key
-
Wherever you are currently verifying the signed data returned by the google play API, either server or client code, please be sure to update your public key obtain using these instructions.
Sample Application
We have take the Google Play API V3 sample application and modified it to work in environment. This section describes how to download and use this sample application using IntelliJ IDE.
-
Download the application from https://github.com/App47/InAppBillingExample.git.
-
For the purpose of this documentation, only the TrivialDrive directory will be used.
-
The master branch of this project contains applications directly as they come from Google. In other words, if you were to setup a Google play account as documented in the README in the project, it would work with Google Play APIVersion 3.
-
There is a branch corresponding to your environment that reconfigures the app to work specifically for your environment.
-
Check out the corresponding branch for your environment and setup the SKUS according to the README file in the TrivialDrive project
SKU Configuration
Using the SKU configuration documentation, configure the following SKUs in your environment. Be sure to initially set to test mode to limit the interaction with the payment gateway.
-
Create MANAGED in-app items with these IDs:
-
premium
-
gas
-
-
Set their prices to 1 dollar (or any other price you like, but make it a small price since this is just for testing purposes).
-
Create a SUBSCRIPTION items with this ID:
-
infinite_gas
-
-
Set the price to 1 dollar and the billing recurrence to monthly.
Testing
Once the updates to the SKU are made and you have the correct branch checked out for your environment.
-
Make sure you have the app store installed on a device.
-
Log into the app store and ensure that the credit card information is correctly configured for your enviornment.
-
Compile and deploy the sample application to the same device that contains the app store.
-
While running the Trivial Drive application, ensure the you can buy gas in 1/4 tank increments, upgrade the car to premium as well as subscribe to unlimited gas.
Comments
0 comments
Please sign in to leave a comment.