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 in Android by Edureka
• 12,290 points
44 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 by Edureka
• 10,880 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

4 days ago in Android by Edureka
• 10,880 points
5 views
0 votes
0 answers

How to launch Amazon Shopping app in Android app?

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

3 days ago in Android by Ashwini
• 2,760 points
7 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,022 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,100 points
1,656 views
0 votes
1 answer

Is there a way to run Python on Android?

YES! An example via Matt Cutts via SL4A -- "here’s ...READ MORE

answered Sep 19, 2018 in Python by Priyaj
• 58,100 points
465 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,630 points
422 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 in Android by Edureka
• 10,880 points
30 views
0 votes
1 answer

How to display Toast in Android?

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

answered Nov 8 in Android by Edureka
• 10,880 points
36 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