Beispiel #1
0
        // Launches billing flow using billingFlowParamBuilder, in addition, it will add corresponding
        // accountId, developerId parameters.
        private void LaunchBillingFlow(AndroidJavaObject billingFlowParamBuilder)
        {
            if (!string.IsNullOrEmpty(_obfuscatedProfileId))
            {
                billingFlowParamBuilder.Call <AndroidJavaObject>(
                    Constants.BillingFlowParamsBuilderSetObfuscatedProfileIdMethod, _obfuscatedProfileId);
            }

            if (!string.IsNullOrEmpty(_obfuscatedAccountId))
            {
                billingFlowParamBuilder.Call <AndroidJavaObject>(
                    Constants.BillingFlowParamsBuilderSetObfuscatedAccountIdMethod, _obfuscatedAccountId);
            }

            _billingClient.Call <AndroidJavaObject>(
                Constants.BillingClientLaunchBillingFlowMethod,
                JniUtils.GetUnityAndroidActivity(),
                billingFlowParamBuilder.Call <AndroidJavaObject>(Constants.BuildMethod));
        }
Beispiel #2
0
        public void ConfirmSubscriptionPriceChange(string productId, Action <bool> callback)
        {
            if (!IsGooglePlayInAppBillingServiceAvailable())
            {
                _billingUtil.RunOnMainThread(() => callback.Invoke(false));
                return;
            }

            ProductDefinition unityProduct;
            SkuDetails        skuDetails;

            if (!_inventory.GetUnityProductDefinition(productId, out unityProduct) ||
                !_inventory.GetSkuDetails(unityProduct.storeSpecificId, out skuDetails))
            {
                _billingUtil.LogErrorFormat("Cannot find SKU for Unity product {0}", productId);
                _billingUtil.RunOnMainThread(() => callback.Invoke(false));
                return;
            }

            var listener = new PriceChangeConfirmationListener();
            Action <AndroidJavaObject> cb = (billingResult) =>
                                            _billingUtil.RunOnMainThread(() => ProcessPriceChangeResult(billingResult, callback));

            listener.OnPriceChangeConfirmationResult += cb;

            using (var priceChangeConfirmationParamBuilder =
                       new AndroidJavaObject(Constants.PriceChangeFlowParamsBuilder)
                       .Call <AndroidJavaObject>(Constants.PriceChangeFlowParamsBuilderSetSkuDetailsMethod,
                                                 skuDetails.ToJava()))
            {
                _billingClient.Call(
                    Constants.LaunchPriceChangeConfirmationFlowMethod,
                    JniUtils.GetUnityAndroidActivity(),
                    priceChangeConfirmationParamBuilder.Call <AndroidJavaObject>(Constants.BuildMethod),
                    listener);
            }
        }