简体   繁体   中英

Updating google play billing library to version 3 with confusing behavior

I have a functioning Android implementation in-app billing, using the billing client 1.0.2 library and everything works fine. I have a simple premium upgrade, without subscriptions. Now I tried to upgrade to 3.0.0, I made all the necessary changes to my code (using official documentation, release notes, and StackOverflow) and it seems to work. I know I must recognize all purchases within three days. Failure to correctly recognize purchases will result in reimbursement for these purchases. And that's what I did. Now the point that confuses me:

I tested my purchase workflow another time and debugged all steps to see what happens. Inside handlePurchase in BillingManager, I use the following code, inspired by the official documentation:

if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
    if (!purchase.isAcknowledged()) {

        AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();

        AcknowledgePurchaseResponseListener acknowledgePurchaseResponseListener = new AcknowledgePurchaseResponseListener() {
            @Override
            public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
                Toast.makeText(getContext(), "Purchase acknowledged", Toast.LENGTH_LONG);
            }
        };

        mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, acknowledgePurchaseResponseListener);
     }
}

In the second line „isAcknowledged()“ always returns true (so the if statement returns false), although the method „acknowledgePurchase“ was never called and will never be called…. Does anybody have an explanation for this behavior? How can it be already acknowledged? Will this result in reimbursement for these purchases in real in app purchases? I only used a trial account.

Thanks a lot for your help!

I found the reason for the behavior described in my question:

I used the same Google account for testing the purchase workflow before (although it is a simple premium upgrade without subscriptions there is a simple trick for "consuming" this purchase and rebuy it again for testing) and that led it to return "true" from "isAcknowledged()".

After creating a completely new Google account and testing the complete workflow again, everything works fine and the process of acknowledging a purchase can be observed in debug mode!

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