Search Unity

[Solved] Unity IAP get item price

Discussion in 'Unity IAP' started by Lostrick, Mar 13, 2016.

Thread Status:
Not open for further replies.
  1. Lostrick

    Lostrick

    Joined:
    Jan 9, 2014
    Posts:
    32
  2. markychoi

    markychoi

    Moderator

    Joined:
    Aug 4, 2014
    Posts:
    40
    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.
     
    D12294, Menion-Leah, e2000 and 4 others like this.
  3. Lostrick

    Lostrick

    Joined:
    Jan 9, 2014
    Posts:
    32
    oh i see, thanks for the info, this will really help
     
    erika_d likes this.
  4. alonsoGarrote

    alonsoGarrote

    Joined:
    Jun 23, 2012
    Posts:
    25
    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
     
  5. Lostrick

    Lostrick

    Joined:
    Jan 9, 2014
    Posts:
    32
    that's just normal, u need to test it from android, and have working IAP in ur google dev
     
    CaptainNoah likes this.
  6. alonsoGarrote

    alonsoGarrote

    Joined:
    Jun 23, 2012
    Posts:
    25
    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?,
     
  7. Lostrick

    Lostrick

    Joined:
    Jan 9, 2014
    Posts:
    32
    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
     
    MrSIiddes likes this.
  8. chintan_shroff

    chintan_shroff

    Joined:
    Feb 1, 2015
    Posts:
    4

    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
     
    IgorAherne and taimur_azhar like this.
  9. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    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:
    Code (CSharp):
    1. IAP1Text = GameObject.Find ("IAP1Text").GetComponent<Text>();
    2. 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. voporak5

    voporak5

    Joined:
    Jul 1, 2013
    Posts:
    31
    if you do

    1. IAP1Text = GameObject.Find ("IAP1Text").GetComponent<Text>();
    2. 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
     
    codebaby2, jrrathod7 and erika_d like this.
  11. Bitvork

    Bitvork

    Joined:
    Aug 31, 2015
    Posts:
    4
    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...
     
    Kamil_Reich and IgorAherne like this.
Thread Status:
Not open for further replies.