Hi
Can someone please show how to setup listener in javascript.
There should be some example in the docs, they are hard to understand, it should be explained better.
Cheers!
Hi
Can someone please show how to setup listener in javascript.
There should be some example in the docs, they are hard to understand, it should be explained better.
Cheers!
This:
this.buyListener = {
onSuccess : function (product) {
console.log("######1", product);
},
onFailure : function (product, msg) {
console.log("######2", product, msg);
},
onCanceled : function (product) {
},
onRestored : function (product) {
},
onProductRequestSuccess : function (products) {
},
onProductRequestFailure : function (msg) {
}
};
sdkbox.IAP.setListener(this.buyListener);
Does not work 
Ok I made it working… ufff
Which version of cocos2d-x are you using?
3.6 js
I don’t know magically it started to work so it looks alright now.
Thanks
This guy intergrated successful with cc-js3.6 
I’m having the same problem, I can make purchases fine, but my JS listener functions never get called. I’ve triple checked all of the instructions here: http://sdkbox-doc.github.io/en/plugins/iap/v3-js/, but it just doesn’t seem to work.
I’m using {‘sdkbox_version’: ‘0.5.6.11’, ‘cocos’: ‘3.6.0’, ‘args’: {‘plugin’: u’/Users/hasson/.sdkbox/plugins/sdkbox-iap_v1.2.1.1/’}
Looking in the Android logs, I see “SDKBox IAPGooglePlay” successfully doing it’s job, I see the refresh work and the buy dialog pop up but none of the listeners ever fire. Am I missing something?
07-30 06:56:58.798: D/SDKBox IAPGooglePlay(30898): Query inventory finished.
07-30 06:56:58.798: D/SDKBox IAPGooglePlay(30898): Query inventory was successful.
07-30 06:56:58.798: D/SDKBox IAPGooglePlay(30898): Got product details: [{"id":"ads_removed","title":"Remove Ads","desc":"Remove ads from the game screen.","price":"$2.99","priceValue":2.990000009536743},{"id":"money_pack_0","title":"Small Money Pack","desc":"Small Money Pack","price":"$0.99","priceValue":0.9900000095367432}]
07-30 06:56:58.799: D/SDKBox IAPGooglePlay(30898): GooglePlay Request result : 0 msg : Product request successful data :[{"id":"ads_removed","title":"Remove Ads (Blackjack Genius)","desc":"Remove ads from the game screen.","price":"$2.99","priceValue":2.990000009536743},{"id":"money_pack_0","title":"Small Money Pack","desc":"Small Money Pack","price":"$0.99","priceValue":0.9900000095367432}]
Here’s my JS code:
cc.log(['sdkbox.IAP.init!!']);
sdkbox.IAP.init();
sdkbox.IAP.setDebug(true);
listener = {
onSuccess: function(product) {
return cc.log(['sdkbox.IAP onSuccess', product]);
},
onFailure: function(product, msg) {
return cc.log(['sdkbox.IAP onFailure', product, msg]);
},
onCanceled: function(product) {
return cc.log(['sdkbox.IAP onCanceled', product]);
},
onRestored: function(product) {
return cc.log(['sdkbox.IAP onRestored', product]);
},
onProductRequestSuccess: function(products) {
var i, results;
cc.log(['sdkbox.IAP onProductRequestSuccess', product]);
i = 0;
results = [];
while (i < products.length) {
results.push(i++);
}
return results;
},
onProductRequestFailure: function(msg) {
return cc.log(['sdkbox.IAP onProductRequestFailure', msg]);
}
};
cc.log(['sdkbox.IAP setListener', listener]);
sdkbox.IAP.setListener(listener);
this.buy = function(id) {
cc.log(['sdkbox.IAP.purchase!!', id]);
return sdkbox.IAP.purchase(id);
};
setTimeout((function(_this) {
return function() {
cc.log(['sdkbox.IAP.refresh!!']);
return sdkbox.IAP.refresh();
};
})(this), 12000);
setTimeout((function(_this) {
return function() {
return _this.buy('money_pack_0');
};
})(this), 30000);
Any help would be super appreciated, thanks in advance!
I finally got it working. The whole problem was caused by a JS error. While copying and pasting, I didn’t change “product” to “products”.
Error’ing section from my earlier post:
onProductRequestSuccess: function(products) {
var i, results;
cc.log(['sdkbox.IAP onProductRequestSuccess', product]);
Lesson learned: If your listeners aren’t working– check for JavaScript errors!
Everything is working great now. Thanks for making such a sweet system!
yeah I had the same problem with console error, Just wanted to write it for you, but as I see you’ve already managed the problem 