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. Dismiss Notice

IAP Button not functioning outside test

Discussion in 'Unity IAP' started by danielrconrad, Apr 22, 2021.

  1. danielrconrad

    danielrconrad

    Joined:
    Apr 19, 2021
    Posts:
    15
    Hey, I'm using the codeless approach to IAP with 2020.3.4f1. Not sure about the IAP Version but it was updated through the service menu and says its the most up to date. Pretty sure Google is set up for the Catalog ID and stuff so I'm really confused about it. I have the log attached from start to finish but am not sure what's wrong. Any help would be appreciated
     

    Attached Files:

  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Ensure that you check "auto initialize IAP" in your button properties. There are no IAP entries in the logs, that means that IAP is not initializing. I might suggest you start with the Sample IAP Project https://forum.unity.com/threads/sample-iap-project.529555/#post-6950270. And you don't want to install IAP from the Service window. You install IAP now through Package Manager (only)
     
  3. danielrconrad

    danielrconrad

    Joined:
    Apr 19, 2021
    Posts:
    15
    k I've tried that script and didn't have any success either. Its interesting to me that the IAP catalog doesn't load its definitely set up. I removed the IAP from the project and loaded it from the package manager. I think maybe I used the IAP button or catalog so it initialized automatically, which I had on before. When we run initiatepurchase on the controller is when the purchase has gone through and the two else clauses beneath it are if the purchase fails right? Also does ticking consume immediately box on the IAP not function if the product is non consumable? Thanks for the help. If this doesn't work I'll post a log.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Wait, you are using the catalog AND calling InitiatePurchase? Are you mixing a Codeless IAP Button with scripted IAP (unfortunately a common mistake). Please compare to the Sample IAP Project
     
  5. danielrconrad

    danielrconrad

    Joined:
    Apr 19, 2021
    Posts:
    15
    It might've been an oversight in a previous build. Sorry in hindsight the message wasn't too helpful. Anyway I'm working with the script in that project as a template and I've turned the catalog completely off so this build will test that. It runs Initiate on start adds the IAP to builder just like those examples. When I ran it I did get this debug message "error is " the method or operation is not implemented. Dont know if that helps. Gonna try this one and I'll post debug if it doesn't work. thanks again
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You will need to tell me the full error please, it should describe which method. Are you using the Sample IAP Project?
     
  7. danielrconrad

    danielrconrad

    Joined:
    Apr 19, 2021
    Posts:
    15
    I adapted the script from that project into my own so yeah its based off the Sample IAP. I was referring to the debug log message in the ProcessPurchase. The code MyDebug("Error is " + e.Message.ToString()); read out as "Error is " + "the method or operation is not implemented". It did not register as a literal error, I'm just not sure what that means so I thought I'd mention it.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Right but where are you getting that error, what method is generating it. Please show your code. And I believe I know the error. And I meant to actually open and use the Sample IAP Project and get that working first, THEN apply the code to yours. You may miss things, like this. It's always best to develop code by incrementally building on success rather than chasing bugs. Get the basics working first, then customize. The receipt validator will show this error when running in the Editor, in the Sample IAP Project it's within a Try/Catch block, this is by design since the Editor doesn't actually support transactions, only on an Android or iOS device.
     
    Last edited: Apr 22, 2021
  9. danielrconrad

    danielrconrad

    Joined:
    Apr 19, 2021
    Posts:
    15
    K. I'll attach the altered script I use. I use a normal button to activate the function BuyRemoveAds() which functions basically the same as the other purchases buygold50 etc. I add the item to the builder in the initialize function. Functionally things work in Unity and there is something blocking the google purchase. Anywho I still haven't tested this, I'll let you know if its messed up. thanks again
     

    Attached Files:

  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, the code looks correct, the error is expected when running in the Editor.
     
  11. danielrconrad

    danielrconrad

    Joined:
    Apr 19, 2021
    Posts:
    15
    Hey! sorry for the long time between responses. I had some issues with google updating my betas and stuff like that, I've never done this before btw. Anywho I've got the google stuff working pretty good and I'm just sort of figuring it out and had a few questions, I'll upload the purchase script for you to check as well. I dont get an indication from google that this is a fake purchase and I'm not actually being charged. I honestly dont even care about the dollar I lose, but is this a sign of a problem? in other tutorials I was told the indicator that its not actually a purchase would appear and I do not see it. Should I be concerned? Otherwise my script is functional. Also I use a static bool to indicate when the user is buying the product and when they aren't. So basically When I start the purchase I set it to true and when the purchase finishes, whether the user makes a purchase or not, it needs to be set to false again (In the script this bool is MainMenuScript.isBuyingRemoveAds). Setting it to true in the BuyRemoveAds function which initiates the purchase itself works fine as the purchase always begins at that point. However I must set the bool back to false when I run PurchaseProcessingResult, OnPurchaseFailed, and OnPurchaseDeferred. does this effectively ensure that regardless of how the purchase proceeds the bool (MainMenuScript.isBuyingRemoveAds) will be set back to false reenabling the in session main menu. All the menu needs is that bool set to false. Thanks for the help again
     

    Attached Files:

  12. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sounds like everything is working for you! Did you have a specific question?
     
  13. danielrconrad

    danielrconrad

    Joined:
    Apr 19, 2021
    Posts:
    15
    yeah basically what is the OnPurchaseDeferred for. I reset my main menu functionality with a static Boolean (MainMenuScript.isBuyingRemoveAds, true = menu not work, false = menu works). I set it to false in process purchase (when the purchase goes through) and onpurchase fail (when it doesn't go through) and onpurchase deferred. does this catch every possible scenario? Sale or no sale, cancels, tabs out, insufficient funds etc. Also if google does not explicitly tell me its not a real purchase have I set things up correctly? the game is in closed beta and tutorials I watched said it would indicate a fake purchase. The script I use was in my previous post if you need to refer to it. Also is there a way to know a user reinstalling my game has already purchased a non consumable?

    BTW one of the issues with teh buttons was the button functionality did'nt work on android but would on android testing on pc. I dont even think it was an IAP problem in the end. I think maybe I dont know enough about the UI assets, I usually script that stuff.
     
  14. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You can test this yourself, it's called Restore. When you reinstall the app on Google, ProcessPurchase should be triggered automatically during IAP Initialization for non-consumables and subscriptions. But you'll need a Codeless Listener. I would recommend scripted IAP instead of Codeless, and I would suggest to start (and publish!) the Sample IAP Project. Once you publish it and confirm it's working, THEN add the code your game. This way you are always building on success, never chasing bugs and your game is never broken.