Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Unity IAP Docs

Discussion in '5.3 Beta' started by Baroni, Sep 30, 2015.

  1. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,277
    First announced in the keynote for Unite 2015, Unity is planning to add their own in-app purchase API in Unity 5.3, integrated into the Analytics service. As an Asset Store developer supporting external billing plugins, this is highly interesting for me.

    I couldn't find it in the list of initial (preview) features though. Is this something to expect at a later beta stage?
     
    MrEsquire likes this.
  2. Alex-Lian

    Alex-Lian

    Guest

    Docs being worked on...
     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,277
    Any news on docs? I can't even seem to figure out how to properly initialize billing.

    Code (CSharp):
    1.         var builder = ConfigurationBuilder.Instance( --- what is going on here!? ---);
    2.         builder.AddProduct("100_gold_coins", ProductType.Consumable);
    3.         UnityPurchasing.Initialize(this, builder);
     
  4. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Have you enabled IAP in the services window? See attached image, there was a problem that was preventing this step for which a fix was recently rolled out.

    You then need to import our store implementations by hitting the 'import' button in the attached image. If you have any trouble with that, import the unitypackage directly.

    You're on the right track with your code. Here's an example initialisation with a single consumable product with a bunch of different identifiers on different platforms:

    Code (CSharp):
    1. var module = StandardPurchasingModule.Instance();
    2. var builder = ConfigurationBuilder.Instance(module);
    3.  
    4. builder.AddProduct("100.coins", ProductType.Consumable, new IDs {
    5.             {"com.outlinegames.100goldcoins.v2.c", GooglePlay.Name, AmazonApps.Name},
    6.             {"com.outlinegames.100goldcoins.6", AppleAppStore.Name},
    7.             {"com.outlinegames.100goldcoins.mac", MacAppStore.Name},
    8.             {"com.outlinegames.100goldcoins.win8", WinRT.Name}
    9.     });
    10.  
    11. // Now we're ready to initialize.
    12. UnityPurchasing.Initialize(this, builder);
    13.  
     

    Attached Files:

    Baroni likes this.
  5. markychoi

    markychoi

    Unity Technologies

    Joined:
    Aug 4, 2014
    Posts:
    28
    And to answer the original question of documentation, it should be available as part of the Unity Manual that ships with the next beta Unity 5.3.0b2.
     
    Baroni likes this.
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,277
    @Banderous @markychoi
    Thanks to both of you! This definitely helps and the scripting reference included is enough to figure out the rest. It all makes sense with the ProductDefinition and meta data, btw - great design work on that.
     
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,277
    Is there a reason for not having all platforms as an enum? When building an editor window for creating IAPs, I would like this to be more dynamic rather than hardcoding platform names with their scripts such as GooglePlay.Name, AmazonApps.Name etc.

    With an enum, I could create products like this:

    Code (csharp):
    1. string[] localIds = ...
    2.  
    3. builder.AddProduct(globalId, productType, new IDs {
    4.            {localIds[0], ((PlatformType)0).ToString()},
    5.            {localIds[1], ((PlatformType)1).ToString()},
    6.            {localIds[2], ((PlatformType)2).ToString()},
    7.            {localIds[3], ((PlatformType)3).ToString()}
    8.    });
    - and have the IDs array created dynamically too in a separate method and just pass that in.

    Code (csharp):
    1. IDs productIds = new IDs();
    2. for (int i = 0; i < localIds.Length; i++)
    3.    productIds.Add(localIds[i], ((PlatformType)i).ToString());
    4.  
    5. builder.AddProduct(globalId, productType, productIds);
     
    Last edited: Oct 11, 2015
  8. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    The reason there's no enum is because Unity IAP is plugin based; there is no definitive list of supported stores. You could install another module supporting further stores each with their own name.

    If you want to dynamically gather a list of stores you can instantiate the StandardPurchasingModule and call it's Process method yourself, but you're probably best off creating your own enum.
     
  9. Alex-Lian

    Alex-Lian

    Guest

    FYI, updated the preview post with a link to an IAP doc
     
    Baroni likes this.
  10. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    570
    I wish Unity 5.3 IAP could also support Samsung Android IAP. This is basic. Unibill supports it. Please add this and the build in IAP system will be complete.
     
  11. markychoi

    markychoi

    Unity Technologies

    Joined:
    Aug 4, 2014
    Posts:
    28
    Thanks for your feedback @giorgos_gs. Adding support for Samsung in our IAP implementation is on our roadmap. Stay tuned for more details.
     
  12. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    570
    When you say IAP will support Windows Universal Apps, do you mean also apps not universal but solo Windows Phone 8.1 or Windows Store apps?
     
  13. markychoi

    markychoi

    Unity Technologies

    Joined:
    Aug 4, 2014
    Posts:
    28
    "Windows Universal Apps" is actually misnomer that we recently recognized is causing some confusion. We're updating the copy to read "Windows Store" to more accurately describe that IAP will support transactions for any apps sold through the store (including Windows Phone apps and desktop apps).
     
  14. mihakinova

    mihakinova

    Joined:
    Jan 6, 2015
    Posts:
    85
    I might be missing something, but i cant get to the Unity Manual in b4. If i click it in the help menu nothing happens... Where can i find the documentation for IAP?

    P.S. Your example for IAP has an "OnDeferred" method, but it's never registered with IAppleExtensions.
     
  15. sschan

    sschan

    Unity Technologies

    Joined:
    Oct 8, 2014
    Posts:
    87
    Hi @mihakinova - Here is documentation for IAP. I'll look into why it's not showing up in the b4 Unity Manual.
     
  16. Alex-Lian

    Alex-Lian

    Guest

    Did you install the documentation? If you installed only the Editor download (not the Download Assistant) then documentation is missing. Documentation is it's own modular install now. The Download Assistant allows for full options.
     
  17. Alima-Studios

    Alima-Studios

    Joined:
    Nov 12, 2014
    Posts:
    47
    The nomenclature conflicts with unibill .. means iap is an integration of unibill ¿?

    @Banderous??
     
  18. mihakinova

    mihakinova

    Joined:
    Jan 6, 2015
    Posts:
    85
    Thanks for the documentation @sschan!

    @Alex Lian You are right, I did not install the documentation, I tried downloading it now, but the download link on the beta page seems to be broken (503 server error).
     
  19. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    I believe it was just a clash of Class names. I already deleted Unibill because it has been deprecated from the Asset Store, which is what prompted me to implement the new Unity IAP instead.

    @sschan Could we also request for some information in the documentation about how receipt validation could be implemented with the Purchasing module?
     
  20. zastrow

    zastrow

    Joined:
    May 23, 2012
    Posts:
    20
    For iOS, there is a Display name and a Reference name for In-App Purchases.

    Which one do we use to connect the product to the App store?
     
  21. zastrow

    zastrow

    Joined:
    May 23, 2012
    Posts:
    20
    FYI: I got it working with the Reference Name.
     
  22. zastrow

    zastrow

    Joined:
    May 23, 2012
    Posts:
    20
    Is there a method that's called when everything is all done with an IAP?

    [iOS] The thank you notice comes in after purchase is complete.

    I'd like to set variables when it's totally done.
     

    Attached Files:

  23. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @zastrow Your IStoreListener's ProcessPurchase method is called when an IAP completes.
     
  24. zastrow

    zastrow

    Joined:
    May 23, 2012
    Posts:
    20
    If you're talking about this method;

    Code (CSharp):
    1. /// <summary>
    2.     /// Called when a purchase completes.
    3.     ///
    4.     /// May be called at any time after OnInitialized().
    5.     /// </summary>
    6.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    7.     {
    8.         return PurchaseProcessingResult.Complete;
    9.     }
    In iOS at least, the thank you message pops up after this method is complete.

    The IAP process pauses the app everytime it has a message window, but unpauses it when that window is closed. So your app bounces back and forth between void Update() mode and void OnApplicationPause() mode.

    I want to either provide specific instruction when the app enters void OnApplicationPause() mode due to IAP

    OR

    Figure out when the IAP process is totally complete because public PurchaseProcessingResult ProcessPurchase() doesn't signal the last disruption.
     
  25. sschan

    sschan

    Unity Technologies

    Joined:
    Oct 8, 2014
    Posts:
    87
    @u0204909 in regards to your comment:
    >>Could we also request for some information in the documentation about how receipt validation could be implemented with the Purchasing module?

    Yes, we are still finalizing the implementation but we can post the documentation once it's ready. :)
     
    hawken and MrEsquire like this.
  26. Chris Custard

    Chris Custard

    Joined:
    Mar 4, 2015
    Posts:
    1
    Strange question... should I be expecting UnibillWin8 exceptions being thrown after (and only after) calling UnityPurchasing.Initialize(this, builder); in a windows store universal 10 build?

    Note: IStoreListener's OnInitialized or OnInitializeFailed aren't called either.

    Edit: The exception is UnibillWin8:Exception loading listing information:Element not found. (Exception from HRESULT: 0x80070490)
    I've removed Unibill when I made a new project to test the Unity IAP stuff.
     
    Last edited: Nov 4, 2015
  27. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @zastrow That dialog is controlled by storekit, unfortunately Unity IAP doesn't have visibility or control over it. Can you anticipate the interruption in your ProcessPurchase method?

    @Chris Custard Are you running against the live windows environment for an app that isn't yet published? See here. If so you can run against Microsoft's local simulated environment by setting the 'useMockBillingSystem' flag on the StandardPurchasingModule:

    Code (CSharp):
    1. var module = StandardPurchasingModule.Instance();
    2. module.useMockBillingSystem = true;
    3. var builder = ConfigurationBuilder.Instance(module);
     
  28. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,035
    I use 5.3.0b5. i enabled IAP, linked my project and imported storage package. i added "using UnityEngine.Purchasing;"

    i get following error;

    The name `StandardPurchasingModule' does not exist in the current context
     
  29. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @atmuc Can you run the scene at "Assets/Plugins/UnityPurchasing/scenes/IAP Demo" without errors?
     
  30. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,035
    I have another computer. At that computer i clicked import button and it showed me some files while importing. At my first computer i saw nothing. now it is ok at my 2nd computer. i think it did not imported to the 1st one.
     
  31. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    You mention supported platforms, but in the contents Amazon is not mentioned but there is a testing note about it.
    How will Amazon be handled? Recently I made a Android Google Play app using Prime 31 plugins, you must be aware of these, handling InApp purchases but got stuck on Amazon as realized it requires a separate plugin and process and Prime 31 do not have Amazon plugin. I hope Unity be able handle Amazon properly..
    Thanks
     
  32. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,035
    is it possible to get all IAP products from Google Play with Unity IAP API ?
     
  33. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @MrEsquire Amazon is not currently a supported platform for Unity IAP. Amazon have their own Unity plugin though, I believe.

    @atmuc Once Unity IAP has initialised you can access all your IAP product metadata. See the demo scene that comes with the imported files:

    Code (CSharp):
    1.     public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    2.     {
    3.         m_Controller = controller;
    4.         appleExtensions = extensions.GetExtension<IAppleExtensions> ();
    5.  
    6.         Debug.Log("Available items:");
    7.         foreach (var item in controller.products.all)
    8.         {
    9.             if (item.availableToPurchase)
    10.             {
    11.                 Debug.Log(string.Join(" - ",
    12.                     new[]
    13.                     {
    14.                         item.metadata.localizedTitle,
    15.                         item.metadata.localizedDescription,
    16.                         item.metadata.isoCurrencyCode,
    17.                         item.metadata.localizedPrice.ToString(),
    18.                         item.metadata.localizedPriceString
    19.                     }));
    20.             }
    21.         }
    22.     }
     
  34. zastrow

    zastrow

    Joined:
    May 23, 2012
    Posts:
    20
     
  35. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Most plugins I use for InApps - Prime 31 and Stans Assets have example scenes and example scripts
    Will this be the same case for Unity, it really helps, see example: https://prime31.com/docs#iosStoreKit
    Lot of things to consider when testing also..
     
  36. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Yes, there is an IAP demo scene that comes with the IAP packaged installed via the IAP cloud service window; Plugins/UnityPurchasing/scenes
     
    MrEsquire likes this.
  37. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    How do we access the app store receipt for validating and parsing? The only way I found in the docs was using IAppleExtensions.RefreshReceipt since the successful callback returns a string which I believe is the encoded unified receipt? As you know that should not be the default way because it prompts the user for their App Store credentials every app run. Is there a way to access the receipt locally stored on the device so I can validate and parse it every time before determining what in app purchases the user has made? Or am I responsible for storing a copy of the receipt (Product.receipt) whenever a purchase is made?

    This was from Apple's documentation. Retrieving this unified receipt that is stored in the application bundle is what I meant.
    "Locate and Parse the Receipt
    When an application is installed from the App Store, it contains an application receipt that is cryptographically signed, ensuring that only Apple can create valid receipts. The receipt is stored inside the application bundle. Call theappStoreReceiptURL method of the NSBundle class to locate the receipt."

    Also, could there be an inclusion in the docs regarding the use of iOSStoreBindings and other classes/interfaces like IStore not covered in the manual? For example, iOSStoreBindings.RetrieveProducts asks for a string param called json. So exactly what object am I suppose to pass in as a json string? The receipt or a collection of ProductDefinitions like the IStore interface?

    The initial setting up and basic purchasing has adequate docs but beyond that, it's really hard to test effectively if we are navigating blind.
     
    Last edited: Nov 11, 2015
  38. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    You're right, there's something missing from IAppleExtensions to just read the receipt is is without explicitly refreshing it. I'll get it added and update this thread when available.

    Regarding undocumented types iOSStoreBindings should not be visible, I'll make them internal.
     
    myama likes this.
  39. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    Thanks! Yea some of those undocumented types might make us chase rabbit holes because we are trying hard to solicit a solution from the docs haha.
     
  40. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,035
  41. movinarc

    movinarc

    Joined:
    Nov 7, 2014
    Posts:
    6
    Is it going to be a One-4-All solution? Anyways, I cant wait to test Unity IAP!
     
  42. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @atmuc great, are you targeting any other platforms too?
    @mvnrc Yes, Unity IAP will have a universal API if that's what you mean.
     
  43. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,035
    @Banderous Yes, i plan iOS, WP8, Windows 8,TvOS
     
  44. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,035
    Can you confirm that; i cannot test IAP on Universal Build like i do on iOS and Android. i haven't published my app yet. i get following error UnibillWin8:Exception loading listing information:Exception from HRESULT: 0x805A0194 . i used builder.Configure<IMicrosoftConfiguration>().useMockBillingSystem = true; do i have to do something more?
     
  45. Entity3Limited

    Entity3Limited

    Joined:
    Jan 10, 2012
    Posts:
    21
    Hi, I have managed to set this up with Google Play using the below

    builder.Configure<IGooglePlay Configuration>().GetPublicKey("MyKey");

    To set IAP up with iPhone / iTunes Connect is there code or an alternative to the above I should be using?

    Thanks
     
  46. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    570
    In Unity 5.3f1 I get ILogger errors with Unibill. Can we fix that because Unity IAP is great but it doesnt support Amazon and Samsung yet. Anyone fixed this?
     
  47. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Amazon should be priority as technically its Android..
     
  48. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @atmuc you'll need to set that on the store module -

    Code (CSharp):
    1. var module = StandardPurchasingModule.Instance();
    2. module.useMockBillingSystem = true; // Microsoft
    3. var builder = ConfigurationBuilder.Instance(module);
    @giorgos_gs You should use either Unity IAP or Unibill rather than both.
     
  49. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    570
    No, I just tried Unity 5.3f1, I didnt enable Unity IAP. The ILogger errors must be related to other Unity changes but since Unibill is deprecated I am just trying to see if anyone made it work.
     
  50. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,035
    Thanks @Banderous. Your code worked. you should change documentation (C:\Program Files\Unity\Editor\Data\Documentation\en\Manual\UnityIAPUniversalWindows.html) the code on this page did not worked.

    Code (CSharp):
    1. var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    2. builder.Configure<IMicrosoftConfiguration>().useMockBillingSystem = true;
     
    milox777 likes this.