示例#1
0
        private void ProcessPriceChangeResult(AndroidJavaObject billingResult, Action <bool> callback)
        {
            var responseCode = _jniUtils.GetResponseCodeFromBillingResult(billingResult);

            if (responseCode != BillingResponseCode.Ok)
            {
                _billingUtil.LogWarningFormat(
                    "Confirming subscription price change failed with error code {0} and debug message: {1}",
                    responseCode, JniUtils.GetDebugMessageFromBillingResult(billingResult));
            }

            callback.Invoke(responseCode == BillingResponseCode.Ok);
        }
示例#2
0
        private void MarkBillingClientStartConnectionCallComplete(AndroidJavaObject billingResult)
        {
            var responseCode = _jniUtils.GetResponseCodeFromBillingResult(billingResult);

            if (responseCode == BillingResponseCode.Ok)
            {
                _billingClientReady = true;
            }
            else
            {
                _billingUtil.LogErrorFormat(
                    "Failed to connect to service with error code '{0}' and debug message: '{1}'.",
                    responseCode, JniUtils.GetDebugMessageFromBillingResult(billingResult));
            }
        }
示例#3
0
        private void ProcessConsumePurchaseResult(string skuId, AndroidJavaObject billingResult)
        {
            var responseCode = _jniUtils.GetResponseCodeFromBillingResult(billingResult);

            if (responseCode == BillingResponseCode.Ok)
            {
                _inventory.RemovePurchase(skuId);
            }
            else
            {
                var debugMessage = JniUtils.GetDebugMessageFromBillingResult(billingResult);
                _billingUtil.LogErrorFormat(
                    "Failed to finish the transaction with error code {0} and debug message: {1}. " +
                    "Please consider to call FinishAdditionalTransaction using the extension.",
                    responseCode, debugMessage);
            }
        }
示例#4
0
        private void ProcessAcknowledgePurchaseResult(string skuId, SkuType skuType, AndroidJavaObject billingResult)
        {
            string productId;

            if (!_inventory.GetUnityProductId(skuId, out productId))
            {
                _billingUtil.LogErrorFormat(
                    "Couldn't find Unity product that maps to {0} when processing acknowledge purchase result",
                    skuId);
                return;
            }

            var responseCode = _jniUtils.GetResponseCodeFromBillingResult(billingResult);

            if (responseCode != BillingResponseCode.Ok)
            {
                _billingUtil.LogErrorFormat(
                    "Acknowledging purchase {0} failed with error code {1} and debug message: {2}.",
                    productId,
                    _jniUtils.GetResponseCodeFromBillingResult(billingResult),
                    JniUtils.GetDebugMessageFromBillingResult(billingResult));
                return;
            }

            // Call queryPurchases again to update the acknowledge status.
            var queryResult = QueryPurchasesForSkuType(skuType);

            if (queryResult != BillingResponseCode.Ok)
            {
                _billingUtil.LogWarningFormat(
                    "Update the purchase {0} after FinishTransaction failed with error code {1}. " +
                    "The purchase receipt might be out of date. One can call FetchAdditionalProducts " +
                    "on this product to get the updated purchase receipt.",
                    productId, queryResult);
            }

            // Double check updated results....
            var updateList = _inventory.UpdateProductDescriptionList(new List <string> {
                skuId
            });

            _callback.OnProductsRetrieved(updateList);
        }
示例#5
0
        private void ParsePurchaseResult(AndroidJavaObject billingResult, AndroidJavaObject javaPurchasesList)
        {
            var responseCode = _jniUtils.GetResponseCodeFromBillingResult(billingResult);
            var debugMessage = JniUtils.GetDebugMessageFromBillingResult(billingResult);

            if (responseCode == BillingResponseCode.Ok)
            {
                var purchasesList = _jniUtils.ParseJavaPurchaseList(javaPurchasesList);
                _inventory.UpdatePurchaseInventory(purchasesList);
                // Unity IAP only supports one purchase at a time.
                Purchase purchase = purchasesList.First();
                if (Google.Play.Billing.Internal.Purchase.State.Pending.Equals(purchase.PurchaseState))
                {
                    string unityProductId;
                    _inventory.GetUnityProductId(purchase.ProductId, out unityProductId);
                    _billingUtil.RunOnMainThread(() =>
                                                 _deferredPurchaseListener.Invoke(_callback.products.WithID(unityProductId)));
                }
                else
                {
                    _billingUtil.RunOnMainThread(() =>
                                                 _callback.OnPurchaseSucceeded(purchase.ProductId, purchase.JsonReceipt,
                                                                               purchase.TransactionId));
                }
            }
            else
            {
                _billingUtil.LogWarningFormat("Purchase failed with error code '{0}' and debug message: '{1}'",
                                              responseCode, debugMessage);
                PurchaseFailureReason purchaseFailureReason;
                switch (responseCode)
                {
                case BillingResponseCode.UserCancelled:
                    purchaseFailureReason = PurchaseFailureReason.UserCancelled;
                    break;

                case BillingResponseCode.ServiceTimeout:
                case BillingResponseCode.ServiceDisconnected:
                case BillingResponseCode.ServiceUnavailable:
                case BillingResponseCode.BillingUnavailable:
                    purchaseFailureReason = PurchaseFailureReason.PurchasingUnavailable;
                    break;

                case BillingResponseCode.ItemUnavailable:
                    purchaseFailureReason = PurchaseFailureReason.ProductUnavailable;
                    break;

                case BillingResponseCode.ItemAlreadyOwned:
                    purchaseFailureReason = PurchaseFailureReason.DuplicateTransaction;
                    break;

                default:
                    purchaseFailureReason = PurchaseFailureReason.Unknown;
                    break;
                }

                // Copy _productInPurchaseFlow.id into the delegate as the delegate is called by the main thread and
                // _productInPurchaseFlow will get cleaned up immediately in this thread.
                var productId = _productInPurchaseFlow.id;
                _billingUtil.RunOnMainThread(() =>
                                             _callback.OnPurchaseFailed(
                                                 new PurchaseFailureDescription(productId, purchaseFailureReason, debugMessage)));
            }

            _productInPurchaseFlow = null;
        }
示例#6
0
        void MarkBillingClientStartConnectionCallComplete(AndroidJavaObject billingResult)
        {
            var responseCode = this.GetResponseCodeFromBillingResult(billingResult);

            if (responseCode == BillingResponseCode.Ok)
            {
                _billingClientReady = true;
            }
            else
            {
                Debug.Log(
                    $"Failed to connect to service with error code '{responseCode}' and debug message: '{JniUtils.GetDebugMessageFromBillingResult(billingResult)}'.");
            }
        }