onepf / OpenIAB

Open In-App Billing for Google Play, SlideMe, Amazon Store, Nokia Store, Samsung Apps, Yandex.Store, Appland, Aptoide, AppMall and Fortumo.
http://onepf.org/openiab/
Apache License 2.0
475 stars 171 forks source link

Unity OpenIAB Integration fails because there is no popup showing after test purchase is clicked #479

Closed OmerCeliker closed 9 years ago

OmerCeliker commented 9 years ago

I followed the instructions at this link. https://github.com/onepf/OpenIAB-Unity-Plugin/wiki/How-to-use-OpenIAB-Unity-Plugin-with-Google-Play OpenIAB can connect to the google store and get the list of inventory okay but inapp purchase pop up will not display.

Please help with the issue mentioned in the title. Thank you.

I notice there are 2 manifest files in the project. AndroidManifest.xml and AndroidManifest 1.xml

Partial view from AndroidManifest.xml

<uses-feature android:name="android.hardware.telephony" android:required="false" />
<permission android:name="com.tmoney.vending.INBILLING"/>

Partial view from AndroidManifest 1.xml

<!--all-->
<uses-permission android:name="android.permission.INTERNET"/>
<!--Google Play-->
<uses-permission android:name="com.android.vending.BILLING" />
<!--Open Store-->
<uses-permission android:name="org.onepf.openiab.permission.BILLING" />
<!--Amazon requires no permissions -->
<!--Samsung Apps-->
<uses-permission android:name="com.sec.android.iap.permission.BILLING" />
<!--Nokia-->
<uses-permission android:name="com.nokia.payment.BILLING"/>
<!--SlideME-->
<uses-permission android:name="com.slideme.sam.manager.inapp.permission.BILLING" />

The file I modified is below.

/***

  • Copyright 2012-2014 One Platform Foundation *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. **/

