android / play-billing-samples

Samples for Google Play In-app Billing
Apache License 2.0
2.38k stars 1.34k forks source link

Even if the user has refunded, it still recognizes the purchase. #224

Open githubsoooh opened 5 years ago

githubsoooh commented 5 years ago

`Inventory() { }

/** Returns the listing details for an in-app product. */
public SkuDetails getSkuDetails(String sku) {
    return mSkuMap.get(sku);
}

/** Returns purchase information for a given product, or null if there is no purchase. */
public Purchase getPurchase(String sku) {
    return mPurchaseMap.get(sku);
}`

The user refunded, but getPurchase returns a non-null value.

fab327 commented 4 years ago

I agree with @githubsoooh , Digging into the code v2.0.3, it reads the following:

/** Returns the state of purchase. */
  public @PurchaseState int getPurchaseState() {
    switch (mParsedJson.optInt("purchaseState", PurchaseState.PURCHASED)) {
      case 4:
        return PurchaseState.PENDING;
      default:
        return PurchaseState.PURCHASED;
    }
  }

There is basically no way of handling canceled/refunded purchases...

timalsoon commented 4 years ago

I confirm also that I reached the same issue. When this issue can be fixed ??

gabrielepmattia commented 4 years ago

Do necessarily we need a backend server? It seems that the item must be consumed after refunded, this is not documented but found on stackoverflow [1] [2]

gabrielepmattia commented 4 years ago

It seems that purchases and other information queried are cached, so after refund, if you do not want to implement your own purchase check with a backend, you have to wait that BillingClient cache is automatically reset.

I think that this issue can be closed

adrcotfas commented 3 years ago

What if we don't want to use a backend to check refunds/cancelled purchases?

I found a workaround and wrote the details here: https://issuetracker.google.com/issues/73982566#comment62 Can you folks working on the Billing Library confirm if this is safe or not until you'll provide a real solution?

Enstone commented 1 year ago

+1

fbongcam commented 4 months ago

Also wanted to check this with a built in method but sadly seems to not exist. What I came up with is checking if the purchase has been acknowledged, if it's not acknowledged its basically awaiting a refund.

In case it has been acknowledged and the purchase state is 0, I think you can consider it refunded. Otherwise the purchase state would return 1 if it still was registered as a purchase.

jpgpuyo commented 1 month ago

+1