Sergio Ballestero
Sergio Ballestero

Reputation: 61

Android subscriptions getPurchases

I am using subscriptions in my app and for testing purposes I am using a test developer that buys test subscriptions.

I have bougth a three month subscription to my app with that test developer. After that, I cancelled that subscription from my user's account (wich basically means setting renewing=false). Once I cancelled the subscriptions, I am able to buy it again from the app (it's supose to "merge" the subscriptions and delay your expiry time. For example if a had a month left and buy thre more months my new wxpiry date should be in four months).

When I invoke the method getPurchases() the same purchase I got on the firt time I bougth data is returned (nothing has changed, not the token, not the purchase date).

When I use this data to do a request server to server with google developer API (The only away I know to request for the expiry date), the expiry date returned is in the past. So if I do some bussiness logic, I have to consider that subscription expired, but nevertheless it's the data I am receiveing from GooglePlay when I query getPurchases(). And in the documentation it says "The getPurchases() method does not return failed or expired subscriptions."

So, what I am thinking it's that when I bougth for the second time, a new purchase data must have been generated, with new token to query server to server, but I am not receiving it.

Any ideas about what could be happening?

Also I would like to know where can I see these orders in my google account, because I have checked in my merchant account I don`t see them. Thanks!

Upvotes: 2

Views: 1073

Answers (1)

straya
straya

Reputation: 5059

Given 3 years have passed, I assume you were using Google In-App Billing v2.

Nevertheless, problems remain in v3 (at least for the sandbox/test accounts) and syncing. You can really only depend on Google In-App Billing v3 API (GIABAPIv3) to provide you with a new purchaseToken and developerPayload upon successful completion of the payment popup flow. purchaseData returned by getPurchases may not be in sync with reality*, as I have often observed. Furthermore, the behaviour of the GIABAPIv3 popup flow may not be in sync with reality*.

It is possible for GIABAPIv3's purchaseData to reflect the wrong isAutoRenewing state and for GIABAPIv3 popup flow too! For example, a subscription may be cancelled (and expired) in reality* but both GIABAPIv3 and it's popup indicate that the User remains subscribed. In such cases, it seems cancelling again (via Google Play app) helps encourage GIABAPIv3 to get in sync.

"The getPurchases() method does not return failed or expired subscriptions."

Contrary to that, getPurchases will return data for 'cancelled' purchases. Strangely, the GDAPI expiryTime will be changed from what had been the normal subscription end to the time at which the purchase was cancelled. So in order to achieve the desirable behaviour whereby your app continues to treat the User as subscribed until the subscription end, your server will need to remember the original expiryTime. If expiryTime < subscription end then it indicates that the purchase got cancelled (and you should expect GDAPI's AutoRenewing to also have changed to false). https://developer.android.com/google/play/billing/billing_integrate.html "The call returns a Bundle with all the active subscriptions owned by the user. Once a subscription expires without renewal, it will no longer appear in the returned Bundle." This leads me to conclude that Google have used the word 'expires' above and the field name expiryTime poorly, they are not entirely related (expiryTime will represent the time of cancellation if that happens, and the true expiry (subscription end) won't be available via GDAPI - one must remember it or infer it via the absence of that purchase in GIABAPIv3^).

*reality here is in accordance with what the human User has done and what the Google Developer API (GDAPI) says.

^I can't say I've seen that happen, which might be a symptom of sandbox/test's daily reset. I've seen a cancelled and expired subscription in reality* continue to show up in GIABAPIv3 for days after (only re-cancelling in Google Play app yielded a sync back to reality*).

Upvotes: 2

Related Questions