Exemplo n.º 1
0
        /// <summary>
        /// Gets introductory offer details.
        /// Includes Free Trial.
        /// </summary>
        /// <param name="productID">Product ID</param>
        /// <returns>Offer details if exists.</returns>
        public async UniTask <IntroductoryOffer> GetIntroductoryOfferDetailsAsync(string productID)
        {
            Product[] products = await GetAvailableProductsAsync();

            if (products == null || products.Length == 0)
            {
                return(null);
            }

            var availableProducts = products.Where(pd => !pd.hasReceipt).ToArray();

            if (availableProducts == null || availableProducts.Length == 0)
            {
                return(null);
            }

            Product[] p = availableProducts.Where(a => a.definition.id == productID).ToArray();
            if (p.Length == 0)
            {
                return(null);
            }

            SkuDetails sku = GetSKU(productID);

            if (sku == null)
            {
                return(null);
            }

            return(new GooglePlayIntroductoryOfferFactory(sku).Make());
        }
Exemplo n.º 2
0
        private void LaunchBilling(SkuDetails sku, Activity parent)
        {
            Log.Debug(TAG, "LaunchBilling()");
            BillingFlowParams billingFlowParams = BillingFlowParams.NewBuilder()
                                                  .SetSkuDetails(sku)
                                                  .Build();

            billingClient.LaunchBillingFlow(parent, billingFlowParams);
        }
