Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feedback Server Receipt Validation using PlayFab

Discussion in 'Unity IAP' started by DamonJager, Feb 17, 2022.

  1. DamonJager

    DamonJager

    Joined:
    Jul 16, 2015
    Posts:
    56
    I'm looking to integrate Playfab and coded Unity IAP. I'm starting to really look at the code implementation, and I stumbled at this example given by PlayFab:

    https://docs.microsoft.com/en-us/ga...conomy/getting-started-with-unity-iap-android

    I've not tested it yet, and I would guess it would work since it's in the docs. The problem is that it never returns PurchaseProcessingResult.Pending and that's not compliant with Unity's recomendations to integrate to systems with Server Receipt Validations (https://docs.unity3d.com/Packages/com.unity.purchasing@4.1/manual/UnityIAPProcessingPurchases.html). It seems it locks the app until it sends PurchaseProcessingResult.Complete() (after it calls PlayFabClientAPI.ValidateGooglePlayPurchase). What issues could arise from this?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    @DamonJager You can return either status, depending on your requirements. Generally you would only return Pending if there was a server failure or delay. I'm not sure what you meant by "seems it locks the app", these are asynchronous calls with appropriate callbacks so you app should never be locked. If there was a server problem, you return Pending from ProcessPurchase and don't award the product to the user. When the user launches the game later, since the transaction is still in Pending, then ProcessPurchase would be triggered during IAP initialization and you would retry the server validation.
     
  3. DamonJager

    DamonJager

    Joined:
    Jul 16, 2015
    Posts:
    56
    It would make sense it's asynchronous. Though that rises more questions:

    As of what I'm interpreting it's a transaction with an async component that's outside of it (the playfab component). It would fail in some edge cases: Such as the server suddenly fails and the items are not given to the player, and the player is charged. I would hope that it's logged and treated through automation or customer support.

    Another edge case would be that the transactions isn't closed for some reason with the store: that is, the PurchaseProcessingResult.Complete isn't processed with the store, and the items are given to the player (that is, if playfab could validate the receipt even though it's in a pending state). Would this be treated as a pending state of the purchase? Should ask them about how PlayFabClientAPI.ValidateGooglePlayPurchase() internally works?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You are assuming issues that likely don't exist, and using terms like "for some reason". I would suggest that you get it working for 99.95% of the cases that would follow the success path and not delay your development for issues that don't yet exist. If the purchase is left in Pending, there should be no issue, as mentioned. If Complete didn't finish, it would still be in Pending. Keep in mind that receipt validation on it's own is a read-only operation, it doesn't change the transaction state. Unless you (or they) are calling additional PlayFab APIs that in turn call the Google APIs. We haven't heard of any reports of other behavior as you suggest.