Problem with google play billing library

I’m having problem with google play billing library in cocos. It seems to be working fine a few weeks ago but now it stoped working. I’m using com.android.billingclient:billing:6.1.0

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        obj = this;
        mContext = this;
        SDKWrapper.shared().init(this);
        billingClient = BillingClient.newBuilder(this)
                .enablePendingPurchases()
                .setListener(
                        (billingResult, list) -> {
                            System.out.println("This is not executed")
                }).build();
        //start the connection after initializing the billing client
        establishConnection();
}

It does not go to listner. I tried updating the label to com.android.billingclient:billing:7.0.0. still not working. It shows list as empty even thoough it should hav some values. Does anyone have any example code that I can check?

you have better go to google to ask the question

cocos creator 谷歌支付_cocos creator接google支付-CSDN博客 check this one

Have tried but couldn’t find any solution.

I am not familiar with the google play billing, you can ask the ask the ChatGPT for the answer.

1 Like

You should check the billingResult code, it will return the results and also a message if failing.
I do something like this:

if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchases != null) {
            if (DEBUG) {
                System.out.println("onPurchasesUpdated OK");
            }
            for (Purchase purchase : purchases) {
                handlePurchase(purchase);
            }
        } else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) {
            if (DEBUG) {
                System.out.println("onPurchasesUpdated CANCELED");
            }
            if (purchaseListener != null) {
                purchaseListener.onUserCanceled();
            }
        } else {
            if (DEBUG) {
                System.out.println("onPurchasesUpdated FAILED "+billingResult.getDebugMessage());
            }
            if (purchaseListener != null) {
                purchaseListener.onPurchaseFailed(null);
            }
        }

Do not take in cosideration “purchaseListener” I did create my own library to handle inapp and ads.

It is working fine now, there was a problem with product ID and Application ID