Search Unity

[Closed] UnityPurchasing provides an empty product object for productIDs of non-existant products

Discussion in 'Unity IAP' started by MariaAngelovaPD, Dec 15, 2017.

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

    MariaAngelovaPD

    Joined:
    Jun 15, 2017
    Posts:
    25
    If we provide the ConfigurationBuilder instance with a productID which does not correspond to an existing IAP product (as configured in itunes connect) we get a non-null Product object for it in the controller.products.all in OnInitialized(IStoreController controller, IExtensionProvider extensions). The product object's metadata fields are empty strings.
    Likewise, if (after OnInitialized() is called) we query the controller for a non-existing product using the controller.products.WithID(IdToNonExistentProduct); instead of getting null, we get a Product object with empty string fields.
    Expected behavior is that the controller.products.all only contains valid products found in itunes connect which match a productID given to the ConfigurationBuilder and that controller.products.WithID(IdToNonExistentProduct); return null for id's not matching an existing products.
    Expected non-null product objects only when there is a corresponding itunes connect product with the given id, regardless of the state of its configuration (missing metadata, in review, fully configured, available for purchase or not)

    iTunes Connect configured IAPs - none.

    Code:
    public class IAPSystemIOS : IStoreListener
    {
    private const string ProductId = "alabala";
    private const string ProductId_iOS = "alabala_ios";
    public IAPSystemIOS()
    {
    var module = StandardPurchasingModule.Instance();
    var builder = ConfigurationBuilder.Instance(module);

    builder.AddProduct(ProductId, ProductType.NonConsumable, new IDs() {
    {ProductId_iOS, AppleAppStore.Name}
    });
    UnityPurchasing.Initialize(this, builder);
    }

    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
    foreach (var product in controller.products.all)
    {
    D.Log(string.Format("***** IAP: has product {0}, {1}, {2}, {3}, {4}", product.metadata.localizedTitle, product.metadata.localizedDescription, product.metadata.localizedPriceString, product.metadata.isoCurrencyCode, product.availableToPurchase));
    }

    Product product = controller.products.WithID(ProductId);
    if (product == null)
    {
    D.Log("***** IAP: no products found; hiding purchase UI");
    HidePurchaseUI();
    return;
    }
    if (!product.availableToPurchase)
    {
    D.Log("***** IAP: product unavailable; BUY button disable");
    DisableBuyButton();
    return;
    }
    }
    // ...
    }

    Log Output: ***** IAP: has product , , , , False
    UI: Buy button is disabled instead of hiding the entire purchase UI.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @MariaAngelovaPD Thank you for the detailed report, I will check with the IAP team here and will keep you updated.
     
    MariaAngelovaPD likes this.
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I checked with the team here, and this behavior is by design. You might consider the local product catalog a union of those products that you've entered in the local catalog combined with the metadata retrieved from the stores. If you want to check to see if the product is valid for purchasing, you can call Product.availableToPurchase

    https://docs.unity3d.com/ScriptReference/Purchasing.Product-availableToPurchase.html
     
  4. MariaAngelovaPD

    MariaAngelovaPD

    Joined:
    Jun 15, 2017
    Posts:
    25
    Like you can see from my code i already check if it is available for purchase. That is a separate use case. I would like to know if the product even exists. I don't understand why asking for a non-existing product should return an object filled with empty strings. Could you explain the "by design" considerations here? What exactly is "the local catalog"? In our case we have one piece of code which supports potentially several apps with different app bundle ids and each having different products in itunes connect. The app needs to find out what products are available on the store.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    May I ask, how is it a different use case? You added the product locally via builder.AddProduct. If this product does not exist on the App Store, then you can use availableForPurchase to see if it is a valid product. Again, can you elaborate as to why this would not work for you? So you are receiving an empty string, instead of a null? Can you not just check for the empty string, or use availableForPurchase? I suspect I am missing something with regard to your issue, please clarify if you can.
     
Thread Status:
Not open for further replies.