Exemple #1
0
        void InstantiateBillingClientAndMakeConnection()
        {
            _billingClientStateListener = new BillingClientStateListener();
            _billingClientStateListener.OnBillingServiceDisconnected += () => {
                Debug.Log("Service disconnected");
                EndConnection();
                //InstantiateBillingClientAndMakeConnection();
            };

            _billingClientStateListener.OnBillingSetupFinished += (billingResult) => MarkBillingClientStartConnectionCallComplete(billingResult);

            // Set ready flag to false as this action could be triggered when in-app billing service is disconnected.
            _billingClientReady = false;

            var context = JniUtils.GetApplicationContext();

            _billingClient = new AndroidJavaObject("com.android.billingclient.api.BillingClientImpl",
                                                   "3.0.0-unity");

            _billingClient.Call(
                "initialize",
                context,
                null,
                _deferredPurchasesEnabled);

            _billingClient.Call("startConnection", _billingClientStateListener);
        }
Exemple #2
0
        // Unity IAP framework will call this method after Initialize method regardless.
        public void RetrieveProducts(ReadOnlyCollection <ProductDefinition> products)
        {
            _billingClientStateListener = new BillingClientStateListener();
            // Retry connection when Play Billing Service is disconnected.
            _billingClientStateListener.OnBillingServiceDisconnected += () =>
            {
                _billingUtil.LogWarningFormat("Service disconnected, retrying connection...");
                EndConnection();
                InstantiateBillingClientAndMakeConnection();
            };
            _billingClientStateListener.OnBillingSetupFinished += (billingResult) =>
            {
                MarkBillingClientStartConnectionCallComplete(billingResult);
                if (_billingClientReady)
                {
                    _inventory.UpdateCatalog(products);

                    // Kick off tasks to retrieve products information on the main thread.
                    _billingUtil.RunOnMainThread(() =>
                                                 RetrieveProductsInternal(products));
                }
                else
                {
                    _billingUtil.LogWarningFormat("Google Play Store: play billing service unavailable!");
                    _billingUtil.RunOnMainThread(() =>
                                                 _callback.OnSetupFailed(InitializationFailureReason.PurchasingUnavailable));
                }
            };

            InstantiateBillingClientAndMakeConnection();
        }
Exemple #3
0
        public void Initialize(IStoreCallback callback)
        {
            _callback = callback;

            _billingClientStateListener = new BillingClientStateListener();
            // Retry connection when Play Billing Service is disconnected.
            _billingClientStateListener.OnBillingServiceDisconnected += () =>
            {
                _billingUtil.LogWarningFormat("Service disconnected, retrying connection...");
                EndConnection();
                InstantiateBillingClientAndMakeConnection();
            };
            // Mark Billing Client startConnection method call as completed.
            _billingClientStateListener.OnBillingSetupFinished += MarkBillingClientStartConnectionCallComplete;

            InstantiateBillingClientAndMakeConnection();
            // Block this method until startConnection call finishes. This is because the follow-up call will depend on
            // this connection.
            _billingClientStartConnectionCallStatus.WaitOne(Constants.BillingClientAsyncTimeout);
        }