Unity IAP doesn't consume consumable acknowledged purchases

Good to hear! Can you describe your configuration and transaction flow? I’m planning to set up a server similarly myself as these questions are becoming more common. If you could provide the specific syntax that you are using on the server, that would be helpful, perhaps send in a private message. Or anyone else on this thread, same request. I’ll ensure to test your code with upcoming releases.

Hi @JeffDUnity3D !

Can’t go over the details too much, but basically the flow can be summarized this way:

UNITY CLIENT

  • Unity IAP processes the purchase
  • we perform local receipt validation using Unity IAP
  • we send all the details (including receipt) to the server, and set the transaction as Pending

OUR SERVER (.NET)

  • we validate the receipt using Google.Apis.AndroidPublisher.v3.AndroidPublisherService.Purchases.Products.Get
  • we assign proper rewards to user
  • we consume purchased consumable using Google.Apis.AndroidPublisher.v3.AndroidPublisherService.Purchases.Products.Acknowledge

Hope that helps!

Yes, I understand the flow. I was offering to test your code, but that’s ok.

so what happend in non consumable

Hello there !

I haven’t tried this before, but i have some question about acknowledged on server side.

Lets say client have receipt on game, and then send it to server and set it pending on game. Server check receipt on Google API, after that server give the currency to client on database, and then server acknowledge to Google API. And server give return to client ‘success’.

So what client should do on after server give return success? its still need to invoke ConfirmPendingPurchase() or its will automaticly confirmed after server acknowledge on server ?

Thank you.

Automatically acknowledged, ConfirmPendingPurchase should not be needed. Please test and confirm.

Thank god i found this article, I’ve been struggling with this for a while. Acknowledgment on client after your have given the user the items and validated on servers seems pretty strange. If your dealing with any other payment gateway you process server side and only confirm success client side.

Thanks for unity for listening to its users, that was a long read :smile:

2 Likes

Can you elaborate? You don’t award an IAP product unless it’s been validated on the server. Keep in mind that “validation” on the server is much different than “acknowledged” on the server. Validation only confirms a valid receipt, Acknowledge is done on the server via the Google billing API and completes the transaction and sets purchaseState = 1. If acknowledged on the server, it’s not necessary on the client, we pick up that status. A customer can do none, one or both on the server. This flow is dictated by Google, not Unity IAP. We are only a pass-through service for the client Google Play Billing Library.

I completely understand the difference, i was just saying once the receipt has hit my server, i would want it to be validated and acknowledged server side because at that point they have access to their items/purchases. If for some reason the response from the server to client fails, it really doesn’t matter because its been validated and acknowledged e.g User quits, client doesnt receive response to acknowledge, logs in on different device has access to the goods, order still hasnt been acknowledged and then gets cancelled.

To get around this i would have to implement further checks and validation to see if it has been acknowledged after the payment process which in all my years of developing ive never had to do.

Process for server side implementation should always be Client (Payment Details) → Server (Confirm - Take Payment) → Clients (gets a success or failure.)

The reason i was a little stuck was i thought i had to follow this pattern of acknowledgment client side.

1 Like

Yes, if for some reason the response from the server to client fails, it really doesn’t matter because its been validated and acknowledged. That is the current behavior. The (server-side) acknowledgement goes to the Google servers and the receipt and transaction is marked as such, not back to the client. The client behavior is basically “fire and forget”. Yes, if your server fails to acknowledge to the Google servers, the transaction is not complete and the product should not be awarded. The user can quit at any time without issue. If they log on again (same or other device), the transaction is still in process as you would expect, and you would want to try your server acknowledge again. Are validating and acknowledging on your server? What Google API are you using?

