Cocos Cretor SDKBOX debug IAP plugin – #18 by Horchynskyi – Cocos Creator


Hi all, I am wondering if I can debug SDKBOX IAP plugin before publish to the Google Play?
I added an product in the Google Play Console, added it to the sdkbox_config.json, but when I try check my products it returns empty array:

{
	"android": {
		"iap": {
			"items": {
				"test_gems": {
					"id": "test_item_product"
				}
			},
			"key": "my key" (I added correct key)
		}
	},
	"ios": {
		"iap": {
			"items": {
				"remove_ads": {
					"type": "non_consumable",
					"id": "com.cocos2dx.non1"
				},
				"coin_package": {
					"id": "com.cocos2dx.plugintest2"
				},
				"double_coin": {
					"type": "non_consumable",
					"id": "com.cocos2dx.non2"
				},
				"coin_package2": {
					"id": "com.cocos2dx.plugintest3"
				}
			}
		}
	}
}
console.log(sdkbox.IAP.getProducts());

Also, I noticed callback for onInitialized listener doesn’t call, is it normal?
After sdkbox.IAP.refresh(); also, no one listener is called

my full code of setup is here:

export class PurchaseMain extends Component {
	protected onLoad() {
		if (typeof sdkbox !== 'undefined') {
			sdkbox.IAP.setListener({
				onInitialized: function (success) {
					console.log('Initialized');
					console.log(success);
				},
				onSuccess: function (product) {
					console.log('Purchase success');
				},
				onFailure: function (product, msg) {
					console.log('Purchase failed');
					console.log(product);
					console.log(msg);
					//Purchase failed
					//msg is the error message
				},
				onCanceled: function (product) {
					console.log('Purchase canceled');
					//Purchase was canceled by user
				},
				onRestored: function (product) {
					console.log('Purchase restored');
					//Purchase restored
				},
				onProductRequestSuccess: function (products) {
					console.log('Purchase refresh success');
					//Returns you the data for all the iap products
					//You can get each item using following method
					for (var i = 0; i < products.length; i++) {
						console.log(products[i]);
					}
				},
				onProductRequestFailure: function (msg) {
					console.log('Purchase refresh failed');
					console.log(msg);
					//When product refresh request fails.
				},
			});

			sdkbox.IAP.init(sdkboxConfig);

			sdkbox.IAP.setDebug(true);

			console.log(sdkbox.IAP.getProducts());

			sdkbox.IAP.refresh();
		}
	}

	purchase() {
		sdkbox.IAP.purchase('test_gems');
	}
}



Source link

More To Explore

Share on facebook
Share on twitter
Share on linkedin
Share on email