Search Unity

Question Stores and IAP

Discussion in 'Game Foundation' started by zhukovv, Jun 30, 2020.

  1. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hello,

    I'm trying to use IAP transactions and display them in a store, for convenience.

    I've set everything according to the tutorial, after initialization I've got a message "UnityIAP: Promo interface is available for 4 items", but in the store, all the IAP items are disabled - purchase buttons are not interactable, and even if I make them interactable manually and then click - nothing is happening.

    I'm using store view and transaction item prefabs, which worked just fine for me with virtual transactions.

    What am I doing wrong?)

    I've attached some screenshots of my setup:
    Screenshot 2020-06-30 at 15.51.27.png Screenshot 2020-06-30 at 15.51.46.png Screenshot 2020-06-30 at 15.51.59.png

    Thank you in advance!!
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Thank you, I will, but for that, I need the GF purchase button to work, but it's disabled for IAP transactions, even running on a device, so I cannot trigger a transaction(

    Any possible reason why it becomes disabled?

    For virtual transactions, purchases disabled if a transaction needs soft currency, and there's not enough balance.

    But I didn't find why it's disabled for my IAPs.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please provide the device logs. If IAP initialization fails, the button is likely disabled. The logs will tell.
     
    zhukovv likes this.
  5. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    To expand on @JeffDUnity3D's remarks, the logs we're looking for are not specifically at the point of purchase, but at the point of IAP initialization, so we can get more details on what IAP products are being downloaded from the store, to confirm that all the setup is correct. Also there may be additional logs from Game Foundation indicating any potential issues in set up and initialization. Based on the Game Foundation window only having the product id listed in the apple identifier line, it sounds like you'll be testing on ios. Jeff's also got a guide for getting those logs https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/

    I'm also wondering what is printed on the button when you see it in the editor? Is it blank or does it have a 0 on it?

    Some other things that can cause the button to be disabled are if the transaction key is blank or null, or if the GameFoundation BaseTransaction is null, or if the TransactionManager purchasingAdapter is false (this is the Runtime Settings Purchasing Enabled flag talked about at the top of the tutorial you linked).

    I would suggest, in addition to sending us the logs, double checking whether that flag is still checked, and that the transaction item prefab that's disabled is showing the correct value in the transaction key field in the inspector when playing. If both of those things are correct than the only way to figure out what's going on will be from the full logs that include initialization.

    I hope that helps and thanks for using Game Foundation!
     
    zhukovv and mingz-unity like this.
  6. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi @erika_d, @JeffDUnity3D

    Thank you for your suggestions!
    Purchasing Enabled flag is on.
    Sorry, where can I find the value in the transaction key?)

    The log:
     
  7. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @zhukovv,

    I think transaction key issues are probably less likely to be the issue though than some of the other ways. However for your reference here are the steps for finding the transaction key:
    - Enter playmode in editor
    - navigate to the transaction item prefab in the hierarchy that isn't working, click on it to view more details about it in the inspector
    - Find the Transaction Item View component in the inspector
    - See what is selected in the transaction item dropdown. If this has a value, then the transaction item key should not be null as this is ultimately what sets the key, unless you are calling SetTransactionKey in the code at all.

    The Purchasing flag being off was really my best non-IAP setup/initialization guess, so since it sounds like it isn't that, it seems likely to be something with the IAP setup.

    Based on the logs you included, one guess I have for what might be causing the issue is that it's using Codeless IAP. We don't currently support using both codeless IAP and Game Foundation enabled purchasing at the same time, so it could cause some unexpected behavior. I did run a quick test adding a codeless IAP button to my test game and it still worked, so I can't say for sure that this is the issue, but there may be some sort of conflict or race condition going on there. I would suggest removing any codeless IAP buttons you have in the game so that those `Initializing unitypurchasing via codeless IAP` logs go away, and see if that solves the issue.

    If it doesn't, let us know. Those logs look a little small compared to what I'm used to seeing, so we may need more complete logs, or for you to submit a support ticket with the project so we can look into it if that's not the issue.
     
    zhukovv likes this.
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please share your code. It almost looks like IAP is attempting to initialize twice. Do you have a working IAP implementation that you are trying to use with Game Foundation? There is a Sample IAP project here, you might consider getting IAP working first (if you haven't already), then look into Game Foundation integration https://forum.unity.com/threads/sample-iap-project.529555/ I would not suggest Codeless IAP, but use the Scripted example, it's much more flexible in the long term.
     
    Last edited: Jul 8, 2020
    zhukovv and erika_d like this.
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  10. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi @erika_d, @JeffDUnity3D

    Thank you for all the information!

    I removed codeless API usage - I think it was called because I used IAP catalog.
    Now there is no "Initializing unity purchasing via codeless IAP` in logs.

    I did have scripted IAP implementation, but I thought that it's not compatible with Game Foundation and I switched to codeless API)

    I will try again and will share results and code with you.
     
    erika_d and mingz-unity like this.
  11. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @zhukovv,

    I don't _think_ just using IAP catalog should trigger a codeless IAP usage (maybe @JeffDUnity3D can confirm). You definitely do need to have your products defined in the IAP catalog for Game Foundation to trigger purchases with them though.

    Game Foundation should take care of all of the IAP initialization/implementation for you. The only setup you should need to do on the IAP package side of things is just entering the items in the IAP catalog, everything else (checking the Purchasing Enabled flag in GameFoundationSettings, setting up your IAP transactions, triggering a purchase) should all happen through Game Foundation.

    Hope that provides more clarity, and not confusion ;) and that your next tests go smoothly! :D
     
  12. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi @erika_d,

    Yes, it was not because of the catalog itself, but the catalog's option "Automatically initialize UnityPurchasing (recommended)" - it was checked)
    So I've filled the catalog, unchecked the option, added scripted IAP manager, launched on my device - but the buttons still don't work)
    The logs look more or less the same, but without the 'codeless' messages.

    I'm attaching the logs, the IAP manager script, and some parts of the main script, related to Game Foundation)
     

    Attached Files:

    erika_d likes this.
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @zhukovv Yes, your IAP logs show successful initialization. In your IAP code, you are loading the products dynamically and not from the catalog. I believe you would want to call AddProduct for each product in your catalog.

    Code (CSharp):
    1.  ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog();
    2.  
    3.         foreach (ProductCatalogItem product in catalog.allProducts)
    4.         {
    5.  
    6.             MyDebug("Product = " + product.id);
    7.         }
     
    Last edited: Jul 21, 2020
    zhukovv likes this.
  14. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi @JeffDUnity3D,

    yes, thank you, I've added all the products from the catalog using your example.

    I think IAP itself works, it just not fully connected to Game Foundation IAP transactions, somehow.
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Apologies, I may have offered incorrect advice. Game Foundation auto-initializes IAP and another initialization would cause problems. Sorry about that. So something else is going on here. We are checking, and I will follow up here.
     
    zhukovv likes this.
  16. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @zhukovv,

    You shouldn't need the IAP manager class, Game Foundation should do all that for you, but that's a good test for confirming that the IAP side of things is correctly set up! I would suggest removing the IAPManager class now, and testing whether you can complete a transaction through Game Foundation without using the Store prefabs. This will tell us whether the issue is in the connection with IAP to Game Foundation (or possibly if there is a bug in the TransactionManager) or if it's a bug in the prefab component code itself. You can follow the code in this tutorial for initiating a transaction via code (the code is in the Virtual Transaction section of the tutorials, but it's the same code for IAP and virtual transactions): https://docs.unity3d.com/Packages/c...alTransaction.html#initiating-the-transaction

    Also thank you for pointing out the "Automatically initialize UnityPurchasing (recommended)" flag in the IAP catalog! We will be sure to add unchecking that to the recommendations in the docs.
     
    zhukovv likes this.
  17. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi @erika_d!

    Thank you, I removed the IAP manager and initiated a transaction as you suggested - it gives "Exception: Tried to process an in-app purchase transaction with no platform purchase handler configured", on an actual iOS device as well as in Unity Editor.
    With the IAP manager back it gives the same error.

    Btw without the manager init logs are very short, basically just:
    UnityIAP UnityEarlyTransactionObserver: Created
    UnityIAP UnityEarlyTransactionObserver: Registered for lifecycle events
    UnityIAP UnityEarlyTransactionObserver: Added to the payment queue

    Also, I tested direct purchasing with the IAP manager (without Game Foundation), and it seems to work, at least it gives no error and shows me a login window to complete purchasing (screenshot attached).

    I attached the code and logs for all 3 cases.
     

    Attached Files:

    Last edited: Jul 23, 2020
    erika_d likes this.
  18. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hey @zhukovv,

    Thanks for that info, that error message is super helpful; it indicates that game foundation itself isn't initializing correctly.

    Can you confirm which version of Game Foundation package manager says you're using? 0.4 or 0.6? My coworker pointed out that the tutorial you linked in the first post of the thread is for 0.4, but we were having a bug with our documentation server that was causing the latest docs not to show up, which is fixed now, so I'm not sure whether you're using Game Foundation 0.4 and looking at the correct docs (in which case the link I sent you in the previous message goes to the wrong version for you) or whether you're using Game Foundation 0.6 but following the instructions for 0.4 (in which case sorry about the missing documentation it took us a bit to realize it was happening). If it's the latter it turns out the way Transaction Manager initializes changed significantly between 0.4 and 0.6, so our old docs would have led you wrong. :eek:

    I see in your IAP snippet from further up that you are creating a purchasingAdapter in Start() and passing it to the TransactionManager in OnInitSucceeded. If you are using 0.6 this actually isn't necessary anymore. (You can check out the final source code for using TransactionManager in 0.6 here: https://docs.unity3d.com/Packages/c...timeVirtualTransaction.html#final-source-code)

    I think there's a good chance this is the root of the issue! (Fingers crossed ;) )
     
    zhukovv likes this.
  19. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi @erika_d!

    I was using 0.4, but now I've updated to 0.6, removed a purchasing adapter and it seems to work)
    Store buttons are clickable and show purchasing interface!
    Thank you!)

    The only thing left that after migrating to 0.6 I've got error messages when trying to using my old GameFoundationDatabase.asset, so I had to switch to a new, blank database, and errors are gone.
    But even if I use my old database, despite the errors, it still works - I have all my data.
    It just kind of not stable - sometimes I see unexpected behavior.
    I've attached the error log.

    But anyway, thank you very much for your help, I'm very happy that I can move on with IAP and GF)

    P.S. A little addition to the 0.6 tutorial you've shared - I needed to add
    "using UnityEngine.GameFoundation.DefaultLayers;", otherwise there are 'MemoryDataLayer not found' errors)
     

    Attached Files:

    erika_d likes this.
  20. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Yay! I'm glad it's working now! Yes, I do recommend recreating the database for 0.6 so you don't get those errors and unexpected behaviors. Since we're still working on finding the best structure for the database, we did have some breaking changes between those releases. We totally understand that having to recreate your database when there are upgrades can be frustrating, and we're trying to find ways to minimize that happening, but we also want to make sure we get a really solid database structure for once we're out of preview. We appreciate your patience and understanding!

    And thanks for letting me know about the missing using statement in the doc! I'll make sure we add that for the next release!
     
    zhukovv likes this.
  21. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi @erika_d,

    okay, I understand, I will recreate it)

    Thank you again for all the support!
     
    erika_d likes this.