cordova-plugin-inapppurchase
cordova-plugin-inapppurchase copied to clipboard
Can't start async operation (refresh inventory) because another async operation(refresh inventory) is in progress.
I have implemented the code as mentioned.
Code:
window.inAppPurchase
.getProducts([PRODUCTID])
.then(function (products) {
console.log(products);
})
.catch(function (err) {
console.log(err);
});
Steps to reproduce:
- Case when the application is not yet processed by google play and it throws the error "this version of the application is not configured for billing through google play".
Once after getting the error above error, if the in-app purchase process is repeated again starting with the getProducts() method, it throws the error Can't start async operation (refresh inventory) because another async operation(refresh inventory) is in progress.
I encountered the very same error:
E/PluginManager(26995): Uncaught exception from plugin
E/PluginManager(26995): java.lang.IllegalStateException: Can't start async operation (refresh inventory) because another async operation(refresh inventory) is in progress.
E/PluginManager(26995): at com.alexdisler.inapppurchases.IabHelper.flagStartAsync(IabHelper.java:832)
E/PluginManager(26995): at com.alexdisler.inapppurchases.IabHelper.queryInventoryAsync(IabHelper.java:624)
E/PluginManager(26995): at com.alexdisler.inapppurchases.IabHelper.queryInventoryAsync(IabHelper.java:652)
E/PluginManager(26995): at com.alexdisler.inapppurchases.InAppBillingV3.restorePurchases(InAppBillingV3.java:357)
E/PluginManager(26995): at com.alexdisler.inapppurchases.InAppBillingV3.execute(InAppBillingV3.java:172)
E/PluginManager(26995): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
E/PluginManager(26995): at org.apache.cordova.PluginManager.exec(PluginManager.java:133)
E/PluginManager(26995): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
E/PluginManager(26995): at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
E/PluginManager(26995): at android.webkit.JWebCoreJavaBridge.sharedTimerFired(Native Method)
E/PluginManager(26995): at android.webkit.JWebCoreJavaBridge.sharedTimerFired(Native Method)
E/PluginManager(26995): at android.webkit.JWebCoreJavaBridge.fireSharedTimer(JWebCoreJavaBridge.java:92)
E/PluginManager(26995): at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:108)
E/PluginManager(26995): at android.os.Handler.dispatchMessage(Handler.java:99)
E/PluginManager(26995): at android.os.Looper.loop(Looper.java:137)
E/PluginManager(26995): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:818)
E/PluginManager(26995): at java.lang.Thread.run(Thread.java:841)
I believe that the minimal example to reproduce it is:
window.inAppPurchase.restorePurchases();
window.inAppPurchase.getProducts(PRODUCTS);
The operations cannot be executed concurrently.
Ran into this as well and was able to resolve using async's series:
async.series([
function(done) {
inAppPurchase
.restorePurchases()
.then(function (data) {
console.log('Restored Purchases: ', data);
done(null);
/*
[{
transactionId: ...
productId: ...
state: ...
date: ...
}]
*/
})
.catch(function (err) {
console.error('Restored purchase :', err);
done(err)
});
}, function(done) {
inAppPurchase
.getProducts(['your_product_name])
.then(function (iaps) {
console.log('IAPs -> ', iaps);
scope.vc.iaps = iaps;
done(null);
/*
[{ productId: 'com.yourapp.prod1', 'title': '...', description: '...', price: '...' }, ...]
*/
})
.catch(function (err) {
console.error('IAPS error -> ', err);
done(err)
});
}
], function(err, result) {
if(err) {
console.error('Error restore and fetch iaps');
} else console.log('Success restore and fetch iaps')
});
I also had this occur specifically because the intent LaunchPurchaseFlow was occurring. In my case, I am using angular and ionic and had an getProducts and then a restorePurchases sequentially (using Promise callbacks) but the problem was it was in my ngOnInit so it was triggering because the component reloaded itself after completing the purchase.
this was my final solution: https://stackoverflow.com/questions/44941508/error-retrieving-sku-details
The above may or may not have been valid but for sure adding the billing licensing key resolved all issues not related to code. The IAP service is constrained that it can only do 1 async operation at a time so make sure to run your calls sequentially