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,620 points
1,545 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,690 points

Related Questions In Android

0 votes
1 answer
0 votes
0 answers
0 votes
0 answers

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

How should the system lock screen be ...READ MORE

Nov 22, 2022 in Android by Edureka
• 12,690 points
683 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
829 views
0 votes
1 answer

Running docker on Android

According to the documentation, the Android kernel is ...READ MORE

answered Aug 1, 2018 in Docker by Kalgi
• 52,350 points
3,770 views
0 votes
1 answer

Task Canceled Exception while invoking AWS Lambda

I'm guessing either the TaskCanceledException instance is ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,020 points
2,467 views
0 votes
1 answer

Is there a way to run Python on Android?

YES! here’s a barcode scanner written in six ...READ MORE

answered Sep 19, 2018 in Python by Priyaj
• 58,020 points
1,023 views
0 votes
1 answer

How can we get the current location in Android?

First you need to define a LocationListener to handle ...READ MORE

answered Sep 25, 2018 in Java by Parth
• 4,640 points
927 views
0 votes
1 answer

How to turn on front flash light programmatically in Android?

For this problem you should: Check whether the ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 12,690 points
1,615 views
0 votes
1 answer

How to display Toast in Android?

Use the show() function of the Toast ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 12,690 points
1,437 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP