From 0caadb66c52b0521e81cfb1601fb47b21e9713d9 Mon Sep 17 00:00:00 2001 From: Philippe Creytens Date: Mon, 5 Mar 2018 20:25:06 +0100 Subject: [PATCH 1/4] add introductory price android --- .../InAppBillingProduct.cs | 19 ++++++++++++++++ .../InAppBillingImplementation.cs | 22 +++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Plugin.InAppBilling.Abstractions/InAppBillingProduct.cs b/src/Plugin.InAppBilling.Abstractions/InAppBillingProduct.cs index a62addc..7aa8a72 100644 --- a/src/Plugin.InAppBilling.Abstractions/InAppBillingProduct.cs +++ b/src/Plugin.InAppBilling.Abstractions/InAppBillingProduct.cs @@ -41,6 +41,25 @@ public class InAppBillingProduct /// public Int64 MicrosPrice { get; set; } + /// + /// Gets or sets the localized introductory price. + /// + /// The localized introductory price. + public string LocalizedIntroductoryPrice { get; set; } + + /// + /// Introductory price of the product in micor-units + /// + /// The introductory price. + public Int64 MicrosIntroductoryPrice { get; set; } + + /// + /// Gets a value indicating whether this + /// has introductory price. This is an optional value in the answer from the server, requires a boolean to check if this exists + /// + /// true if has introductory price; otherwise, false. + public bool HasIntroductoryPrice => !string.IsNullOrEmpty(LocalizedIntroductoryPrice); + } } \ No newline at end of file diff --git a/src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs b/src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs index 0cfc483..2226ec3 100644 --- a/src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs +++ b/src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs @@ -105,7 +105,9 @@ public async override Task> GetProductInfoAsync CurrencyCode = product.CurrencyCode, LocalizedPrice = product.Price, ProductId = product.ProductId, - MicrosPrice = product.MicrosPrice + MicrosPrice = product.MicrosPrice, + LocalizedIntroductoryPrice = product.IntroductoryPrice, + MicrosIntroductoryPrice = product.IntroductoryPriceAmountMicros }); } @@ -711,9 +713,21 @@ public Product() [JsonProperty(PropertyName = "price_amount_micros")] public Int64 MicrosPrice { get; set; } - public override string ToString() - { - return string.Format("[Product: Title={0}, Price={1}, Type={2}, Description={3}, ProductId={4}]", Title, Price, Type, Description, ProductId); + [JsonProperty(PropertyName = "introductoryPrice")] + public string IntroductoryPrice { get; set; } + + // 0 is default if this property is not set + [JsonProperty(PropertyName = "introductoryPriceAmountMicros")] + public Int64 IntroductoryPriceAmountMicros { get; set; } + + [JsonProperty(PropertyName = "introductoryPricePeriod")] + public string IntroductoryPricePeriod { get; set; } + + [JsonProperty(PropertyName = "introductoryPriceCycles")] + public int IntroductoryPriceCycles { get; set; } + + public override string ToString() { + return string.Format("[Product: Title={0}, Price={1}, Type={2}, Description={3}, ProductId={4}, CurrencyCode={5}, MicrosPrice={6}, IntroductoryPrice={7}, IntroductoryPriceAmountMicros={8}, IntroductoryPricePeriod={9}, IntroductoryPriceCycles={10}]", Title, Price, Type, Description, ProductId, CurrencyCode, MicrosPrice, IntroductoryPrice, IntroductoryPriceAmountMicros, IntroductoryPricePeriod, IntroductoryPriceCycles); } } From ebfd8557ad9535ef1a4c6662aba41476f12b1cc3 Mon Sep 17 00:00:00 2001 From: Philippe Creytens Date: Mon, 5 Mar 2018 20:29:33 +0100 Subject: [PATCH 2/4] add introductory price ios --- .../InAppBillingImplementation.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs b/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs index 9cb3c76..d8955e2 100644 --- a/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs +++ b/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs @@ -56,14 +56,15 @@ public async override Task> GetProductInfoAsync { var products = await GetProductAsync(productIds); - return products.Select(p => new InAppBillingProduct - { - LocalizedPrice = p.LocalizedPrice(), - MicrosPrice = (long)(p.Price.DoubleValue * 1000000d), - Name = p.LocalizedTitle, - ProductId = p.ProductIdentifier, - Description = p.LocalizedDescription, - CurrencyCode = p.PriceLocale?.CurrencyCode ?? string.Empty + return products.Select(p => new InAppBillingProduct { + LocalizedPrice = p.LocalizedPrice(), + MicrosPrice = (long)(p.Price.DoubleValue * 1000000d), + Name = p.LocalizedTitle, + ProductId = p.ProductIdentifier, + Description = p.LocalizedDescription, + CurrencyCode = p.PriceLocale?.CurrencyCode ?? string.Empty, + LocalizedIntroductoryPrice = p.IntroductoryPrice != null ? p.IntroductoryPrice.LocalizedPrice() : "", + MicrosIntroductoryPrice = p.IntroductoryPrice != null ? (long)(p.Price.DoubleValue * 1000000d) : 0 }); } @@ -537,5 +538,16 @@ public static string LocalizedPrice(this SKProduct product) Console.WriteLine(" ** formatter.StringFromNumber(" + product.Price + ") = " + formattedString + " for locale " + product.PriceLocale.LocaleIdentifier); return formattedString; } + + public static string LocalizedPrice(this SKProductDiscount product) { + var formatter = new NSNumberFormatter() { + FormatterBehavior = NSNumberFormatterBehavior.Version_10_4, + NumberStyle = NSNumberFormatterStyle.Currency, + Locale = product.PriceLocale + }; + var formattedString = formatter.StringFromNumber(product.Price); + Console.WriteLine(" ** formatter.StringFromNumber(" + product.Price + ") = " + formattedString + " for locale " + product.PriceLocale.LocaleIdentifier); + return formattedString; + } } } From 549743c6f9550bd8aaf6c6dbf4bbff60401fa1c0 Mon Sep 17 00:00:00 2001 From: Philippe Creytens Date: Tue, 20 Mar 2018 20:58:12 +0100 Subject: [PATCH 3/4] added ios systemversion check --- src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs b/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs index d8955e2..db81e86 100644 --- a/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs +++ b/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs @@ -56,6 +56,8 @@ public async override Task> GetProductInfoAsync { var products = await GetProductAsync(productIds); + var operatingSystemHasIntroductoryPrice = NSProcessInfo.ProcessInfo.IsOperatingSystemAtLeastVersion(new NSOperatingSystemVersion(11, 2, 0)); + return products.Select(p => new InAppBillingProduct { LocalizedPrice = p.LocalizedPrice(), MicrosPrice = (long)(p.Price.DoubleValue * 1000000d), @@ -63,9 +65,9 @@ public async override Task> GetProductInfoAsync ProductId = p.ProductIdentifier, Description = p.LocalizedDescription, CurrencyCode = p.PriceLocale?.CurrencyCode ?? string.Empty, - LocalizedIntroductoryPrice = p.IntroductoryPrice != null ? p.IntroductoryPrice.LocalizedPrice() : "", - MicrosIntroductoryPrice = p.IntroductoryPrice != null ? (long)(p.Price.DoubleValue * 1000000d) : 0 - }); + LocalizedIntroductoryPrice = operatingSystemHasIntroductoryPrice && p.IntroductoryPrice != null ? p.IntroductoryPrice.LocalizedPrice() : "", + MicrosIntroductoryPrice = operatingSystemHasIntroductoryPrice && p.IntroductoryPrice != null ? (long)(p.Price.DoubleValue * 1000000d) : 0 + }); } Task> GetProductAsync(string[] productId) From fe31234b9bdacb56a68410cc50cd2c0e417c76f8 Mon Sep 17 00:00:00 2001 From: Philippe Creytens Date: Thu, 22 Mar 2018 19:20:21 +0100 Subject: [PATCH 4/4] updated IntroductoryPrice doublevalue and added extension method to check valid introductoryprice --- .../InAppBillingImplementation.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs b/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs index db81e86..b0e892a 100644 --- a/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs +++ b/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using UIKit; namespace Plugin.InAppBilling { @@ -56,8 +57,6 @@ public async override Task> GetProductInfoAsync { var products = await GetProductAsync(productIds); - var operatingSystemHasIntroductoryPrice = NSProcessInfo.ProcessInfo.IsOperatingSystemAtLeastVersion(new NSOperatingSystemVersion(11, 2, 0)); - return products.Select(p => new InAppBillingProduct { LocalizedPrice = p.LocalizedPrice(), MicrosPrice = (long)(p.Price.DoubleValue * 1000000d), @@ -65,8 +64,8 @@ public async override Task> GetProductInfoAsync ProductId = p.ProductIdentifier, Description = p.LocalizedDescription, CurrencyCode = p.PriceLocale?.CurrencyCode ?? string.Empty, - LocalizedIntroductoryPrice = operatingSystemHasIntroductoryPrice && p.IntroductoryPrice != null ? p.IntroductoryPrice.LocalizedPrice() : "", - MicrosIntroductoryPrice = operatingSystemHasIntroductoryPrice && p.IntroductoryPrice != null ? (long)(p.Price.DoubleValue * 1000000d) : 0 + LocalizedIntroductoryPrice = p.IntroductoryPrice.CanBeUsed() ? p.IntroductoryPrice.LocalizedPrice() : "", + MicrosIntroductoryPrice = p.IntroductoryPrice.CanBeUsed() ? (long)(p.IntroductoryPrice.Price.DoubleValue * 1000000d) : 0 }); } @@ -518,6 +517,8 @@ public static PurchaseState GetPurchaseState(this SKPaymentTransaction transacti [Preserve(AllMembers = true)] static class SKProductExtension { + static bool IsiOS112 => UIDevice.CurrentDevice.CheckSystemVersion(11, 2); + /// /// Use Apple's sample code for formatting a SKProduct price /// https://developer.apple.com/library/ios/#DOCUMENTATION/StoreKit/Reference/SKProduct_Reference/Reference/Reference.html#//apple_ref/occ/instp/SKProduct/priceLocale @@ -551,5 +552,10 @@ public static string LocalizedPrice(this SKProductDiscount product) { Console.WriteLine(" ** formatter.StringFromNumber(" + product.Price + ") = " + formattedString + " for locale " + product.PriceLocale.LocaleIdentifier); return formattedString; } + + public static bool CanBeUsed(this SKProductDiscount product) + { + return IsiOS112 && product != null; + } } }