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

iOS subscription handling

Discussion in 'Unity IAP' started by k_belonogov, Mar 15, 2021.

  1. k_belonogov

    k_belonogov

    Joined:
    Jan 12, 2016
    Posts:
    10
    Unity 2020.1.17
    Unity IAP 3.0.1

    1) Start your application with integrated Unity IAP. Wait for UnityPurchasing been initialized.
    2) For sandbox environment go to Settings > AppStore > Sandbox Account > Manage.
    3) You can see a list of your subscription items.
    4) Buy one of them.
    5) Return to your application.
    You can detect via code, that you have receipt for this subscription item.
    Via such code
    Code (CSharp):
    1.  
    2. void OnApplicationPause(bool isPaused)
    3. {
    4.     if (isPaused)
    5.         return;
    6.  
    7.     Product[] nonPurchasedSubscriptions = Array.FindAll(_storeController.products.all, p =>
    8.         p.definition.type == ProductType.Subscription && !p.hasReceipt);
    9.  
    10.     foreach (Product p in nonPurchasedSubscriptions)
    11.     {
    12.         string receipt = _storeExtensions.GetExtension<IAppleExtensions>().GetTransactionReceiptForProduct(p);
    13.         if (!string.IsNullOrEmpty(receipt))
    14.             ; // Todo: here is new subscription!!!
    15.     }
    16. }
    17.  
    Unity IAP module does not trigger ProcessPurchase callback during this session.
    I tried to call ConfirmPendingPurchase, but it leads to error.
    I even tried to recreate IStoreListener object. But it also leads to error Duplication transaction.
    Help! I don't want to make complex workarounds in gameplay logic to handle this case.
    Just make triggering ProcessPurchase callback and thats all!

    Thanx!
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    This is expected behavior, we don't receive the callback from the store. Typically users would not purchase via their Dashboard. Do you see the ProcessPurchase when you restart your app, or reinstall?
     
  3. k_belonogov

    k_belonogov

    Joined:
    Jan 12, 2016
    Posts:
    10
    Yes, ProcessPurchase is called after restart or reinstall the app.
    Excuse me but it’s odd to read the answer like “typically users will not... [so just ignore this case]”. But if user can do it, they will do it!
    I can detect this case using UnityIAP module as i described earlier. Are there problems to handle this case with ProcessPurchase?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry I wasn't clear. In a few years, I have not heard from any customer doing so even in a live game (the typical part, but possible to your point). If you have a solution that works for you, then great. Otherwise, you would need to restart your app, or possibly reinitialize IAP. The ProcessPurchase is a callback from the store API, we have no control over it and can't explicitly trigger it.
     
  5. k_belonogov

    k_belonogov

    Joined:
    Jan 12, 2016
    Posts:
    10
    As an engineer, I understand what you're talking about. But how does the purchase receipt with the transaction id arrive immediately after we return to the game from background? As I described in my question I can detect it.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    We receive it via the Google API. If you can detect it, then in your case, that seems like the solution. If you choose, you can award the product at that time.