Search Unity

[Solved] Quick questions about iap

Discussion in 'Unity IAP' started by HotPhone, Feb 20, 2016.

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

    HotPhone

    Joined:
    May 14, 2014
    Posts:
    53
    Hi, I am finishing my online shooter for Android, and I think that I have successfully implemented iap. But I still have some quick questions about it.

    1. IAP works in the editor, but when I click on "Buy" in my phone, nothing happens. Does this happen, because the game is not released yet, or is it a bug? (Products are set to active)
    2. Is it correct, that ProcessPurchase is called on Initialisation, so that I basically don't have to handle anything? It does not work in the editor, but I don't expect it to.
    3. What is the method to check, if a player owns a non-consumable?

    Thanks for your help. I am sure that you can answer my simple questions very fast.
     
  2. mpinol

    mpinol

    Joined:
    Jul 29, 2015
    Posts:
    317
    Hi @HotPhone,

    1. “Buy” on your phone works when all the Store configuration steps have been followed. For Android see https://docs.google.com/document/d/1qLfNTPIwRIFcPJkBfyuxRuf388ckxIyy12LjR8Hdm_E (from http://forum.unity3d.com/threads/un...le-play-apple-app-store-windows-store.372647/).

    2. ProcessPurchase may be called after Initialize if when purchases have completed from a Store perspective but not have not been completed by your game, being carried over from a prior game lifecycle. So if the user quits before ProcessPurchase returns PurchaseProcessingResult.Complete then ProcessPurchase will be called again, after Initialize.

    Typically however ProcessPurchase is called after InitiatePurchase (e.g. https://bitbucket.org/Unity-Technol...eviewer=file-view-default#UnityIAPDemo.cs-221) indicating the user successfully purchased something just a moment ago.

    After you receive a ProcessPurchase the money will have been exchanged on the Store and it is up to your game to make whatever gameplay changes come from making that purchase.

    3. To check if a player owns a non-consumable, after OnInitialized, access the IStoreController’s product array and look to see if there is a product with a

    `hasReceipt == true`. E.g.` if (m_StoreController.products.WithID(kProductIDSword).hasReceipt == true) { Debug.Log("I own " + kProductIDSword); }

    Let me know if you have any other questions!
     
  3. HotPhone

    HotPhone

    Joined:
    May 14, 2014
    Posts:
    53
    Thanks, I will follow the google steps in 1. and try out tomorrow. When buying works on my phone, probably I will be able to make it work with your tipps.
     
    mpinol likes this.
  4. HotPhone

    HotPhone

    Joined:
    May 14, 2014
    Posts:
    53
    I made it work, I'll post some problems here I encountered, maybe someone else is also struggling at it,

    1. Buy worked in the editor, but on the phone nothing happened:

    - I had to release an Alpha test version in Google Play
    - Had to set the products to active
    - Had to add myself as a tester

    2. Buy worked on the phone but I got a "Developer cant purchase his own items" error:

    - I had to completely delete my developers google account from my phone

    3. Another error "Items can't be purchased"

    - I dont know exactly how I fixed it
    - I changed the product ids in developers console from "id" to "package.id" for example:
    from "unlock1" to "com.example.game.unlock1"
    - I waited even longer, maybe google needed some more time to publish the app correctly.

    4. Purchase finally worked on my phone. I could unlock characters, but when I restarted the game, everything was locked again. I fixed it like this:

    public void OnInitialized (IStoreController controller, IExtensionProvider extensions)
    {
    // Purchasing has succeeded initializing. Collect our Purchasing references.
    Debug.Log ("OnInitialized: PASS");

    // Overall Purchasing system, configured with products for this application.
    m_StoreController = controller;
    // Store specific subsystem, for accessing device-specific store features.
    m_StoreExtensionProvider = extensions;
    RestoreNonConsumable ();
    }

    public void RestoreNonConsumable ()
    {
    if (m_StoreController.products.WithID (kProductIDRemoveAds).hasReceipt == true) {
    // Thats also what happens directly after the purchase
    purchaseHandler.RemoveAds ();
    }
    if (m_StoreController.products.WithID (kProductIDChar1).hasReceipt == true) {
    // Thats also what happens directly after the purchase
    purchaseHandler.UnlockChar1 ();
    }
    if (m_StoreController.products.WithID (kProductIDChar2).hasReceipt == true) {
    // Thats also what happens directly after the purchase
    purchaseHandler.UnlockChar2 ();
    }
    if (m_StoreController.products.WithID (kProductIDChar3).hasReceipt == true) {
    // Thats also what happens directly after the purchase
    purchaseHandler.UnlockChar3 ();
    }
    if (m_StoreController.products.WithID (kProductIDChar4).hasReceipt == true) {
    // Thats also what happens directly after the purchase
    purchaseHandler.UnlockChar4 ();
    }
    }
     
    mpinol and erika_d like this.
Thread Status:
Not open for further replies.