Getting purchase token for a paid app from Google Play
Asked Answered
B

1

8

We need to associate information about the app purchase with the user on our servers. For in-app products, this is easy to do because we can receive the purchase token.

How to achieve the same functionality for a paid app downloaded directly from Google Play? We cannot find a way to receive an order id or purchase token to record on our servers.

Bin answered 31/5, 2019 at 14:15 Comment(3)
haven't you access to an identifier of your clients buying your app ?Harrison
@axelaxel if you could let me know how we can get an id/email of the person who bought the app, it would solve our problems. Unfortunately, we are not aware of such methods. It's possible to get a list of accounts connected to Google Play on the device. However, no way to pinpoint which one actually bought the app.Bin
Have you found a solution? I bumped into similar problem, when user resumes expired subscription within google play itself - just new payment with new token is created. And I have no idea how to connect it to backend user.Phonate
S
0

I came across this and your question while researching a problem of my own. I think this might be what your looking for:

Developer payload is supported

2.0 of the Google Play Billing library adds support for developer payload—arbitrary strings that can be attached to purchases. You can attach a developer payload parameter to a purchase, but only when the purchase is acknowledged or consumed. This is unlike developer payload in AIDL, where the payload could be specified when launching the purchase flow. Because purchases can now be initiated from outside of your app, this change ensures that you always have an opportunity to add a payload to purchases.

To access the payload in the new library, Purchase objects now include a getDeveloperPayload() method.

Note: You cannot modify a payload after it is assigned.

And here is some sample code:

Consumable

BillingClient client = ...
ConsumeResponseListener listener = ...

ConsumeParams consumeParams =
    ConsumeParams.newBuilder()
        .setPurchaseToken(/* token */)
        .setDeveloperPayload(/* payload */)
        .build();

client.consumeAsync(consumeParams, listener);

Non-consumable

BillingClient client = ...
AcknowledgePurchaseResponseListener listener = ...

AcknowledgePurchaseParams acknowledgePurchaseParams =
    AcknowledgePurchaseParams.newBuilder()
        .setPurchaseToken(/* token */)
        .setDeveloperPayload(/* payload */)
        .build();

client.acknowledgePurchase(acknowledgePurchaseParams, listener)
Sill answered 12/6, 2019 at 1:37 Comment(1)
You mention Google Play Billing library which is used to sell in-app products. But we can track in-app purchases using purchase tokens and order IDs. The question is how we can track downloaded apps which are purchased in Google PlaySloganeer

© 2022 - 2024 — McMap. All rights reserved.