Unable to get updated Purchase object after Acknowledging the purchase in new Google billing Api 2.0
NickName:Rajat Beck Ask DateTime:2019-05-31T00:52:01

Unable to get updated Purchase object after Acknowledging the purchase in new Google billing Api 2.0

I am implementing the new billing API 2.0 which has this purchase acknowledge method. Earlier i was using AIDL for my purchase and i had following use case is that i used to pass developer payload during initiating purchase and used to get back my developer payload in the response as a part of purchase object.

Bundle bundle = mService.getBuyIntent(3, "com.example.myapp",
   MY_SKU, "subs", developerPayload);

PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
   // Start purchase flow (this brings up the Google Play UI).
   // Result will be delivered through onActivityResult().
   startIntentSenderForResult(pendingIntent, RC_BUY, new Intent(),
       Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
}

and in my on on activity result i used to get purchase object

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
   if (requestCode == 1001) {           
      int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
      String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
      String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");

      if (resultCode == RESULT_OK) {
         try {
            JSONObject jo = new JSONObject(purchaseData);
            String sku = jo.getString("productId");
            alert("You have bought the " + sku + ". Excellent choice, 
               adventurer!");
          }
          catch (JSONException e) {
             alert("Failed to parse purchase data.");
             e.printStackTrace();
          }
      }
   }
}

This purchase object has a developer payload which i send to the server for verification.

Now in the new API the developer payload can be added only after purchase is completed or when we consume a purchase, so the problem is after purchase is acknowledged i need the updated purchase object but how to get it?

 if (!purchase.isAcknowledged()) {
            AcknowledgePurchaseParams acknowledgePurchaseParams =
                AcknowledgePurchaseParams.newBuilder()
                    .setPurchaseToken(purchase.getPurchaseToken())
                    .setDeveloperPayload(/* my payload */)
                    .build();
            client.acknowledgePurchase(acknowledgePurchaseParams, acknowledgePurchaseResponseListener);
        }

In acknowledgePurchaseResponseListener i get only the response code whether it is success or failure. But i need to updated purchase object object with developerPayload and isAcknowledged flag true.

Is there a way to do so? Could not find anything in documentation.

Copyright Notice:Content Author:「Rajat Beck」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56382436/unable-to-get-updated-purchase-object-after-acknowledging-the-purchase-in-new-go

More about “Unable to get updated Purchase object after Acknowledging the purchase in new Google billing Api 2.0” related questions

Unable to get updated Purchase object after Acknowledging the purchase in new Google billing Api 2.0

I am implementing the new billing API 2.0 which has this purchase acknowledge method. Earlier i was using AIDL for my purchase and i had following use case is that i used to pass developer payload

Show Detail

With Google Play Billing, is it okay to wait with granting entitlement to an in-app purchase until after the purchase has been acknowledged?

The Google Play Billing library documentation on acknowledging purchases states that: you must acknowledge all purchases that have a SUCCESS state received through the Google Play Billing Librar...

Show Detail

How to get purchase status from Google Play Billing?

I have a problem with the google play billing. I have an android app consist of in-app purchase there. I maintain the SharedPreference to purchase an app status. If google gave purchase status as s...

Show Detail

Google play billing purchase result shows empty list after a successful purchase in the google play billing library (Native android)

Google play billing purchase result shows empty list after a successful purchase in the google play billing library. While purchase the product it returning the list as expected. After navigating t...

Show Detail

How to check purchase state of subscription in all new Play Billing Library?

Hi am using new Play Billing Library for in app subscriptions. https://developer.android.com/google/play/billing/billing_library.html Everthing works perfect and am able to subscribe the product. ...

Show Detail

Google billing Library - Fragment getting disappeared after subscription purchase

I am new to the implementation of Google's Billing library and using this system to make subscriptions inside my app. I have created a fragment that displays a list of subscriptions available for our

Show Detail

Retrieve the Inapp purchase of particular user from google play using billing client

I have used Billing client to handle inapp purchase. Once a non-consumable product is purchased, after acknowledging I can save a value in shared preferences. Constraints If the user clear the app...

Show Detail

Google in app purchase version 5 purchase verification issue

I'm unable to verify the purchase or particular item after being purchased from the google play billing version. Is there any way to get the verification of the item purchase from email, or from the

Show Detail

Refunded purchase still appearing in purchase list (Google in-app billing API)

I'm testing IAP with the Google in-app billing API in my Android app. I've made a test purchase, then did a refund on the Google Play Console. I can see the order status is now refunded. However, w...

Show Detail

How to stop Google Play Billing from charging until an api request confirms the purchase can be made

I have a question about the Google Play Billing Library (version 5) but I guess older versions are fine too. In Google Play Billing, the purchase flow is launched like below: BillingResult billingR...

Show Detail