Android in-app purchase: how to consume?

I implemented Google In-App Billing V3 in my application and I made my first test purchase. Now, as you can see, I want it to be consumed, but if I press the Buy button again, I get an error, I wonder how and where to insert the consumePurchase. I worked all day on a computer search in each thread, but I am confused with older versions of the same. From what I saw, I need to call consumePurchase after a successfully purchased item. And when the action is created, but I can’t figure out how to do it.

Is this the only line of code?

int response = mService.consumePurchase(3, getPackageName(), token);

If so, what is a token?

Ps consumables: 50, 150 and 300 coins that the user can buy to get a slight advantage in the game.

Ahh, so confusing for me: /

+4
source share
2 answers

As stated in the white paper: https://developer.android.com/google/play/billing/billing_reference.html

In response to the purchase, several fields are included, one of which:

INAPP_PURCHASE_DATA String in JSON format that contains details of the purchase order. See Table 4 for a description of the JSON field.

Inside JSON, you have several fields also explained on this page, the one you are looking for is:

purchaseToken A token that uniquely identifies a purchase for this item and a pair of users.

, , .

+4

, . :

int response = mService.consumePurchase(3, getPackageName(), token); 

:

mService.consumePurchase(3, packageName, purchaseToken) RESULT_DEVELOPER_ERROR = 5 - , API

+4

Source: https://habr.com/ru/post/1541901/


All Articles