简体   繁体   中英

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.

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM