Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I retrieve IAP price from Codeless IAP for use in scripts?

Discussion in 'Unity IAP' started by DaveKap, Jun 4, 2020.

  1. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    Title is the question. I tried grabbing the price via the codeless IAP's "price text" variable inside the component but this (via xcode AND testflight) doesn't actually show any text at all, so even without trying to grab it via a script, it's simply not working right. Is there some way to retrieve the product catalog data from the Codeless IAP component without trying to hack together my own new IAP class?

    An alternative question (the longer version): I'm just trying to get a display in my game that shows the proper localized pricing of IAP so I can get this thing sold worldwide. There doesn't seem to be a simple way to do this as Googling around says I need to write my own IAP class or simply explains the IStore interfaces without any example code anywhere for how to actually use said interfaces, which isn't a coding paradigm I quite understand, to be completely honest. This page in particular needs a LOT of work: https://docs.unity3d.com/Manual/UnityIAPBrowsingMetadata.html Because I don't know how I'm supposed to use the interface or get controller information from the already established Codeless IAP component. All this said, any help would be appreciated.
     
    Last edited: Jun 4, 2020
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I would suggest that you look at IAPButton.cs, you can see the use of the localized price there.
     
  3. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    Thanks but unfortunately that's just confirming my suspicion that something is broken so let me ask a different question now:
    Is that localized price supposed to work when I run my app from xcode or testflight? As is, it displays "0", even though I can successfully make IAP purchases in both of those testing environments and the pop-up from apple correctly displays the price.

    Edit: For that matter, is it supposed to work in the editor? Even though I have the price set in the catalog, testing in the editor just says it's "0" and not the actual price.
     
    Last edited: Jun 4, 2020
  4. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Did you choose the price for the product in Apple Configuration?
    upload_2020-6-5_13-44-27.png
     
  5. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    Yes, I can confirm that I selected a price tier. I've staged the app to testflight again and the price field is simply empty. I have the field default with the text <price> so I know now that it's being replaced by an empty string. In the editor, it shows as the number 0. I'm unsure what to do to make this work considering the difference in result between the editor and testflight.

    Again, actually clicking the button brings up the proper dialog with the proper price. I just can't seem to retrieve the price from IAPButton.cs alone. This is why I'm asking where, exactly, this price is supposed to actually work. If it's supposed to work in the editor, then I can try debugging there. If it's only supposed to work after it goes through xcode or testflight, then I know I have to do debugging through that somehow. Can I first get a confirmation about which platform should actually retrieve this pricing before I continue? Thank you for the help.

    Edit: I added prices for the Google Play section and those are now displaying when I play via the Editor... even if I change the build configuration to iOS, oddly enough. So I believe that's why it's showing as blank in TestFlight, it's pulling from the blank field for Google Play. Which brings me back to... how do I get it to look for the iOS price instead?
     
    Last edited: Jun 5, 2020
  6. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    I just tested it and it looks like the price of Apple products in the editor will show 0, and we will investigate it.
    But the price of the product in Testflight should be normal. Please check whether the product ID and type are consistent with the configuration of the Apple Store.
     
  7. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    Ah, I went to the appstoreconnect page to double check this for you and I see now that both IAPs are flagged as "missing metadata." I'll correct this error and hopefully it will solve my problem! Thank you for looking into the bug with the editor.

    Edit: I've updated the IAPs in appstoreconnect so that their status is "ready to submit" but running the app via testflight still blanks out the price text. I'll try again in 12 hours but just in case, I'm curious how else I should be debugging this.
     
    Last edited: Jun 5, 2020
  8. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Can you provide us with the configuration screenshot of the product in the Apple App Store and a screenshot of the catalog for us to have a look?

    BTW, you can use the following code to retrieve the product's price.
    Code (CSharp):
    1.  public IAPButton button;
    2.    
    3.     void Start()
    4.     {
    5.         Debug.Log("The product's price is:"+ button.priceText.text);
    6.     }
     
  9. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    Edited to correct myself:
    I've been grabbing from IAPButton.cs the following code:
    Code (csharp):
    1.  
    2. priceText.text = product.metadata.localizedPriceString;
    3.  
    Which is how I got the "0", " ", and Google Play pricing to be displayed. The text box says "<Price>" by default and has always managed to get overwritten, so it's always pulling something from that variable.

    Here's the IAP Catalog entry:
    https://i.imgur.com/iqEBADK.png

    Here's what it shows on appstoreconnect:
    https://i.imgur.com/C9xN2ye.png
    https://i.imgur.com/tNiEegG.png

    Let me know if you need anything else. It's bed time where I am so I'll be replying again in 9+ hours.
     
    Last edited: Jun 5, 2020
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Last edited: Jun 5, 2020
  11. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    Thank you for all the help! I've got the price displaying properly when run via XCode so I believe my next build to testflight will work.

    I have to assume it was due to the IAPs missing metadata and not being ready for submission which just took some time to propagate to the right servers after I fixed it last night.
     
    JeffDUnity3D likes this.