User login
SlideME In-App-Payments (IAP) SDK
SlideME In-App-Payments (IAP) SDK is developed from the ground up, with ease of integration in mind. It provides a simple and secure way to interface with our billing system using asynchronous network calls.
Note: SlideME also supports OpenIAB, an open OnePF standard, single IAP SDK for multiple stores, such as Google Play, Amazon, SlideME and for other stores that plan to support this open standard.
The SlideME IAP SDK is designed to support two types of products:
- "In-App"
- "Subscription" (pending)
An "In-App" product is a product that can be consumed and be re-purchased unlimited times. That means that only one(1) non-consumed in-app product (of a specific item-sku) can be purchased (owned) at any time. If a product is not consumed, it's considered an "active" product and therefore the system will deny any further purchases. A subscription is an auto renewing according to the renewal period that is set up in the administration.
Note: The Subscription in-app product type implementation has not been finalized. This is a server side implementation and won't need an SDK update. Feel free to proceed with the "In-App" type and watch this space for updates for the "Subscription" type.
Generate validation key
- Log in to your slideme.org developer account
- Go to Applications tab (https://slideme.org/my-applications), visit "Keypair list" to "Add new key". Provide a meaningful Key Name e.g. 'myApplicationName IapKey' so you can recognize it later on.
- Once the key is generated you can copy the public key signature and paste it in your applications verify methods (check sample application).
Plan your IAP products
Each IAP product must have a "Product ID", product ids must be unique for each application you upload.
Product id's can be alphanumeric, there are no restrictions in the combination of characters with a max length of 50 characters.
You will use your product id's when building your app and after uploading your app in SlideME.
InApp SDK integration
The entire SDK functionality is wrapped in the InAppHelperActivity's life-cycle & callback methods.
Extend InAppHelperActivity in your own activity that should display the in app purchasing options and override some or all of its callback methods.
- Add InApp SDK library jar to your project
- Add the following permission to your AndroidManifest.xml
<uses-permission android:name="com.slideme.sam.manager.inapp.permission.BILLING" />
- extend InAppHelperActivity, e.g.
public class MainActivity extends InAppHelperActivity
You should start using the SDK once
it's set-up and ready. You can check if the SDK is ready with the
isReady()
function. Once the SDK is ready for use the onIapReady()
callback method is fired. From there on, you can safely use any
couple of the request-callback helper methods of InAppHelperActivity.
Load user purchases
Call loadPurchases(String type)
with
one of:
- Constants.InAppProductType.ALL;
- Constants.InAppProductType.PRODUCT;
- Constants.InAppProductType.SUBSCRIPTION;
A good time to call this would be right after the inApp SDK is set-up:
@Override protected void onIapReady() { loadPurchases(Constants.InAppProductType.ALL); }
Load IAP items details
Call loadList(List<String> ids) with a list of the SKU ids that you wish to retrieve details (e.g. price) for. Once the response is ready, callback method onListLoaded(result) is loaded and the result object containing the List<Product> is in your disposal.
The id's are defined by you and can be anything you want, as long as they are unique. You will be asked to create the same IAP id's once you upload your application to SlideME (see "Create IAP Products").
Purchase an item
Call purchase(String sku, String developerPayload) in order to start the purchase flow for the specific sku.
A good time to call this would be in a buy button's onClickListener().
Once purchasing is finished, callback method onPurchaseFinished(purchaseResult) is called and the result object is in your disposal. Check purchaseResult.status and purchaseResult.purchaseResult. It is advised to validate the purchaseResult signed data using your generated public key.
Consume an item
Call consume(String sku) in order to consume an iap item. Once the consume request has finished the callback method onPurchaseConsumed(int result) the result can be one of:
- InAppStatus.SUCCESS
- InAppStatus.CANCELLED
- InAppStatus.INVALID_IAP_ID
- InAappStatus.ERROR
InApp SDK Integration (alternative)
Another way to integrate with SlideME IAP SDK is using the InAppHelper Interface/InAppHelperCallback.
- Implement the interface in you activity:
public class MainActivity extends Activity implements InAppHelperCallback
- Bind InAppHelper with some of the activity lifecycle methods
private InAppHelper inAppHelper; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); inAppHelper = new InAppHelper().create(this, this); } @Override protected void onDestroy() { super.onDestroy(); inAppHelper.destroy(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case InAppHelper.REQUEST_CODE_BUY: Bundle b; if(data == null || data.getExtras() == null) { b = new Bundle(); b.putInt(Constants.BUNDLE_STATUS, InAppStatus.ERROR); } else { b = data.getBundleExtra(Constants.EXTRA_RESPONSE); } onPurchaseFinished(new PurchaseResult(b)); break; default: break; } }
Create IAP Products
Once your application is uploaded you can create your IAP Products.
- Go to Applications tab (https://slideme.org/my-applications) and select your Application
- Go to Manage IAP tab
- Add new IAP Product(s). Create a new IAP entry for each IAP product you wish to add. The important part of this step is to be sure that "Product ID" field is the exactly the same as the one you are using in your application for this specific product.
Test Mode
During development you can use test mode to check your application behavior under different scenarios. You can emulate success or failure, by changing the "Test mode" option value accordingly.
Note: When in Test Mode, purchases aren't recorded and therefore not returned in onPurchasesLoaded. This however will work as expected when your app is Published and Test Mode is disabled.
Caution: When you are ready to Publish your app you should disable 'Test Mode'.
OpenIAB
As mentioned in OpenIAB wiki, for testing OpenIAB integration, your apk must be installed on the device using adb with the SlideME package name as the installer, like so:
adb install -i com.slideme.sam.manager /path/to/YourApp.apk
This is required by OpenIAB in order to distinguish which store should handle the IAP purchase flow. The manual adb installation is only needed during testing. When you release your app to the SlideME market this will be automatically handled from the SlideME Market (SAM) application.
Check list
- Plan your IAP product items
- Implement your IAP product items within your app
- Create key-pair for your app. "My Applications" > "Add new key"
- Submit/upload your App to SlideME and assign Key pair to this app and keep App "Unpublished". From this Edit app form, go to "IAP key:" to associate your app to a key-pair
- Create your IAP products. View your app details, select "Manage IAP" menu
- Enable Test Mode to test while keeping app "Unpublished". Visit IAP item from Manage IAP menu > Select IAP product, edit to set Test Mode.
- Publish your app for distribution when ready. Visit to edit your app > select checkbox at top and set to "Published". Disable Test mode if enabled.
Requirements
You will need to have the new SlideME (SAM) app (version 6) that can be installed from this link to your device: http://slideme.org/sam.apk
Changes: 18 March, 2014 - (SAM v6 production version has been released and is available from the above link that supports IAP. We are propagating release updates to all our OEM's also.)
Download the SlideME IAP SDK from the below link.