Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Processing Purchases, confirming purchase flow

Discussion in 'Unity IAP' started by MatL, Sep 29, 2021.

  1. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    On purchase flow Saving purchases to the cloud

    We are giving the purchased item on step 6, suppose that the app disconnects before step 7, and the purchase remains in a pending state. When the user loads the game again ProcessPurchase(step 4) the app sends the same receipt(step 6), and on step 7 the app server sends the app a duplicated receipt message, then the app does step 8 that works fine.
    But what happens If the user doesn't load the game for a few days, the purchase is going to be declined and after that, he can load the game again and is going to have the purchased item is that correct?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I don't believe you want to award the product in Step 6? I believe it would be Step 9. Are you doing server side product fulfillment? You would want to test your scenario.
     
  3. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    Yes, I am doing server-side product fulfillment, Step 9 is between Unity IAP and App Store, I guess I can do it after calling ConfirmPendingPurchase on Step 8, but if I do that is also possible to have server or connection problems, in that case, the user would not get the purchase but would we charge, defeating the propose of this flow, is that correct?
    Thanks for the help.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you elaborate "we charge"? IAP transactions are handled by the respective stores. To understand your flow better, I assume you associate these purchases with a game user login, correct? So if I bought a product on the Android version of the game, I would also own it on the iOS version? If you are doing server-side fulfillment, I believe you want to acknowledge on the server with the Google API, so no need to call ConfirmPendingPurchase on the client. And an exception in the flow as you suggest should not defeat the purpose for the general case. At any rate, I would encourage you to test your flow.
     
  5. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    I mean that If we do the fulfillment after ConfirmPendingPurchase the user would be charged but if there is a server error after that he would not get the item.

    You are right in your assumption that when a user login would own it on Android and IOS on our game. Making the acknowledge on the server and not calling ConfirmPendingPurchase on the client makes sense. I didn't saw a flow on unity documentation doing that. Can you confirm that flow is supported by Unity IAP?

    I am confused about why our use case is different than the doc flow "Saving purchases to the cloud "and how would avoid the issue that I described if doesn't do acknowledge on the server.

    Thanks again!
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    May I ask, where did you obtain that flow diagram? It doesn't look like a cloud save flow. It looks more like server-side receipt validation flow (only).
     
  7. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    On the IAP documentation here on "Saving purchases to the cloud"
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    That is a bit different flow and would not work across device types. For your scenario, you typically would acknowledge on the server not the client. Again, please test to confirm.
     
  9. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    Ok, thanks, I saw this related thread, so can you confirm previously was not supported doing the acknowledge on the server-side but now is supported starting from Unity version 3.2.3? You should probably add that to the documentation since is a lite confusing, I just don't understand in what scenario the flow "Saving purchases to the cloud" would work, is always going to have those issues.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I suspect it would work for Google only or iOS only, but not both. Agreed on the documentation! And I'm not clear what issues you are referring to, you haven't stated an error or otherwise. I personally have not implemented server-side save and is why I'm encouraging you to test. You are suggesting an error flow when the success flow has not been confirmed yet.
     
  11. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    The flow "Saving purchases to the cloud" on the documentation is not for server-side save? I am probably missing something.

    On testing yes sure I will test it but there are a lot of possible situations that can happen if you combine ios and android, delayed credit cards validations, wrong receipts, network problems, server problems, etc and since is a really crucial feature I just don't want a case fall to the cracks. Furthermore, it can work fine now and on a new IAP update break since I don't know if is the intended case of the library, is really bad if this breaks.
    Is important to know-how is the intended use case flow of unity IAP for fulfillment on the server-side, it seems a pretty normal use case for the library.
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The documentation appears to need updating was my point, apologies on the confusion. You are discussing error conditions, my suggestion is to get the expected flow working first. How are you acknowledging the purchase on the server with the Google API (for example), as in the link you shared? They are not using ConfirmPendingPurchase is my understanding, that is done on the server. For my understanding of your design, I suspect you are using a hash of the username as a primary key in a database on your server? I must admit that I have not tested server side save, so I may ask for other forum members to hopefully chime in here. This feature is on our roadmap.
     
  13. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    My current flow is just returning PurchaseProcessingResult.Complete on onProcessPurchase, it works fine but not ideal because the server may have an error when doing the fulfillment, that's why I wanted to change the implementation to the suggested flow on the doc of "Saving purchases to the cloud" I thought that was for our situation on server-side save. So if the documentation is no longer valid, I will wait until is updated before changing that or is confirmed by the unity team that is supported. Thanks!
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @MatL It is supported, please try it. That diagram does not reflect server side acknowledge and is what 3.2.3 addresses. If you are not calling a store API as mentioned in the thread you linked, then the image is accurate. And again, how are you doing the fulfillment across multiple devices and possible OS's per user? I had asked if you are using a username hash. Also, instead of rolling your own solution, you might consider PlayFab or ChilliConnect cloud save options.
     
  15. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    I am doing the fulfillment using the user id, that is generated the first time that the user logs into the game, he then has an option of creating an account for having the purchases on other devices. Thanks, we will do the acknowledges on the server and remove it from the client if is supported.
     
    JeffDUnity3D likes this.
  16. MatL

    MatL

    Joined:
    Jan 29, 2014
    Posts:
    43
    It looks that I had a mistaken concept that caused this confusion, for example on android you need to acknowledge and consume a purchase. So the referenced flow seems accurate and applies to our case. You acknowledge the purchase on step 7 and make the fulfillment, from that moment the purchase is not going to be declined, and after that, you do Step 8 that consumes the purchase.