Exemplo n.º 3
0
        private void ShowThankYouMessage(SkuDetails item)
        {
            AlertDialog.Builder dialog = new AlertDialog.Builder(parent_activity);
            var alert = dialog.Create();

            alert.SetTitle("Thank you for purchasing: " + FormatTitle(item.Title));
            alert.SetMessage(item.Description);
            alert.SetButton("OK", (c, ev) => { });
            alert.Show();
        }
        public GooglePlayIntroductoryOfferFactory(SkuDetails sku)
        {
            // https://developer.android.com/reference/com/android/billingclient/api/SkuDetails?hl=ja
#if DEBUG_IAP
            Debug.Log("---GooglePlayIntroductoryOfferFactory");
            Debug.Log(sku.JsonSkuDetails);
#endif

            // Subscription period, specified in ISO 8601 format.
            Period regularPeriod = GetPeriod(sku.subscriptionPeriod);
            // The billing period of the introductory price, specified in ISO 8601 format.
            Period introductoryPeriod = GetPeriod(sku.introductoryPricePeriod);
            // Trial period configured in Google Play Console, specified in ISO 8601 format.
            Period freePeriod = GetPeriod(sku.freeTrialPeriod);

            // common
            // the title of the product.
            this.SetLocalizedTitle(sku.title);
            // the description of the product.
            this.SetLocalizedDescription(sku.description);
            // Returns ISO 4217 currency code for price and original price.
            this.SetISOCurrencyCode(sku.price_currency_code);

            // regular
            this.SetRegularPrice(sku.price_amount_micros / 1000000);
            this.SetLocalizedRegularPriceString(sku.price);
            this.SetRegularUnit(regularPeriod.Unit);
            this.SetRegularNumberOfUnit(regularPeriod.Number);

            if (introductoryPeriod != null)
            {
                this.SetIntroductory(true);
                // introductory
                this.SetIntroductoryUnit(introductoryPeriod.Unit);
                this.SetIntroductoryNumberOfUnits(introductoryPeriod.Number);
                // The number of subscription billing periods for which the user will be given the introductory price, such as 3.
                this.SetIntroductoryNumberOfPeriods(sku.introductoryPriceCycles);
                // Introductory price in micro-units.
                this.SetIntroductoryPrice(sku.introductoryPriceAmountMicros / 1000000);
                // Formatted introductory price of a subscription, including its currency sign, such as €3.99.
                this.SetIntroductoryPriceLocale(sku.introductoryPrice);
                this.SetLocalizedIntroductoryPriceString(sku.introductoryPrice);
            }

            if (freePeriod != null)
            {
                //  free trial
                this.SetFreeTrial(true);
                this.SetFreeTrialUnit(freePeriod.Unit);
                this.SetFreeTrialNumberOfUnits(freePeriod.Number); // (number of unit * number of period) * unit = free trial duration
                this.SetFreeTrialNumberOfPeriods(1);
            }

            this.SetOriginalJson(sku.JsonSkuDetails);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sku/Product details Handler
        /// </summary>
        /// <param name="billingResult"></param>
        /// <param name="skuDetails"></param>
        public void OnSkuDetailsResponse(BillingResult billingResult, IList <SkuDetails> skuDetails)
        {
            try
            {
                InAppBillingProducts = new List <InAppBillingProduct>();
                if (billingResult.ResponseCode == BillingResponseCode.Ok)
                {
                    // List<string> unavailableSkus = args.UnavailableSkus;
                    if (skuDetails?.Count > 0)
                    {
                        foreach (var product in skuDetails)
                        {
                            InAppBillingProducts.Add(new InAppBillingProduct
                            {
                                Description                = product.Description,
                                LocalizedPrice             = product.Price,
                                LocalizedIntroductoryPrice = product.IntroductoryPrice,
                                CurrencyCode               = product.PriceCurrencyCode,
                                MicrosIntroductoryPrice    = product.IntroductoryPriceAmountMicros,
                                MicrosPrice                = product.PriceAmountMicros,
                                ProductId                 = product.Sku,
                                Name                      = product.Title,
                                Type                      = product.Type,
                                IconUrl                   = product.IconUrl,
                                IsRewarded                = product.IsRewarded,
                                IntroductoryPrice         = product.IntroductoryPrice,
                                IntroductoryPriceCycles   = product.IntroductoryPriceCycles,
                                IntroductoryPricePeriod   = product.IntroductoryPricePeriod,
                                SubscriptionPeriod        = product.SubscriptionPeriod,
                                FreeTrialPeriod           = product.FreeTrialPeriod,
                                OriginalPrice             = product.OriginalPrice,
                                OriginalPriceAmountMicros = product.OriginalPriceAmountMicros
                            });
                        }

                        ProductToPurcase = skuDetails[0];
                    }
                }

                var errorCode = GetErrorCode(billingResult.ResponseCode);
                if (errorCode != null) //No error
                {
                    _tcsProducts?.TrySetException(errorCode);
                }
                else
                {
                    _tcsProducts?.TrySetResult(InAppBillingProducts);
                }
            }
            catch (Exception ex)
            {
                _tcsProducts?.TrySetException(ex);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Completes the Purchase
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        private async Task <PurchaseResult> DoPurchaseAsync(SkuDetails product)
        {
            if (BillingClient == null || !BillingClient.IsReady)
            {
                await ConnectAsync();
            }
            _tcsPurchase = new TaskCompletionSource <PurchaseResult>();

            BillingFlowParams flowParams   = BillingFlowParams.NewBuilder().SetSkuDetails(product).Build();
            BillingResult     responseCode = BillingClient.LaunchBillingFlow(CrossCurrentActivity.Current.Activity, flowParams);

            return(await _tcsPurchase?.Task ?? default);
        }
Exemplo n.º 7
0
    private void OnQueryInventorySucceeded(Inventory inventory)
    {
        SkuDetails skusDetail = inventory.GetSkuDetails(ItemPurchaseStore.AndroidStore);

        priceText.text = skusDetail.CurrencyCode + " " + skusDetail.PriceValue;

#if UNITY_ANDROID
        if (inventory.HasPurchase(ItemPurchaseStore.AndroidStore))
        {
            UserStockData userStock = UserStockData.Load();
            userStock.PlusMinGem(Gems);
            OpenIAB.consumeProduct(inventory.GetPurchase(ItemPurchaseStore.AndroidStore));
            MessagePopup.Show("You have bought " + Name);

            string command = "{";
            command += "action:BUY_PEARL";
            command += ",item:" + Name;
            command += "}";
            ServerStatistic.DoRequest(command);
        }
#elif UNITY_IOS
        if (inventory.HasPurchase(ItemPurchaseStore.IosStore))
        {
            UserStockData userStock = UserStockData.Load();
            userStock.PlusMinGem(Gems);
            OpenIAB.consumeProduct(inventory.GetPurchase(ItemPurchaseStore.IosStore));
            MessagePopup.Show("You have bought " + Name);

            string command = "{";
            command += "action:BUY_PEARL";
            command += ",item:" + Name;
            command += "}";
            ServerStatistic.DoRequest(command);
        }
#elif UNITY_WP8
        if (inventory.HasPurchase(ItemPurchaseStore.WpStore))
        {
            UserStockData userStock = UserStockData.Load();
            userStock.PlusMinGem(Gems);
            OpenIAB.consumeProduct(inventory.GetPurchase(ItemPurchaseStore.WpStore));
            MessagePopup.Show("You have bought " + Name);

            string command = "{";
            command += "action:BUY_PEARL";
            command += ",item:" + Name;
            command += "}";
            ServerStatistic.DoRequest(command);
        }
#endif
    }
Exemplo n.º 8
0
        /// <summary>
        /// Get SKU information from Google Play
        /// </summary>
        /// <returns>Dictionary key:productId / value:SKU detail</returns>
        public Dictionary <string, SkuDetails> GetSKUs()
        {
            Dictionary <string, string>     SKUs       = googlePlay.GetProductJSONDictionary();
            Dictionary <string, SkuDetails> SKUDetails = new Dictionary <string, SkuDetails>();

            foreach (var pair in SKUs)
            {
                SkuDetails detail = new SkuDetails();
                SkuDetails.FromJson(pair.Value, out detail);
                SKUDetails.Add(pair.Key, detail);
                DebugLog($"------- \n pair.Key={pair.Key}\ndetail.JsonSkuDetails={detail.JsonSkuDetails}");
            }

            return(SKUDetails);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Get SKU information from Google Play
        /// </summary>
        /// <param name="productId">target product id</param>
        /// <returns></returns>
        public SkuDetails GetSKU(string productId)
        {
            Dictionary <string, string> SKUs = GetSKUsJson();

            if (!SKUs.ContainsKey(productId))
            {
                DebugLog($"{productId} doesn't exist in SKU dictionary.");
                return(null);
            }

            SkuDetails detail = new SkuDetails();

            SkuDetails.FromJson(SKUs[productId], out detail);
            DebugLog(detail.JsonSkuDetails);

            return(detail);
        }
Exemplo n.º 10
0
 internal static InAppBillingProduct ToIAPProduct(this SkuDetails product)
 {
     return(new InAppBillingProduct
     {
         Name = product.Title,
         Description = product.Description,
         CurrencyCode = product.PriceCurrencyCode,
         LocalizedPrice = product.Price,
         ProductId = product.Sku,
         MicrosPrice = product.PriceAmountMicros,
         AndroidExtras = new InAppBillingProductAndroidExtras
         {
             SubscriptionPeriod = product.SubscriptionPeriod,
             LocalizedIntroductoryPrice = product.IntroductoryPrice,
             MicrosIntroductoryPrice = product.IntroductoryPriceAmountMicros,
             FreeTrialPeriod = product.FreeTrialPeriod,
             IconUrl = product.IconUrl,
             IntroductoryPriceCycles = product.IntroductoryPriceCycles,
             IntroductoryPricePeriod = product.IntroductoryPricePeriod,
             MicrosOriginalPriceAmount = product.OriginalPriceAmountMicros,
             OriginalPrice = product.OriginalPrice
         }
     });
 }