Hello everyone,
I am currently testing the OpenIAB In-App Purchase System - but I have one problem. I can buy products - that works fine. But after reinstalling the app I don´t know how to check if the product was bought already (It´s a permanent product). Clicking the buy button again only opens a black screen - without any information.
Can someone please explain me how to do this? I know this has something to do with OpenIAB.queryInventory - but I have no idea where to put the check.
Thank you!
My current code:
using UnityEngine;
using OnePF;
using System.Collections.Generic;
public class OpenIABTest : MonoBehaviour {
const string SKU = "sku";
#pragma warning disable 0414
string _label = "";
#pragma warning restore 0414
bool _isInitialized = false;
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, "game_mode_dart");
}
public void Initialize(){
var public_key = "mykey";
var options = new Options();
options.verifyMode = OptionsVerifyMode.VERIFY_SKIP;
options.storeKeys = new Dictionary<string, string> {
{OpenIAB_Android.STORE_GOOGLE, public_key}
};
// Transmit options and start the service
OpenIAB.init(options);
//OpenIAB.queryInventory();
}
public void Buy(){
OpenIAB.purchaseProduct("game_mode_dart");
}
private void billingSupportedEvent() {
_isInitialized = true;
Debug.Log("billingSupportedEvent");
}
private void billingNotSupportedEvent(string error) {
Debug.Log("billingNotSupportedEvent: " + error);
}
private void queryInventorySucceededEvent(Inventory inventory) {
Debug.Log("queryInventorySucceededEvent: " + inventory);
if (inventory != null)
_label = inventory.ToString();
}
private void queryInventoryFailedEvent(string error) {
Debug.Log("queryInventoryFailedEvent: " + error);
_label = error;
}
private void purchaseSucceededEvent(Purchase purchase) {
Debug.Log("purchaseSucceededEvent: " + purchase);
_label = "PURCHASED:" + purchase.ToString();
PlayerPrefs.SetInt("Abs",1);
}
private void purchaseFailedEvent(int errorCode, string errorMessage) {
Debug.Log("purchaseFailedEvent: " + errorMessage);
_label = "Purchase Failed: " + errorMessage;
}
private void consumePurchaseSucceededEvent(Purchase purchase) {
Debug.Log("consumePurchaseSucceededEvent: " + purchase);
_label = "CONSUMED: " + purchase.ToString();
}
private void consumePurchaseFailedEvent(string error) {
Debug.Log("consumePurchaseFailedEvent: " + error);
_label = "Consume Failed: " + error;
}
}