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:
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.
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.
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.
<uses-permission android:name="com.slideme.sam.manager.inapp.permission.BILLING" />
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.
Call loadPurchases(String type)
with
one of:
A good time to call this would be right after the inApp SDK is set-up:
@Override protected void onIapReady() { loadPurchases(Constants.InAppProductType.ALL); }
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").
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.
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:
Another way to integrate with SlideME IAP SDK is using the InAppHelper Interface/InAppHelperCallback.
public class MainActivity extends Activity implements InAppHelperCallback
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; } }
Once your application is uploaded you can create your IAP Products.
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'.
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.
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.
Fichier attaché | Taille |
---|---|
SlideME_IAP_example_TrivialDrive_InAppHelperActivity_v1.5.2_26June2014.zip | 559.77 Ko |
SlideME_IAP_example_TrivialDrive_InAppHelper_v1.5.2_26June2014.zip | 560.18 Ko |
slideme_inappsdk_v1.6_22Sept2015.jar | 46.29 Ko |