Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Detecting a finished purchase as one that was deferred?

Discussion in 'Unity IAP' started by matt_clarke, Jan 4, 2019.

  1. matt_clarke

    matt_clarke

    Joined:
    Aug 30, 2016
    Posts:
    4
    Hi,

    Is there a way to detect that a purchase which was returned to an IStoreListener via ProcessPurchase() and OnPurchaseFailed() is one which was originally deferred?

    The issue we're having is that the following can happen:
    • Device A: Initiates a deferred purchase for "Product A"
      • We lock the UI whilst the purchase is active
      • We receive a callback indicating the purchase has been deferred and show a popup indicating this
    • Device A: Starts a second purchase for "Product A" (and leaves the native purchase flow open)
      • We block the UI whilst the purchase is active
    • Device B: Confirms/declines the purchase of the first item
    • Device A: Receives a call into ProcessPurchase()/OnPurchaseFailed()
      • We think that the second purchase has completed (by checking the product id), so we unlock the UI (even though actually it was the original deferred purchase and the native purchase flow is still active)
    I've noticed that IStoreController.InitiatePurchase() has a payload, although I'm presuming this is only returned when a purchase is actually made. I've also tried to check the 'transactionID' of the Product which is returned for deferred purchases and that is empty (which makes sense really, just clutching at straws here).

    • Unity Version
      • 2018.2.3f1
    • Unity IAP version
      • 2.0.3
    • Platform you are building for
      • iOS

    Thanks,
    Matt
     
    Last edited: Jan 4, 2019
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,130
    Please define a "deferred" purchase. Also, you are discussing two separate devices? Please elaborate, how would Device B "confirm" a purchase on Device A? Are these for the same user? If this is for a consumable, any number of purchases by the same user are allowed.
     
  3. matt_clarke

    matt_clarke

    Joined:
    Aug 30, 2016
    Posts:
    4
    Sorry, I should have elaborated more about the deferred purchases. This is an iOS specific feature, where a request can be sent to a parent's device which can then approve/decline the purchase (with a window of 24h). When the purchase is approved or rejected, the ProcessPurchase() or OnPurchaseFailed() functions on our IStoreListener are called.

    It's detailed on this page under the heading "Ask to Buy": https://docs.unity3d.com/Manual/UnityIAPiOSMAS.html
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,130
    This sounds like an edge case, but regardless, can you elaborate what the actual problem is? The user receives the product, correct?
     
  5. matt_clarke

    matt_clarke

    Joined:
    Aug 30, 2016
    Posts:
    4
    It is an edge case, I'm having to think a lot around edge case issues that deferred purchases can cause. I was mostly wanting to check there wasn't something I'd missed which could easily avoid this.

    The user would receive the product, the purchase flow for the second item would still be active and we wouldn't be able to detect that. There would be a small time window after the purchase completes where you'd be able to navigate around the app, potentially to an area where we can't show the rewards.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,130
    Sorry, I don't quite follow. Would not the second purchase also require deferred approval? Can you not disable buttons until the purchase flow is complete, to avoid a second purchase, as you've stated? Is this an issue that your users are complaining about?
     
  7. matt_clarke

    matt_clarke

    Joined:
    Aug 30, 2016
    Posts:
    4
    No problem.
    • Would not the second purchase also require deferred approval?
      • I'm not 100% sure on this. It depends what happens to the existing requests when you disable it on the device, whether any pending requests are cleared or if they remain. Are you thinking that we could use that to know that in the first example it was the first purchase completing?
    • Can you not disable buttons until the purchase flow is complete, to avoid a second purchase, as you've stated?
      • We are disabling the UI whilst the purchase flow is active, however deferred purchases are active for 24 hours (so we have to unlock the UI once we're told a purchase has been deferred)
    • Is this an issue that your users are complaining about?
      • This is something that has been flagged by our QA, we've not released a build with IAPs in it yet
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,130
    You would want to test these scenarios, we would not have specific advice.
     
  9. purpleshirt

    purpleshirt

    Joined:
    Jun 19, 2014
    Posts:
    2
    I'm not sure that deferred purchases are an edge case. Apple has created the ability for families to set up an approval process for "child" devices. So if a kid attempts or requests a purchase on their phone, the "parent" devices receive a message which would allow for approval of the purchase. It seems like it is likely to be a common scenario.

    This is the apple developer resource that describes StoreKit Behavior I'm talking about... to see the section regarding deferred state purchases, go to time = 25m15s
    https://developer.apple.com/videos/play/wwdc2014/303/
    Here is a deep link to the video.
    https://devstreaming-cdn.apple.com/videos/wwdc/2014/303xxqw0yb14u0r/303/ipad_c.m3u8

    In this scenario, the purchase state in apples StoreKit API will be set to a "deferred" state. It will not set a pass or fail state until the purchase is approved or denied from the parent device. This, apparently, can mean that the purchase will remain in a deferred state for up to 24 hours. Then the purchase state can be changed by the parent's acceptance/denial to a success/fail state.

    Their recommended handling of this situation, and in general, is that on start up of any app, developers should check the SKPaymentQueue which will list any updatedTransactions to purchase states. The developer is then meant to process these changes (after checking their receipts) and then mark the transactions as finished.

    I am looking for how this can be handled in Unity. Currently I have set my game to open a dialog to say if the purchase was successful or not. I'm looking for how to identify if a purchase on the apple app store is set to deferred. I would also like to know if there's a tool I can use to check in with the StoreKit SKPaymentQueue to see if there are any updated purchases that occurred while my app was closed.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,130
    An edge case when a second identical purchase is started when the first is still in flight, was my point.
     
  11. purpleshirt

    purpleshirt

    Joined:
    Jun 19, 2014
    Posts:
    2
    My apologies for misunderstanding. :)