Android Devs
Android Devs

Reputation: 125

How do I verify canceled in-app subscription?

I am using: bp.isSubscribed(ID) to verify my subscription. But when I cancel a subscription the method bp.isSubscribed(ID) still returning true. What should I do?

transDetails.purchaseInfo.purchaseData.purchaseState.toString() Always return PurchasedSuccessfully after i cancelled manually from play store manage subscription.

public void checkSubscriptionDetails(){

bp = new BillingProcessor(this, LICENSE_KEY, new BillingProcessor.IBillingHandler() {
            @Override
            public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) {

                Common.printLog("InApp", ":onProductPurchased :" + productId);


            }

            @Override
            public void onPurchaseHistoryRestored() {

            }

            @Override
            public void onBillingError(int errorCode, @Nullable Throwable error) {
           }

            @Override
            public void onBillingInitialized() {


            }
        });


boolean purchaseResult = bp.loadOwnedPurchasesFromGoogle();
// ## purchaseResult is always return FALSE 

        if (bp.isSubscribed(planID)) {

            TransactionDetails transDetails = bp.getSubscriptionTransactionDetails(planID);

            String strDetailsSubsMonth = "OrderID:" + transDetails.orderId +
                    "\nproductId: " + transDetails.productId +
                    "\npurchaseToken: " + transDetails.purchaseToken +
                    "\npurchaseTime: " + transDetails.purchaseTime +
                    "\npurchaseInfo.signature: " + transDetails.purchaseInfo.signature +
                    "\npurchaseInfo.responseData: " + transDetails.purchaseInfo.responseData +
                    "\npurchaseData.purchaseToken: " + transDetails.purchaseInfo.purchaseData.purchaseToken +
                    "\npurchaseData.autoRenewing: " + transDetails.purchaseInfo.purchaseData.autoRenewing +
                    "\npurchaseData.developerPayload: " + transDetails.purchaseInfo.purchaseData.developerPayload +
                    "\npurchaseData.purchaseState: " + transDetails.purchaseInfo.purchaseData.purchaseState.toString();

            String strPurchaseState = transDetails.purchaseInfo.purchaseData.purchaseState.toString();
            Common.printLog("InApp", "Details: " + planID + " >> " + strDetailsSubsMonth + " \n" + "Purchase State :" + strPurchaseState);
        }

}


package com.anjlab.android.iab.v3;

public enum PurchaseState
{
    PurchasedSuccessfully,
    Canceled,
    Refunded,
    SubscriptionExpired
}

i need return "Canceled" when subscription canceled.

Upvotes: 1

Views: 491

Answers (2)

Android Devs
Android Devs

Reputation: 125

Best Solution from Server side get actual information for subscription or you can cross verify by Node.js configuration.

https://caster.io/lessons/verify-android-app-subscription-status-from-nodejs

Upvotes: 0

Red Dev
Red Dev

Reputation: 21

Initiate bp varibale in onCreate() and then call loadOwnedPurchasesFromGoogle().

In my case!

Don't know why we need to Call loadOwnedPurchasesFromGoogle() for multiple time. I always get false when I call in loadOwnedPurchasesFromGoogle() in onCreate(). But when I call in onPause() and onDestory(), I get true and my all values get update.

After getting loadOwnedPurchasesFromGoogle() true, I get update subscription value!

Upvotes: 1

Related Questions