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

Unity IAP 4.1.0 automatic fetching of purchases at initialization

Discussion in 'Unity IAP' started by justtime, Oct 18, 2021.

  1. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    422
    @JeffDUnity3D
    4.1.0 Release notes
    Code (CSharp):
    1. IGooglePlayConfiguration.SetFetchPurchasesAtInitialize(bool);
    2. IGooglePlayExtensions.RestorePurchases(Action<bool>);
    Hi there! Could you clarify in which cases this feature is used?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    justtime likes this.
  3. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    @JeffDUnity3D

    1. If I don't call SetFetchPurchasesAtInitialize, What is default setting for SetFetchPurchasesAtInitialize?

    2. If I call SetFetchPurchasesAtInitialize(false) then, Unity IAP doesn't call automatically ProcessPurchase for RestoreProduct on initialize timing. Is it right?

    3. What about Pending Purchase? I think PendingPurchase need to specify the timing as well. It called automatically on initialize
     
    Last edited: Nov 15, 2021
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    1) If you don't set it, I believe the default is true. 2) Correct 3) I would need to test, what are you seeing?
     
  5. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    @JeffDUnity3D

    3) When I call SetFetchPurchasesAtInitialize(false), ProcessPurchase didn't bring the Pending Product.
    So I could not access it forever. I think it should have been added that Handle Pending Products.
    We need to distinguish Restore and Pending Purchase.
     
    Last edited: Nov 16, 2021
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it! I don't think there is a way to distinguish the two.
     
  7. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    So, Could you add an API to new version
     
  8. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    @JeffDUnity3D

    Hope that I can get RestoreProducts and PendingProducts though other API instead of ProcessPurchase.
    It must be uncomfortable to distinguish each other...
    Plz we need some clarification!
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    There does not look to be an API. They always come through ProcessPurchase. However, you can manually inspect the receipt, and look at the purchaseState property. Restored products should have value of 1, Pending 2.
     
  10. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    @JeffDUnity3D

    Yeah I already inspected receipt manually, but It's wired that UnityIAP supports only RestoreProduct API.

    And, Pending purchaseState is 0, not 2.
     
  11. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    According to this, Pending = 2 https://developer.android.com/reference/com/android/billingclient/api/Purchase.PurchaseState. We are a pass-through service for the Google Billing API v3. Which specific API are you referring to? And we do support Pending. If a product is in Pending state, ProcessPurchase will be called.
     
  12. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    1) Thanks to share the link. I read the document. But, The PurchaseState I saw on test was 0.
    (I pend the product then did not confirm it.)
    What does exactly mean UNSPECIFIED_STATE ?

    2) I know UnityIAP support Pending. But There is only way to inspect manually the receipt.
    Otherwise, IGooglePlayExtensions.RestorePurchases can control the timing and doesn't have to inspect something.
    I suggest an API which is able to control PendingProducts.
    For example IGooglePlayExtensions.HandlePendingPurchases.
    And
    IGooglePlayExtensions.GetPurchaseState(Product product) or IGooglePlayExtensions.IsPendingProduct(Product product) for distinguish product from ProcessPurchase
     
  13. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    Here is my sample code.

    At first, I pend the product. then reboot the app, I checked the product from ProcessPurchase after Initialize UnityIAP.
    As you know, Google Document said pending is 2.
    I expected 2 as well. But purchaseState still is 0.


    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
    ValidatePurchase(args.purchasedProduct); // Backend validation
    return PurchaseProcessingResult.Pending;
    }
     
  14. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    I don't think I'm following your issue. So you are saying purchaseState = 0 is behaving as Pending? What if you just make that assumption? And where are you calling ConfirmPendingPurchase? You are welcome to call those extension methods, this may help https://forum.unity.com/threads/google-play-iap-problem.1140367/#post-7351220 and https://docs.unity3d.com/2017.1/Doc....IStoreController.ConfirmPendingPurchase.html
     
  15. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    @JeffDUnity3D

    Plz answer it
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You mean UNSPECIFIED_STATE? That is a Google status, we just pass it along. Hopefully they will make it more clear with Google Billing Library v4 coming out soon.
     
  17. leet_unity

    leet_unity

    Joined:
    Oct 15, 2021
    Posts:
    10
    Thanks to your answer.
    I read another document said like this.

    The purchase state of the order. Possible values are: 0. Purchased 1. Canceled 2. Pending


    So, I thought if the receipt string came from Google API Server, '0' may mean 'Purchased'.

    What is the right thing? Here is the document link.

    https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products
     
  18. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Agreed, Google has been a bit confusing. I have not seen this link.