Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Item already owned error in consumable purchase

Discussion in 'Unity IAP' started by Zape, Sep 16, 2021.

  1. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Hi there.

    I'm having issues with Unity IAP when adding a new purchase on Google Play. Once tried first it did not get any callback and the purchase was not made even the promo code was correctly used and shown that the purchase had been made.

    Now I can't try it again because it says I already own that item even being a consumable purchase and the IAP catalog has it recorded as consumable and the IAPButton has checked the "Consume product" checkbox.

    Logcat is giving three "Already recorded transactions (transactionID)" and when trying to purchase the item again it shows an "onPurchaseFailed" "DuplicateTransaction" error.

    The code has been working until added this new item ( it's recycled code from other games that still are working) and now I can't purchase these items. I was using the Uniity 1.xx IAP and some forums recommended updating to 2.2. Did it and still failed. Now I'm using 3.1 and still the same.

    I'm a bit lost. Does someone have a clue?

    Thanks in advance.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please show a screenshot of your product as configured in the catalog. I might recommend not to use Codeless, we've heard of similar reports. Instead, I would recommend that you use Scripted IAP, perhaps start with the Sample IAP Project v2 here https://forum.unity.com/threads/sample-iap-project.529555/#post-6950270
     
    Zape likes this.
  3. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Thanks for your reply.

    I am not using the Codeless version, at least as far as I know. The code is quite similar to that of the MyIAPManager script in the example project..

    Code (CSharp):
    1. void Awake()
    2.     {
    3.  
    4.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    5.         builder.AddProduct("pack_100", ProductType.Consumable, new IDs
    6.             {
    7.                 {"pack_100", GooglePlay.Name},
    8.                 {"pack_100", AppleAppStore.Name},
    9.  
    10.             });
    11.         builder.AddProduct("pack_250", ProductType.Consumable, new IDs
    12.             {
    13.                 {"pack_250", GooglePlay.Name},
    14.                 {"pack_250", AppleAppStore.Name},
    15.  
    16.             });
    17.         builder.AddProduct("pack_500", ProductType.Consumable, new IDs
    18.             {
    19.                 {"pack_500", GooglePlay.Name},
    20.                 {"pack_500", AppleAppStore.Name},
    21.  
    22.             });
    23.         builder.AddProduct("promorider", ProductType.Consumable, new IDs
    24.             {
    25.                 {"promorider", GooglePlay.Name},
    26.                 {"promorider", AppleAppStore.Name},
    27.  
    28.             });
    29.         //Debug.Log(builder);
    30.         UnityPurchasing.Initialize(this, builder);
    31.     }
    32.  
    33.     public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    34.     {
    35.         this.controller = controller;
    36.         this.extensions = extensions;
    37.         Debug.Log("Purchasing Initialized");
    38.         foreach (var product in controller.products.all)
    39.         {
    40.             //Debug.Log (product.definition.id);
    41.             //Debug.Log(product.definition.storeSpecificId);
    42.             if (product.definition.storeSpecificId == "pack_100")
    43.             {
    44.                 st100 = product.metadata.localizedPriceString;
    45.                 //Debug.Log ("25 tok");
    46.                 text100.text = st100;
    47.  
    48.             }
    49.             else if (product.definition.storeSpecificId == "pack_250")
    50.             {
    51.                 st250 = product.metadata.localizedPriceString;
    52.                 //Debug.Log ("50 tok");
    53.                 text250.text = st250;
    54.             }
    55.             else if (product.definition.storeSpecificId == "pack_500")
    56.             {
    57.                 st500 = product.metadata.localizedPriceString;
    58.                 //Debug.Log ("100 tok");
    59.                 text500.text = st500;
    60.             }
    61.             else if (product.definition.storeSpecificId == "promorider")
    62.             {
    63.                 stPromo = product.metadata.localizedPriceString;
    64.                 //Debug.Log ("100 tok");
    65.                 textPromo.text = st500;
    66.             }
    67.  
    68.         }
    69.         Debug.Log("Prices: " + st100 + ", " + st250+ ", " + st500 + " promo: " + stPromo);
    70.     }
    71.     public void OnInitializeFailed(InitializationFailureReason error)
    72.     {
    73.         Debug.Log("Init failed:  " + error);
    74.     }
    75.  
    76.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    77.     {
    78.      
    79.         Debug.Log("ProcessPurchase" + "   " + e.ToString());
    80.      
    81.  
    82.         return PurchaseProcessingResult.Complete;
    83.     }
    84.     public void OnPurchaseFailed(Product i, PurchaseFailureReason p)
    85.     {
    86.         Debug.Log(i.definition.id + "   " + p.ToString());
    87.         if (i.definition.id == "pack_100")
    88.         {
    89.             //StartCoroutine(PurchaseGP(1, st100, "Error 100:" + i.definition.ToString() + ": " + p.ToString(), 1));
    90.             Debug.Log("Failed 100");
    91.             manager.OpenPurchaseResult(false, 1);
    92.         }
    93.         else if (i.definition.id == "pack_250")
    94.         {
    95.             //StartCoroutine(PurchaseGP(2, st250, "Error 250:" + i.definition.ToString() + ": " + p.ToString(), 1));
    96.             Debug.Log("Failed 250");
    97.             manager.OpenPurchaseResult(false, 2);
    98.         }
    99.         else if (i.definition.id == "pack_500")
    100.         {
    101.             //StartCoroutine(PurchaseGP(3, st500, "Error 500:" + i.definition.ToString() + ": " + p.ToString(), 1));
    102.             Debug.Log("Failed 500");
    103.             manager.OpenPurchaseResult(false, 3);
    104.         }
    105.         else if (i.definition.id == "promorider")
    106.         {
    107.             //StartCoroutine(PurchaseGP(3, st500, "Error 500:" + i.definition.ToString() + ": " + p.ToString(), 1));
    108.             Debug.Log("Failed promorider");
    109.             manager.FailedPromoRider();
    110.         }
    111.         else
    112.         {
    113.             Debug.Log("Error Unknown: " + i.definition.ToString() + ": " + p.ToString());
    114.             manager.OpenPurchaseResult(false, 4);
    115.             //StartCoroutine(PurchaseGP(100, "Err", "Error Unknown:" + i.definition.ToString() + ": " + p.ToString(), 1));
    116.         }
    117.     }
    118.     public void Bought(Product product)
    119.     {
    120.  
    121.      
    122.         if (product != null)
    123.         {
    124.          
    125.             Debug.Log(product.definition.id);
    126.          
    127.          
    128.  
    129.          
    130.             switch (product.definition.id)
    131.             {
    132.  
    133.                 case "pack_100":
    134.                     manager.Bought100();
    135.                     break;
    136.                 case "pack_250":
    137.                     manager.Bought250();
    138.                     break;
    139.                 case "pack_500":
    140.                     manager.Bought500();
    141.                     break;
    142.                 case "promorider":
    143.                     manager.BoughtPromoRider();
    144.                     break;
    145.                 default:
    146.                     Debug.Log(
    147.                         string.Format("Unrecognized productId \"{0}\"", product.definition.id)
    148.                     );
    149.  
    150.                     // "Direct Error: NO PRODUCT " + product.definition.id;
    151.                     //StartCoroutine(PurchaseGP(100, "DirErr ", estado, 0));
    152.                     break;
    153.             }
    154.         }
    155.         else
    156.         {
    157.             //estado = "PRODUCT_NULL";
    158.  
    159.         }
    160.  
    161.     }

    IAP1.PNG IAP2.PNG
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    The IAP Catalog screenshot that you have shows you are using Codeless. So it appears you are mixing Codeless and Scripted IAP unfortunately, and are likely initializing IAP twice. You will want to remove all your products from the catalog and remove any Codeless IAP Buttons. I might suggest you compare to the Sample IAP Project v2
     
    Zape likes this.
  5. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    So we have been using it wrong for years.. o_O facepalm
    Can´t still try the sample project.. It has lots of compiler errors using 2019.3.5f
    IPAPSample.PNG
    Will try to fix it and contact you again.
    Thanks a lot for your help
     

    Attached Files:

  6. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Hi.
    Can not get rid of compiler errors on Sample IAP project v2. Looks like downgrading to 2019 breaks the project down...
    Guess I have to delete IAPButtons and use normal buttons instead and delete the catalog and keep using the builder in code as we did. Could it be?
    Thanks
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You are not adding the sample to another project, right? The errors mention "textures", there are no textures explicitly used in the sample project. There are no IAP Buttons (codeless) used in the sample. You unzip the file, then choose Add project from the Hub.
     
  8. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Yes, that's what I did. It tells me that project is done in another version and downgrades it. When done all those errors in the screenshot are shown and can not be used.. I think the logic behind the myIAPController script and the one on our code is more or less the same. Even I can not see how does the sample project work I think I can learn something from it.
    My question about IAPButtons and Catalog was about the other project, the one we have developed. Are they part of the codeless IAP and not necessary so we have to get rid of them and use normal buttons and the scripted builder?
    Sorry I'm a bit confused of what's considered codeless and what not.
    Thanks
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    The Catalog and IAP Buttons that you drop in are Codeless. But if purchasing is working, then no need to change anything. Only make changes to address any issues you might be seeing.
     
  10. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Ok.
    It has worked until now when has started to give the "item already owned" in consumables... Didn't know that iapButtons were part of the codeless iap, just thought it was a component to control the purchase callbacks such as onPurchaseFailed. Have been using it wrong for at least 3 years but it worked.
    Will try to get rid of iapButtons and catalog and rebuild it tomorrow, this issue is giving me headache.
    Will tell you. Thanks a lot for your patience and have a nice day.
     
    Last edited: Sep 17, 2021
  11. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You are welcome! So your published game started to show these errors? Did you publish a new version? Or was it the same version as always.
     
  12. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    As far as i know previous versions of the game do not have this issue. Not in the tests we did at least and nobody has complained about it in the published versions and purchases have been hundreds at this point.

    This issue has appeared in the version we have built and pushed to the internal test channel for testing purposes before promoting it to production. A new purchase has been added in a very simple way and its settings and code are the same as the previous ones, configured as consumable. This version is not published yet in the production channel and the published one does not have any issue as far as we know.
    Thanks
     
  13. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Hi Jeff.
    I have been trying again and I'm facing a new problem.
    Somehow, we are missing two files: GooglePlayTangle.cs and AppleTangle.cs. Our project was initially using Unity IAP 1.x and when upgraded to 2.2 to try to solve the duplicated transaction issue, did not either have them. When upgraded to 3.1 the note on the upgrade version said something about moving them to another folder but ( even searching for them in old backups) these files have never existed in our project.
    They seem to be generated by the IAP plugin but can´t know how to generate or re-generate them.
    Should I delete all the IAP section and start again from scratch?
    Thanks
    Edited: I have commented that part, seems to have something to do with validating receipts... We did not use it before so I think it could be ignored for now. Let's try if the new code works.
    IAPFail.PNG
     
    Last edited: Sep 17, 2021
  14. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Hi again!
    I have removed all the unity purchasing part and deleted our code related for IAP purchases to avoid compiler errors.
    Enabled and installed again the unity IAP, version 2.2 i1.PNG ( although logcat says it's 2.3.0, weird... i2.PNG ) from the package manager and used the import feature from services>IN-APP Purchases. Remade all the code without catalog and IAPButtons, only normal buttons and code, just as IAP Sample v2 does.
    Still receiving logcat warnings about "Already recorded transactions".

    Although it initializes correctly, returns the prices of each item correctly and the buttons work, I still get the "You already own this item" error. Products are added as consumables.
    i3.PNG

    I'm stuck again. Any idea?
    Thanks

    Code (CSharp):
    1. public void InitializePurchases(){
    2.  
    3.         if (IsInitialized())
    4.         {
    5.             Debug.Log("Purchases are already initialized");
    6.             return;
    7.         }
    8.         else
    9.         {
    10.             var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    11.             builder.AddProduct("pack_100", ProductType.Consumable, new IDs
    12.             {
    13.                 {"pack_100", GooglePlay.Name},
    14.                 {"pack_100", AppleAppStore.Name},
    15.  
    16.             });
    17.             builder.AddProduct("pack_250", ProductType.Consumable, new IDs
    18.             {
    19.                 {"pack_250", GooglePlay.Name},
    20.                 {"pack_250", AppleAppStore.Name},
    21.  
    22.             });
    23.             builder.AddProduct("pack_500", ProductType.Consumable, new IDs
    24.             {
    25.                 {"pack_500", GooglePlay.Name},
    26.                 {"pack_500", AppleAppStore.Name},
    27.  
    28.             });
    29.             builder.AddProduct("promorider", ProductType.Consumable, new IDs
    30.             {
    31.                 {"promorider", GooglePlay.Name},
    32.                 {"promorider", AppleAppStore.Name},
    33.  
    34.             });
    35.             //Debug.Log(builder);
    36.             UnityPurchasing.Initialize(this, builder);
    37.         }
    38.  
    39.  
    40.     }
     
  15. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    @Zape You do not import IAP from Services. You only install IAP from Package Manager now, since 3.x. You are still installing the older asset package, and that is why are you seeing 2.3.0 in your logs. Ensure to not click on any Import buttons from the Service window, that feature will be removed in an upcoming release. You want to be using IAP 4.0.3, available as In App Purchasing in Package Manager and do not click any Import buttons after that. Then delete /Assets/Plugins/UnityPurchasing. Please note in your screenshot, the button at the bottom says "Upgrade to 4.0.3", you should! As mentioned, please get the Sample IAP Project working first, and publish it. For me, I actually have 2 identical versions of the Sample IAP project published on Google for testing. I test new features on one of them so the other does not break, and then apply lessons learned to it.
     
  16. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    Ok, I used the import button because the installed version from the package manager was 2.2 and the warning was for 3.x and above versions only.
    I did not upgrade to 4.0.3 because the log has 3 steps to follow and talks about files that have to be moved from one folder to another. Those files simply do not exist in my folders and I was not sure if only following the last step would work or would mess up the project more than already is.

    Will remove all again and try 4.0.3.
    Thanks a lot.
     
  17. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    "the log has 3 steps to follow", I assume you meant documentation and not log, what are you referring to? Have you got the Sample IAP Project working first, as suggested? Then your game won't be "broken" during this process.
     
  18. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    31
    IPAPSample.PNG
    Yes, I was meaning the documentation on the right side of the package manager. pack.PNG . None of the files on the first and second steps are present in my project and never have been ( checked in previous backups).

    Sorry, maybe I'm not explaining as clear as I thought, english is not my first language.

    No, I didn´t manage to get the sample project working. Opening it with my Unity version ( 2019.3.5f) throws lots of compiler errors. Tried many times with no result. Tried copying assets to a fresh new empty project too but it didn´t work.
    IPAPSample.PNG

    Will remove again all the IAP related elements and try installing the 4.03 version.

    I apologize for this long thread. Thanks for your help.
     
    Last edited: Sep 17, 2021
  19. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please try loading the Sample IAP project with Unity 2019.4 or above. Also, please practice with an empty project first to confirm the process. Typically when you run into an error like you mention, you should "drop everything" and not attempt to move forward until it's resolved. You want to get the basics working first.