Google In-app-purchase: How to check if a consumable product purchase status is pending?
Asked Answered
C

1

8

I have integrated android In-App purchase to an android application. I overridden the onPurchaseUpdated method to get the response of the purchase.

@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
    if (responseCode == BillingResponse.OK) {
        //handling purchase logic here
    }
}

Now I noticed an user tries to purchase an in-app consumable product and while his purchase status is on pending, after some time he cancels the purchase. He is repeating this process over and over again.

So if the purchase status is on pending, does the google returns BillingResponse.OK as response code? If not how to check if the purchase status is on pending or what happens when a purchase is on pending?

I looked about the response code in google play billing reference doc, but found no information about pending purchase.

Here is the link: https://developer.android.com/google/play/billing/billing_reference.html

Candent answered 4/4, 2019 at 5:42 Comment(1)
I need answer to this questions too. What is the response code when payment is pending or chargeable status?Josefinejoseito
M
0

I couldn't find the exact solution but there is a workaround(quite reliable) using real-time developer notification to handle subscription related status:

You should start with the following guide: https://developer.android.com/google/play/billing/billing_subscriptions#Handle-states

and then following guide to Add real-time developer notifications: https://developer.android.com/google/play/billing/realtime_developer_notifications

So basically it notifies you when the state of any play managed subscriptions change,you will get flags like,SUBSCRIPTION_RENEWED,SUBSCRIPTION_PURCHASED,SUBSCRIPTION_CANCELED etc in that push notification.

So what you can do is add all subscription entries to your server(or however you manage it) as pending and handle all the updates using real-time developer notifications.

For example: User A renewed a subscription but payment confirmation might take 24 hours so you have that entry as pending(by default) and in between user decides to cancel that subscription so you might receive a flag of SUBSCRIPTION_CANCELED and again user decides to revoke that account so you might get a flag of SUBSCRIPTION_REVOKED,you can update your entry as user repeats this process over and over.

This might seem a bit confusing but reading the docs might clear the way.

Hope this helps,Let me know the outcome.

Miscarry answered 12/4, 2019 at 14:54 Comment(2)
Thanks for the reply. I'm facing the issue for consumable products only. Your approach is valid only for subscriptions.Josefinejoseito
can i get the similiar response wihtout real-time developer notifications ?, like with queryPurchases() ?.Caskey

© 2022 - 2024 — McMap. All rights reserved.