[Solved] Unity IAP get item price

How do I get the price and currency of an IAP item in my game?
I did this tutorial https://unity3d.com/learn/tutorials/topics/analytics/integrating-unity-iap-your-game-beta
but i can’t find it there

Hi @Lostrick

Check out the UnityEngine.Purchasing API’s here to find information on how to pull the price and currency of an IAP item in your game:
http://docs.unity3d.com/ScriptReference/Purchasing.ProductMetadata.html

Specifically, you should be able to use “purchaseEventArgs.purchasedProduct.metadata.localizedPrice” and “purchaseEventArgs.purchasedProduct.metadata.isoCurrencyCode” to retrieve the price of a purchased product in your localized currency.

7 Likes

oh i see, thanks for the info, this will really help

1 Like

Hi markychoi, can you elaborate on this please?,
I need to retrieve price set in google console, to show it on the buy button.
I did this:

buyButton.text = m_StoreController.products.WithID(“pack_gold1”).metadata.localizedDescription;

I tried using localizedPriceString, localizedTitle, etc.
On PC I get:
localizedPriceString = “0.01”;
localizedTitle = “Fake description”;
localizedDescription

3 Likes

that’s just normal, u need to test it from android, and have working IAP in ur google dev

1 Like

Hi Lostrick, while on PC I got that odd data, on Android device I get no info at all. Do you mean, I have to upload the apk to alpha group on developer console for this to work?,

yeah u need to complete all the procedure to publish your game and publish it at alpha
the important thing is that if it’s showing 0.01 in editor then that means ur script is already right, if it’s not working on android then that’s not ur IAP script problem, try googling for your problem

1 Like

why do i get a object referene not set to an instance error when i try retriving the local price.
this is what i am doing

IAP1Text.text=m_StoreController.products.WithID(“igu_ipa1”).metadata.localizedPrice.ToString();

do i have to call this this elsewhere? currently i am calling it after InitializePurchasing() function

2 Likes

Hi @chintan_shroff

Is IAP1Text a GameObject? It sounds like it has been deallocated when you go to set the text on it.
To make sure you have it allocated you can find the GameObject before setting the text on it, like this:

IAP1Text = GameObject.Find ("IAP1Text").GetComponent<Text>();
IAP1Text.text=m_StoreController.products.WithID("igu_ipa1").metadata.localizedPrice.ToString();

If that does not solve your problem, please post the stack trace of the error you’re getting!

10 Likes

if you do

  • IAP1Text = GameObject.Find (“IAP1Text”).GetComponent();
  • IAP1Text.text=m_StoreController.products.WithID(“igu_ipa1”).metadata.localizedPriceString;

It’ll add the dollar sign for you or I’m guessing whatever the current local currency is

3 Likes

My m_StoreController was null. I worked with it too early, had the same problem. I am now working with m_StoreController when OnInitialized (). And it is OK now…

2 Likes