using UnityEngine; using OnePF; using System.Collections.Generic; using System; using System.IO; /**

  • Example of OpenIAB usage */ public class OpenIABTest : MonoBehaviour { const string SKU = "sku";

    string _label = "Not initialized"; bool _isInitialized = false; Inventory _inventory = null;

    void appendLog(string log){

    try{
    
      using (StreamWriter w = File.AppendText(Application.persistentDataPath + "/log.txt"))
      {
          w.WriteLine(log);
      }
    }
    catch(Exception ex){
    
    }

    }

    private void OnEnable() { // Listen to all events for illustration purposes OpenIABEventManager.billingSupportedEvent += billingSupportedEvent; OpenIABEventManager.billingNotSupportedEvent += billingNotSupportedEvent; OpenIABEventManager.queryInventorySucceededEvent += queryInventorySucceededEvent; OpenIABEventManager.queryInventoryFailedEvent += queryInventoryFailedEvent; OpenIABEventManager.purchaseSucceededEvent += purchaseSucceededEvent; OpenIABEventManager.purchaseFailedEvent += purchaseFailedEvent; OpenIABEventManager.consumePurchaseSucceededEvent += consumePurchaseSucceededEvent; OpenIABEventManager.consumePurchaseFailedEvent += consumePurchaseFailedEvent; } private void OnDisable() { // Remove all event handlers OpenIABEventManager.billingSupportedEvent -= billingSupportedEvent; OpenIABEventManager.billingNotSupportedEvent -= billingNotSupportedEvent; OpenIABEventManager.queryInventorySucceededEvent -= queryInventorySucceededEvent; OpenIABEventManager.queryInventoryFailedEvent -= queryInventoryFailedEvent; OpenIABEventManager.purchaseSucceededEvent -= purchaseSucceededEvent; OpenIABEventManager.purchaseFailedEvent -= purchaseFailedEvent; OpenIABEventManager.consumePurchaseSucceededEvent -= consumePurchaseSucceededEvent; OpenIABEventManager.consumePurchaseFailedEvent -= consumePurchaseFailedEvent; }

    private void Start() { // Map skus for different stores
    OpenIAB.mapSku(SKU, OpenIAB_Android.STORE_GOOGLE, "sku");

    }

    const float X_OFFSET = 10.0f; const float Y_OFFSET = 10.0f; const int SMALL_SCREEN_SIZE = 800; const int LARGE_FONT_SIZE = 34; const int SMALL_FONT_SIZE = 24; const int LARGE_WIDTH = 380; const int SMALL_WIDTH = 160; const int LARGE_HEIGHT = 100; const int SMALL_HEIGHT = 40;

    int _column = 0; int _row = 0;

    private bool Button(string text) { float width = Screen.width / 2.0f - X_OFFSET * 2; float height = (Screen.width >= SMALL_SCREEN_SIZE || Screen.height >= SMALL_SCREEN_SIZE) ? LARGE_HEIGHT : SMALL_HEIGHT;

    bool click = GUI.Button(new Rect(
      X_OFFSET + _column * X_OFFSET * 2 + _column * width, 
      Y_OFFSET + _row * Y_OFFSET + _row * height, 
      width, height),
      text);
    
    ++_column;
    if (_column > 1)
    {
      _column = 0;
      ++_row;
    }
    
    return click;

    }

    private void OnGUI() { _column = 0; _row = 0;

    GUI.skin.button.fontSize = (Screen.width >= SMALL_SCREEN_SIZE || Screen.height >= SMALL_SCREEN_SIZE) ? LARGE_FONT_SIZE : SMALL_FONT_SIZE;
    
    if (Button("Int.OpnIABv2"))
    {
      // Application public key
    
      var googlePublicKey = "OUR_PULIC_KEY_HERE";
    
      var options = new Options();
      options.checkInventoryTimeoutMs = Options.INVENTORY_CHECK_TIMEOUT_MS * 2;
      options.discoveryTimeoutMs = Options.DISCOVER_TIMEOUT_MS * 2;
      options.checkInventory = false;
      options.verifyMode = OptionsVerifyMode.VERIFY_SKIP;
      options.prefferedStoreNames = new string[] { OpenIAB_Android.STORE_GOOGLE };
      options.availableStoreNames = new string[] { OpenIAB_Android.STORE_GOOGLE };
      options.storeKeys = new Dictionary<string, string> { {OpenIAB_Android.STORE_GOOGLE, googlePublicKey} };
    
      options.storeSearchStrategy = SearchStrategy.INSTALLER_THEN_BEST_FIT;
    
      // Transmit options and start the service
      OpenIAB.init(options);
    appendLog("called OpenIAB.init");
    }
    
    GUI.Label(new Rect(10, 300, 300, 20), _label);
    if (!_isInitialized)
      return;
    //_label = "initialized";
    
    if (Button("Query Inventory"))
    {
      appendLog("Query Inventory");
      OpenIAB.queryInventory(new string[] { SKU });
    }
    
    if (Button("Purchase Product"))
    {
      appendLog("Purchase Product");
      OpenIAB.purchaseProduct(SKU);
    }
    
    if (Button("Consume Product"))
    {
       appendLog("Consume Product");
      if (_inventory != null && _inventory.HasPurchase(SKU))
          OpenIAB.consumeProduct(_inventory.GetPurchase(SKU));
    }

// Android specific buttons

if UNITY_ANDROID

    if (Button("Test Purchase"))
    {
        OpenIAB.purchaseProduct("android.test.purchased");
   appendLog("Test Purchase");
    }

    if (Button("Test Consume"))
    {
    appendLog("Test Consume");
        if (_inventory != null && _inventory.HasPurchase("android.test.purchased"))
            OpenIAB.consumeProduct(_inventory.GetPurchase("android.test.purchased"));
    }

    if (Button("Test Item Unavailable"))
    {
    appendLog("Test Item Unavailable");
        OpenIAB.purchaseProduct("android.test.item_unavailable");
    }

    if (Button("Test Purchase Canceled"))
    {
    appendLog("Test Purchase Canceled");
        OpenIAB.purchaseProduct("android.test.canceled");
    }

endif

}

private void billingSupportedEvent()
{
    _isInitialized = true;
    Debug.Log("billingSupportedEvent");
    _label = "billingSupportedEvent " + "initialized";
    appendLog(_label);
}
private void billingNotSupportedEvent(string error)
{
    Debug.Log("billingNotSupportedEvent: " + error);
    _label = "billingNotSupportedEvent: " + error;
    appendLog(_label);
}
private void queryInventorySucceededEvent(Inventory inventory)
{
    Debug.Log("queryInventorySucceededEvent: " + inventory);
    if (inventory != null)
    {
        _label = inventory.ToString();
        _inventory = inventory;
        _label = "queryInventorySucceededEvent: " + inventory.ToString();
        appendLog(_label);
    }
}
private void queryInventoryFailedEvent(string error)
{
    Debug.Log("queryInventoryFailedEvent: " + error);
    _label = "queryInventoryFailedEvent: " + error;
    appendLog(_label);
}
private void purchaseSucceededEvent(Purchase purchase)
{
    Debug.Log("purchaseSucceededEvent: " + purchase);
    _label = "PURCHASED:" + purchase.ToString();
    appendLog(_label);
}
private void purchaseFailedEvent(int errorCode, string errorMessage)
{
    Debug.Log("purchaseFailedEvent: " + errorMessage);
    _label = "Purchase Failed: " + errorMessage;
    appendLog(_label);
}
private void consumePurchaseSucceededEvent(Purchase purchase)
{
    Debug.Log("consumePurchaseSucceededEvent: " + purchase);
    _label = "CONSUMED: " + purchase.ToString();
    appendLog(_label);
}
private void consumePurchaseFailedEvent(string error)
{
    Debug.Log("consumePurchaseFailedEvent: " + error);
    _label = "Consume Failed: " + error;
    appendLog(_label);
}

}

I created a log file for events that gets captured. The log is below.

called OpenIAB.init billingSupportedEvent initialized Test Consume Test Purchase Purchase Product Query Inventory Purchase Product queryInventorySucceededEvent: {purchaseMap:{},skuMap:{"sku":{[SkuDetails: type = inapp, SKU ...

OmerCeliker commented 9 years ago

The following was missing from AndroidManifest.xml, I am closing this issue.

<activity android:name="org.onepf.openiab.UnityProxyActivity"
      android:launchMode="singleTask"
      android:label="@string/app_name"
      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    </activity>

<receiver android:name="com.amazon.inapp.purchasing.ResponseReceiver">
   <intent-filter>
       <action
            android:name="com.amazon.inapp.purchasing.NOTIFY"
            android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY"/>
   </intent-filter>
</receiver>