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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Deferred Purchase

Discussion in 'Unity IAP' started by mateuszjaworski, Aug 16, 2021.

  1. mateuszjaworski

    mateuszjaworski

    Joined:
    Aug 8, 2019
    Posts:
    12
    Hi,

    Lately I've received a lot of reports regarding issues with payments. We started testing payments with slow card and it seems like our game gets stuck right there. I've seen some posts on this forum that say this option does not work on google side. Is that still correct? In any case, I've also noticed that in IGooglePlayStoreExtension you can find IsPurchasedProductDeferred method and in extension we can use SetDeferredPurchaseListener. Apple has kind of similar thing in IAppleExtensions, there is RegisterPurchaseDeferredListener. My question is what is the right way to use them? I didn't find clear asnwer anywhere. After I register my listener when does it get called? During the same session as soon as it gets resolved? Or does it get triggered only when I restart my app? What is the right way to handle that? Should I ConfirmPendingPurchase in DefferedListener callback or only after I get success or fail result?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Until the user pays for a deferred purchase, the purchaseState = 4 in the receipt. Until purchaseState = 1, you'll want to return Pending from ProcessPurchase. You should take no action in the deferred listener, unless you just want to alert the user "We received your purchase intent" or similar. This code shows how to check https://forum.unity.com/threads/google-play-iap-problem.1140367/#post-7351220
     
  3. mateuszjaworski

    mateuszjaworski

    Joined:
    Aug 8, 2019
    Posts:
    12
    @JeffDUnity3D Ok got it, check purchaseState in receipt. I assume the first receipt I get is going to have purchaseState = 4, but what then? Does PurchaseSuccess get called at some point during the same session and I get another receipt with purchaseState 1? Or does it happen after game restart? Or maby I should check something periodicaly to find out when that receipt has changed its' purchaseState?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    ProcessPurchase triggers when the game starts and IAP initializes for any products still in purchaseState = 4. Just continue to return Pending from ProcessPurchase until purchaseState = 1, perhaps a couple of days later when they start the app again. Return Complete at this point, and award the product to the user.
     
  5. mateuszjaworski

    mateuszjaworski

    Joined:
    Aug 8, 2019
    Posts:
    12
    Thanks, I'll try that!
     
  6. AppSD

    AppSD

    Joined:
    Feb 9, 2021
    Posts:
    11
    I am unable to see purchaseState for Apple receipt. How do I check deferred purchase state for Apple in ProcessPurchase? Thanks.
     
  7. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    603
    You can refer to here to implement Apple's "Ask-to-Buy" feature: https://docs.unity3d.com/Manual/UnityIAPiOSMAS.html
     
    Petr777 and AppSD like this.
  8. AppSD

    AppSD

    Joined:
    Feb 9, 2021
    Posts:
    11
    Does the purchase button need to be disabled when the purchase is pending? Would Unity IAP misbehave if the button can be clicked during the pending period?
     
  9. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    603
    I think you don't have to disable the purchase button. If a player clicks the purchase button to purchase a pending product, we will call the store's purchase API and the store will handle this situation.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, you would likely receive a "Duplicate transaction" error if another purchase was attempted while the original is still in Pending.