So as of now, I’m validating server side using (https://github.com/voltrue2/in-app-purchase) its a little old but I’ve brought it up to date. However this doesn’t include Acknowledgment of the receipt so as of now I’m still having to acknowledge client side, i just really don’t like it, i guess its just preference. After reading this i now know i don’t have to acknowledge client side and can implement my code server side.

Like i said i assumed i had to follow the docs and had to acknowledge client side, that’s all and from what I’m reading there used to be issues with it but now you guys fixed which is great.

Unless your game is multiplayer and allows multiple game logins by the same physical user, there is rarely a need to acknowledge server-side.

Its not multiplayer but we use our own accounts and is cross platform meaning purchases on PC/Mac/Linux are global on the account. So although the purchase is on your Google Play account, we don’t use Google play to retrieve purchases, we use our own database. We basically use it for the payment gateway everything else we manage our self. So once that data for the purchase is in the Database that should be validated and acknowledge without having to send back to client (unity) to acknowledge then check again on server then add the items to db, the user shouldn’t get nothing until its acknowledged.

Little bit of background:
We developed an app in node/VueJS, but we want to move over to unity but keep most of the infrastructure in place (Database, APIs etc) as we have existing customers with purchases etc. So in order to mirror the existing process and follow other payment gateways (Stripe, PayPal) we need to incorporate a similar payment flow. Which is

Out existing system (which we want to implement IAP with)
Client (Enter Payment) → Server (Take Payment - Give Goods) → Client (Gets nothing but a success or failure boolean).

Google/*Unity way
Client (Enter Payment) → Server (Validate) → Client (Take Payment) → Server (Give Goods) → Client (Success or Failure).

I’m not even sure of the reason you would validate server side if it can still fail and not be acknowledged step is kind of pointless. Its like validating the payment can be taken but might not be. Unless im completely missing something here.

Sorry, you were asking about validating server side? Now you are asking why it’s needed? Of course it can still fail, just like any software. I don’t follow your “pointless” comment. There is nothing to “send back” to the client, this is all done on your server->Google. The following step is not necessary “without having to send back to client (unity) to acknowledge then check again on server then add the items to db, the user shouldn’t get nothing until its acknowledged.” If you have acknowledged on your server, then you don’t need to do it again on the client. If your server->Google call fails, then you’ll need to retry which is up to you. The client will see it hasn’t been acknowledged, and should retry the server acknowledgement as I mentioned. Are you actually seeing this behavior? Or are you trying to understand the flow before implementing your solution.

Your massively misunderstanding, the whole topic was about acknowledgment server side which I’m not currently doing as i thought i had to do it client side. The only thing im doing right now is Validating (Which is pointless). Which is why I’m here found this article and i now know i can also do this server side without interfering with Unity IAP.

My point about validating server side is why only do the validation if it can still fail after that step. If your using a server side implementation at all you would always want to Validate & Acknowledge. If you do both, you can safety add to DB, give goods with no other steps. You cant just Validate and add to DB and give items for it then to be unacknowledged and cancelled.

Using this guide, at what point would you personally give your clients the items. Because its not until Step 8/9 the card is charged (although the graph says otherwise, this is confirmed by a unity dev on another post). Because its not until step 8/9 you confirm the pending purchase.

image

@markmozza This is how Unity IAP works also: Client (Enter Payment) → Server (Take Payment - Give Goods) → Client (Gets nothing but a success or failure boolean). Although your server cannot “take a payment”, all actual payments occur securely on the device. Validating the receipt on the server is much more accurate than doing so on the client. Look at the “Important” comment here Unity - Manual: Receipt validation Yeah I believe that chart is not accurate, the credit card is not charged until it is acknowledged and the transaction is finished. If you return Pending from ProcessPurchase, the credit card is not charged

1 Like

Okay simple put.

I know what i have to do now to fix all my issues i don’t have an issue anymore. However none of your documentations or graphs point to the flow without acknowledgment server side, which you don’t mention in them docs, you only mention validating the receipt. The code example i provided and use for server side validation was also on the Unity docs page. This also doesn’t even point to the below flow.

Client (Enter Payment) → Server (Take Payment - Give Goods) → Client (Gets nothing but a success or failure boolean).

The only flow i see here without Acknowledge server side is:

Client (Enter Payment) → Server (Validate Receipt - Payment is not taken here) → Client (ConfirmPendingPurchase - Take Payment) → Sever (Give Goods) → Client (Shows Success or Failure)

Which is why i thought i had to do it this way.

1 Like

Got it! Yes, when that image was created about 6 years ago, server-side acknowledgement had not been tested yet.

Sorry for the confusion. I don’t explain myself well. I never really looked up the Google API or Apple etc i just seen Unity IAP does everything we want and decided to use it. I’ve based the entire flow off Unity when i should of really looked up the Google API to understand what was possible.

I believe the Unity IAP is very impressive and has saved us a bunch of time.

Thanks for your help!

1 Like

You are welcome! We are working on improved server-side support also, so stay tuned! Hopefully by Q4 of this year. It’s becoming a popular topic, so you are definitely not alone. The IAP transaction flow for server support is not trivial

2 Likes