OpenIAB plugin for Cordova-based frameworks
- Add Android platform to your project using CLI.
$ cordova platform add android
- Add OpenIAB plugin, referencing repo.
$ cordova plugin add https://github.com/onepf/OpenIAB-Cordova-Plugin.git
- Build the app.
$ cordova build
- Run it.
$ cordova run android
- Include script to your application.
<script type="text/javascript" src="cordova.js"></script>
- Simply call
openiab
object methods, passing callback functions.
a) Map you SKUs. This step is optional.
openiab.mapSku(function(){}, function(error){}, SKU1, openiab.STORE_NAME.GOOGLE, "sku_product");
b) Set some options.
Set store search strategy.
openiab.options.storeSearchStrategy = openiab.STORE_SEARCH_STRATEGY.INSTALLER_THEN_BEST_FIT;
Set available stores to restrict the set of stores to check.
openiab.options.availableStoreNames = [ openiab.STORE_NAME.GOOGLE, openiab.STORE_NAME.YANDEX ];
Set preferred store names (works only for store search strategy OpenIabHelper.Options.SEARCH_STRATEGY_BEST_FIT
and OpenIabHelper.Options.SEARCH_STRATEGY_INSTALLER_THEN_BEST_FIT
).
openiab.options.preferredStoreNames = [ openiab.STORE_NAME.GOOGLE, openiab.STORE_NAME.YANDEX ];
Set store keys.
openiab.options.storeKeys = [ [openiab.STORE_NAME.GOOGLE, 'your public key'] ];
Set verifying mode (applicable only for Google Play, Appland, Aptoide, AppMall, SlideMe, Yandex.Store).
openiab.options.verifyMode = openiab.VERIFY_MODE.SKIP;
c) Initialize plugin.
openiab.init(function(){}, function(error){}, [ "SKU1", "SKU2", "SKU3" ]);
d) Start purchase.
openiab.purchaseProduct(function(purchase){}, function(error){}, "SKU");
e) Consume consumable SKUs in order to be able to purchase it again.
openiab.consume(function(purchase){}, function(error){}, "SKU");
- Use additional methods to get information about SKUs and purchases.
a) Can be used any time after init
is finished.
openiab.getPurchases(function(purchaseList){}, function(error){});
b) Get details of the single SKU.
openiab.getSkuDetails(function(skuDetails){}, function(error){}, "SKU");
c) Get details of the SKU list.
openiab.getSkuListDetails(function(skuDetailsList){}, function(error){}, ["SKU1", "SKU2", "SKU3"]);
Also consider to check sample application for cordova or xdk.
purchase =
{
itemType:'',
orderId:'',
packageName:'',
sku:'',
purchaseTime:0,
purchaseState:0,
developerPayload:'',
token:'',
originalJson:'',
signature:'',
appstoreName:''
}
skuDetails =
{
itemType:'',
sku:'',
type:'',
price:'',
title:'',
description:'',
json:''
}
error =
{
code:-1,
message:''
}