saravanan-vdg / RoboBillingLibrary

Google Play and Amazon Appstore In-app Billing Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Robo Billing Library - Beta

Robo Billing Library is an extention of Android Billing Library which adds support for Amazon In-App Purchases. It makes use of Roboguice for dependency injection, and Otto for decoupling different parts of the library while still allowing it to communicate efficiently.

Billing Should Be Simple

requestPurchase("com.example.item");

That's how simple it should be to use Android in-app billing. And with this library it is.

It doesn't matter whether you are publishing on Google Play, or the Amazon Appstore, Robo Billing Library makes it easy to publish to both with minimal effort.

Transactions are stored in a local obfuscated database which can be easily queried.

Getting Started

That's it!

Maven Setup

The easiest way to use this library is with Maven.

I'm going to assume you're familiar with Maven, and are all set up with:

  1. You will need to first download the Amazon Mobile App SDK and install it in your local Maven repo by running the following in the Terminal. The jar file is in the InAppPurchasing/lib folder.
mvn install:install-file -Dfile=<path-to-file> -DgroupId=com.amazon -DartifactId=in-app-purchasing -Dversion=1.0.3 -Dpackaging=jar
  1. Next, run the command from the root folder of Robobilling Library to install Robobilling Library into your local Maven repo.
mvn clean install
  1. Now that you've got the library installed, you can add it as a dependency in your pom.xml, and you're ready to rock:
<dependency>
     <groupId>com.ensolabs.robobilling</groupId>
     <artifactId>RoboBillingLibrary</artifactId>
     <type>apklib</type>
     <version>1.0.0</version>
</dependency>

Other Setup

None of the library dependencies are packaged with this library, so you'll have to dig through the pom.xml file to find the dependenies if you aren't using Maven. I'll add better instructions here later...

Google Play Setup

For Google Play, open the AndroidManifest.xml of your application and add the following inside the <manifest> element:

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

And the following inside the <application> element:

<meta-data android:name="billingMode" android:value="google" />

As well as the following service and receiver also inside the <application> element:

<service android:name="net.robotmedia.billing.BillingService" />
<receiver android:name="net.robotmedia.billing.BillingReceiver">
    <intent-filter>
        <action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
        <action android:name="com.android.vending.billing.RESPONSE_CODE" />
        <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
    </intent-filter>
</receiver>

Amazon Appstore Setup

For Amazon Appstore, open the AndroidManifest.xml of your application and add the following inside the <application> element:

<meta-data android:name="billingMode" android:value="amazon" />

As well as the following receiver also inside the <application> element:

<receiver android:name="com.amazon.inapp.purchasing.ResponseReceiver">
    <intent-filter>
        <action android:name="com.amazon.inapp.purchasing.NOTIFY"
            android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY"/>
    </intent-filter>
</receiver>

Usage

Subclassing RoboBillingFragmentActivity

RoboBillingFragmentActivity is an abstract activity that provides default integration with in-app billing (an analogous class for fragments is also provided). It is useful to get acquainted with the library, or for very simple applications that require in-app billing integration in only one activity. For more flexibility use RoboBillingController directly.

When created your RoboBillingFragmentActivity instance will check if in-app billing is supported, followed by a call to onBillingChecked(boolean), which has to be implemented by the subclass.

Additionally, your RoboBillingFragmentActivity subclass will attempt to restore all transactions, only once. This is necessary in case the user has previously installed the app and made purchases. Existing transactions will generate calls to onPurchaseStateChanged(PurchaseStateChangeEvent event), which has to be implemented by the subclass.

Starting a purchase is as simple as calling requestPurchase(String). RoboBillingFragmentActivity will start the Google Play or Amazon Appstore intent automatically and onPurchaseStateChange(PurchaseStateChangeEvent event) will be called after the transaction is confirmed.

RoboBillingController

RoboBillingController provides high-level functions to interact with the Billing service and to query an obfuscated local transaction database.

Since most billing functions are asynchronous, RoboBillingController notifies whichever object(s) are listening on the event bus for the various billing events to be fired.

Additionally, RoboBillingController requires an IConfiguration instance from which the public key required to validate signed messages and a salt to obfuscate transactions are obtained. A good place to provide the configuration is in the Application subclass.

Proguard

If you are using Proguard to obfuscate your code (and you should if you're using this library), you will need to add the following to the proguard.cfg file:

# Needed for Square's Otto library
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}

# Needed by the Roboguice library
-keep public class roboguice.**
-keep class com.google.inject.Binder
-keepclassmembers class * {
    @com.google.inject.Inject <init>(...);
}
# There's no way to keep all @Observes methods, so use the On*Event convention to identify event handlers
-keepclassmembers class * {
    void *(**On*Event);
}

Dungeons Redux

Dungeons Redux is a sample app that shows how to use Robo Billing Library via subclassing RoboBillingApplication and RoboBillingFragmentActivity. It is a simplified version of the Dungeons in-app billing example provided by Google.

It should be noted that Dungeons Redux does not intend to be an example of how to use in-app billing in general.

Contact

http://twitter.com/chris_ftmfw | http://about.me/christopherjperry

License

Copyright 2012 Christopher Perry Inc.
Copyright 2011 Robot Media SL (http://www.robotmedia.net)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Google Play and Amazon Appstore In-app Billing Library