Cocos Cretor SDKBOX debug IAP plugin

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');
	}
}

what version of Cocos Creator are you using?

You first need to submit your app to google for internal testing.

The app you submitted and the app you are debugging must have the same build number and version code.

Hi, I have already submitted, thanks. I need to test from build I download from google play, or it should work from apk I install on phone after Cocos build?

As long as the version code and build number are the same, it should work.

So, you can modify the app locally and install to your phone from your computer for testing. But, must keep the version code and build number to be the same as the one available on PlayStore (no need to be a production release, an internal testing release should be fine too)

In this case something wrong… My app is in internal testing now, I added key from google play console, but as I explained in the top:

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

and console.log(sdkbox.IAP.getProducts()); returns empty array

you can turn on debug mode for IAP.
hope it helps.

I will have more times early next month.
I will create a test project and sample codes and write a tutorial for you.

Where I can see debug logs for for IAP?

Perhaps you did not initialize the sdkbox, or initialized it after setting up the listener?

Hi, Thanks for reply, no as you see my code provided above I initialized sdkbox.
Also in documentation says I need to set up listeners first:
image
by the way, when I build the project with default sdkbox config from exmaple I see it works and returns products, so looks like some problem with my game. But I don’t know why, I set up products in GP, added key and product id to the config. My app ready for internal and closed testing.

@htlxyz perhaps you may help?

Does IAP work only in debug build?
I tried to run with debug, and it shows products,
When I try to run without debug, it does nothing…

But I can’t upload a debug build to the GP to test. But it is very strange, I am getting products just in debug build.

use release keystore in google play console.

As I understood, I need to upload an .apk with keystore I generated in Android Studio to Google Play Console and make internal test from this .apk version?
image

Hi again, we added keystore as you said, but result is the same…
image
image
image
But still, I can see and buy products only when debug mode is enabled in build options… I don’t understand
Here is a screenshot with debug mode enabled:
Look between “PRODUCTS START - PRODUCTS END ” logs.




Now the screenshot when debug mode is off:

I guess maybe your app using Google Play App Signing. so the debug version’s keystore is different from the release version.

https://support.google.com/googleplay/android-developer/answer/9842756

We have created new app in Google Play Console and uploaded there our build with release keystore created in Android Studio. We aren’t using debug keystore from Cocos

Even checked properties of gradle, there is release key added:

you can check like this:

package a apk(A) in your local PC.
and upload apk(A) to google play, and then download apk (B) as a normal user.

check keystore of those two apk (A/B)