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

Need help with in-app purchases

Discussion in 'Android' started by squigglyo, Apr 15, 2014.

  1. squigglyo

    squigglyo

    Joined:
    May 21, 2012
    Posts:
    107
    Ive been working on trying to get my app to work with in app purchases and I am stuck.

    I am using OpenIAB at the moment, and have gotten to the point where I can get it to try and make a purchase, but I am met with an error that says 'The item you were attempting to purchase could not be found"

    I must be missing a step somewhere...

    What I have done:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4. using OpenIabPlugin;
    5.  
    6. public class OpenIAB_Init : MonoBehaviour {
    7.  
    8.     public string public_key = "INSERT_KEY";
    9.     public string SKU = "INSERT_SKU";
    10.     //public string STORE_CUSTOM = "store";
    11.     #if UNITY_ANDROID
    12.  
    13.     private void OnEnable() {
    14.         // Listen to all events for illustration purposes
    15.         OpenIABEventManager.billingSupportedEvent += billingSupportedEvent;
    16.         OpenIABEventManager.billingNotSupportedEvent += billingNotSupportedEvent;
    17.         OpenIABEventManager.queryInventorySucceededEvent += queryInventorySucceededEvent;
    18.         OpenIABEventManager.queryInventoryFailedEvent += queryInventoryFailedEvent;
    19.         OpenIABEventManager.purchaseSucceededEvent += purchaseSucceededEvent;
    20.         OpenIABEventManager.purchaseFailedEvent += purchaseFailedEvent;
    21.         OpenIABEventManager.consumePurchaseSucceededEvent += consumePurchaseSucceededEvent;
    22.         OpenIABEventManager.consumePurchaseFailedEvent += consumePurchaseFailedEvent;
    23.     }
    24.     private void OnDisable() {
    25.         // Remove all event handlers
    26.         OpenIABEventManager.billingSupportedEvent -= billingSupportedEvent;
    27.         OpenIABEventManager.billingNotSupportedEvent -= billingNotSupportedEvent;
    28.         OpenIABEventManager.queryInventorySucceededEvent -= queryInventorySucceededEvent;
    29.         OpenIABEventManager.queryInventoryFailedEvent -= queryInventoryFailedEvent;
    30.         OpenIABEventManager.purchaseSucceededEvent -= purchaseSucceededEvent;
    31.         OpenIABEventManager.purchaseFailedEvent -= purchaseFailedEvent;
    32.         OpenIABEventManager.consumePurchaseSucceededEvent -= consumePurchaseSucceededEvent;
    33.         OpenIABEventManager.consumePurchaseFailedEvent -= consumePurchaseFailedEvent;
    34.     }
    35.    
    36.     private void Start() {
    37.         // Map sku for different stores
    38.         OpenIAB.mapSku(SKU, OpenIAB.STORE_GOOGLE, "google-play.sku");
    39.         //OpenIAB.mapSku(SKU, STORE_CUSTOM, "onepf.sku");
    40.  
    41.        
    42.  
    43.         OpenIAB.init(new Dictionary<string, string> {
    44.             {OpenIAB.STORE_GOOGLE, public_key}//,
    45.             //{OpenIAB.STORE_TSTORE, public_key},
    46.             //{OpenIAB.STORE_SAMSUNG, public_key},
    47.             //{OpenIAB.STORE_YANDEX, public_key}
    48.         });
    49.     }
    50.  
    51.     //      OpenIAB.purchaseProduct(SKU);
    52.     //      OpenIAB.unbindService();
    53.  
    54.    
    55.  
    56.    
    57.     private void billingSupportedEvent() {
    58.         Debug.Log("billingSupportedEvent");
    59.     }
    60.     private void billingNotSupportedEvent(string error) {
    61.         Debug.Log("billingNotSupportedEvent: " + error);
    62.     }
    63.     private void queryInventorySucceededEvent(Inventory inventory) {
    64.         Debug.Log("queryInventorySucceededEvent: " + inventory);
    65.     }
    66.     private void queryInventoryFailedEvent(string error) {
    67.         Debug.Log("queryInventoryFailedEvent: " + error);
    68.     }
    69.     private void purchaseSucceededEvent(Purchase purchase) {
    70.         Debug.Log("purchaseSucceededEvent: " + purchase);
    71.     }
    72.     private void purchaseFailedEvent(string error) {
    73.         Debug.Log("purchaseFailedEvent: " + error);
    74.     }
    75.     private void consumePurchaseSucceededEvent(Purchase purchase) {
    76.         Debug.Log("consumePurchaseSucceededEvent: " + purchase);
    77.     }
    78.     private void consumePurchaseFailedEvent(string error) {
    79.         Debug.Log("consumePurchaseFailedEvent: " + error);
    80.     }
    81.     #endif
    82. }
    83.  
    That is put on an object in the scene. The public key is set, gotten from my Google Dev Page from the "YOUR LICENSE KEY FOR THIS APPLICATION" section.
    The Sku, is set as the ID I set for my in-app purchase item in my Dev Center.
    The item is set to active, and I have uploaded an APK for an Alpha build.

    I have a button that calls
    Code (csharp):
    1.  
    2. OpenIAB.purchaseProduct(SKU);
    3.  

    What am I missing? This is such a confusing task to accomplish...:confused:
     
  2. McTomas

    McTomas

    Joined:
    Jan 6, 2014
    Posts:
    8
    Hi,

    You need to add your apk to google developer console and use the exactly same apk version on your phone to test. Add your testing account to the developer console and use that account to buy your in-app.
    Dont forget to sign your apk ;)

    Cheers
     
  3. squigglyo

    squigglyo

    Joined:
    May 21, 2012
    Posts:
    107
    The alpha APK is the exact same as the one on my phone.
    My testing account is added (its the same as my developer account, not sure if that matters)
    The APK is signed.

    Still the same thing
     
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,158
    Is the bundle identifier in Unity the same as displayed in Google Play? That's the point I forget sometimes.
     
  5. squigglyo

    squigglyo

    Joined:
    May 21, 2012
    Posts:
    107
    Yep, thats the same too
     
  6. squigglyo

    squigglyo

    Joined:
    May 21, 2012
    Posts:
    107
    Ok, so going through everything to make sure its all correct.
    The code in my original post is what I am using.
    The SKU in the app matches the item ID in the developer console.
    The public_key variable in my code is set to the Base64-encoded RSA public key found in the services APIs section of the dev console.

    This is the manifest im using
    The APK i have uploaded is the same as the one being tested.
    my testing account is the one im using to download the game on the app store and it gets the alpha build instead of the official build, so thats all working there.
    The in app purchase is set to active in the dev console, as well as Managed Product


    Everything should be working perfectly... im so confused :(
     
  7. squigglyo

    squigglyo

    Joined:
    May 21, 2012
    Posts:
    107
    using the SKU android.test.purchased as per the google docs returns the same
    "the item you were attempting to purchase could not be found"

    :(
     
  8. squigglyo

    squigglyo

    Joined:
    May 21, 2012
    Posts:
    107
    Using the test scene for OpenIAB but replacing the SKU and public Key doesnt seem to work either...
     
  9. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    I am having a similar issue. Did you ever find an answer to your problem squigglyo?
     
  10. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    I believe the testing account must be different than the developer account.
     
  11. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    I have a similar problem. Trying to implement OpenIAB.
    First, I call queryInventory and it prints all my products (I have 4 products) with their details. So I think the version code, bundle ID etc works well and the connection between the google play and the game installed on my phone is ok.

    Then I want to buy something. I press a button and call purchaseProduct. Nothing happens, no events fired and the log is clean. I didn't map the skus, but I read it's not important for the google play.

    Can anyone help me to solve the problem?
     
  12. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    Guys, no ideas? Does anyone else use OpenIAB for IAPs in your games?
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,158
    We've been using OpenIAB extensively in Simple IAP System. Did you check that your AndroidManifest includes all permissions and activities required by OpenIAB?
     
  14. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    I didn't want to use other plugins, just a clear OpenIAB for Unity.
    Yes, I checked all the requirements, they don't have them too many. Everything according to the manual.