Android in-app billing - How to handle refunds

0 votes

I'm trying to add in-app billing in my app; everything works ok except for refunds. Since I have been struggling with this for the past few days, it still amazes me that there is no way to determine from the app's perspective whether a user has requested a refund. After the user has received a refund, I want to have the option to terminate access to a one-time managed product (remove advertisements). I am utilizing Google Play APIs because I do not use a backend.

I tried using queryPurchaseHistoryAsync, which returns a list of the user's most recent purchases, to query the Google Play APIs. Given that the purchases are still present even after requesting a refund, this does not appear to operate (been waiting for one day before writing this).

Here's what I did:

  1. Install the app on a real device
  2. Buy the in-app content
  3. Verify that app unlocks the content
  4. Go to my Google Play order history and ask for refund for the in-app product
  5. 10 minutes later the transaction got refunded (without me as a developer being involved at all)
  6. App still provides the paid content
  7. Cleaning Play Store App data & cache
  8. App still provides the paid content

So after purchasing my in-app product, any customer can request a refund on his Google Play page right away? Is it just me, or is this API a nightmare? Am I missing something simple?

The PurchaseState enum is

  public @interface PurchaseState {
    // Purchase with unknown state.
    int UNSPECIFIED_STATE = 0;
    // Purchase is completed.
    int PURCHASED = 1;
    // Purchase is waiting for payment completion.
    int PENDING = 2;
  }

I do not see anything related to refunded here, This seems to me a pretty normal use case, so I'm still thinking that I am missing some key piece of information, how do I do this?

Thanks for any help

Nov 10, 2022 in Android by Edureka
• 13,750 points
2,619 views

1 answer to this question.

0 votes

Simply disregard the library's purchase to overcome this. instead of the getPurchaseState() method, use your own unmasked custom:

int getUnmaskedPurchaseState(Purchase purchase) {
    int purchaseState = purchase.getPurchaseState();
    try {
        purchaseState = new JSONObject(purchase.getOriginalJson()).optInt("purchaseState", 0);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return purchaseState;
}
answered Nov 10, 2022 by Edureka
• 12,730 points

Related Questions In Android

+1 vote
1 answer
0 votes
0 answers
+3 votes
1 answer

How to implement the system lock screen in your own android app?

There is a feature in Android called ...READ MORE

answered Nov 23, 2022 in Android by Edureka
• 13,750 points

edited Mar 5, 2025 5,927 views
0 votes
0 answers

How to launch Amazon Shopping app in Android app?

I want my Android application to be ...READ MORE

Nov 23, 2022 in Android by Ashwini
• 5,430 points
1,624 views