Search Unity

Apple Ask to buy questions

Discussion in 'Unity IAP' started by livingtarget, Jun 3, 2020.

  1. livingtarget

    livingtarget

    Joined:
    Apr 21, 2015
    Posts:
    83
    Hi,

    I feel like I'm confused and the documentation seems to be lacking in regard to the questions I have.
    iOS has the ask to buy feature, but the documentation seems vague.

    I would test a lot of these questions myself, but it's hard in lockdown and I don't have access to a Mac and iOS device atm.

    So the first question is what does simulateAskToBuy do? There's a post that suggests it does not work for sandbox purchases, so should I test this on the live store only?

    When does OnDeferred() get called? Does it get called when the user initiated the purchase, when the user pressed "ask" or when the purchase was approved by the parent?

    During process purchase the documentation suggests that for "Ask-to-buy" you need to look explicitly for the m_AppleExtensions.GetTransactionReceiptForProduct(Product) which only works on iOS/Apple TV platforms. Can you always use that on these platforms instead of purchasedProduct.receipt or only in the case of ask to buy? Is the Mac platform unsupported for ask to buy or does it send the receipt through the EventArgs like normal?

    Hope someone has answers :)
     
    Petr777 likes this.
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    simulateAskToBuy does an instant approval on the test device, it doesn't go through the parent approval process on the second (parent) device. OnDeferred lets you (the developer) know that a child has made a purchase attempt. You can put up a dialog or similar to let them know that they are waiting for approval. Finally, when the parent approves, ProcessPurchase will be called just as if the person made a normal purchase. It's my understanding that the ProcessPurchase callback can happen at any time during game play, once the parent approves. I haven't heard if Mac is supported. So in your scenario, the child would have their own Mac, as would the parent? So you know, to fully test Ask to Buy, you would need 2 iOS devices, one for the child and the other for the parent.
     
    JonBFS likes this.
  3. livingtarget

    livingtarget

    Joined:
    Apr 21, 2015
    Posts:
    83
    Thanks for the response that helps.
     
  4. JonBFS

    JonBFS

    Joined:
    Feb 25, 2019
    Posts:
    39
    @JeffDUnity3D On a related question, do you know what happens on the child's end when a parent declines a purchase request? Is IStoreListener.OnPurchaseFailed called (and if so what error), or is it silently forgotten?
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are seeing it "silently forgotten". It can be sent "out of band" when the app may not be running. This is expected behavior
     
    JonBFS likes this.
  6. kkl888

    kkl888

    Joined:
    Dec 6, 2014
    Posts:
    55
    I tried setting the
    simulateAskToBuy=true
    and ran in iPhone device, it didn't call
    ProcessPurchase()
    after initialize buying despite you mentioned it should do an instant approval. Did I miss any step?

    I'm using Unity 2018.4.23f, Unity IAP 2.2.7 from asset store and IAP 2.2.2 in package manager. Tested on iPhone 12 iOS 14.5
     
    Last edited: Apr 30, 2021
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    It is "supposed" to do an instant approval, we have no control over this. I've heard of other users seeing similar. Are you using a Deferred Listener? As an example, see the Sample IAP Project v2 https://forum.unity.com/threads/sample-iap-project.529555/#post-6950270
     
  8. kkl888

    kkl888

    Joined:
    Dec 6, 2014
    Posts:
    55
    Yes I'm using this
    _storeExtensionProvider.GetExtension<IAppleExtensions>().RegisterPurchaseDeferredListener(OnDeferred);
    .
    OnDeferred
    was called, but
    ProcessPurchase()
    was not called right after that. The reason we need
    ProcessPurchase()
    to be called is to make sure the format or value in the apple receipt of the deferred purchase is correct and can be validated from our server.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We have no control over the callback timing.
     
  10. kkl888

    kkl888

    Joined:
    Dec 6, 2014
    Posts:
    55
    Is it expected that
    ProcessPurchase()
    will be called after that (regardless of timing) or it will never be called? For my case, I waited like a couple mins but no response at all, even after restarting the app.
     
  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The failed event never arrives, you might have better luck on the Slow/Succeed flow. I have received it after 3-5 minutes if I recall.