Skip to content

Commit

Permalink
updated IntroductoryPrice doublevalue and added extension method to c…
Browse files Browse the repository at this point in the history
…heck valid introductoryprice
  • Loading branch information
Philippe Creytens committed Mar 22, 2018
1 parent 549743c commit fe31234
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using UIKit;

namespace Plugin.InAppBilling
{
Expand Down Expand Up @@ -56,17 +57,15 @@ public async override Task<IEnumerable<InAppBillingProduct>> 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),
Name = p.LocalizedTitle,
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
});
}

Expand Down Expand Up @@ -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);

/// <remarks>
/// 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
Expand Down Expand Up @@ -551,5 +552,10 @@ public static string LocalizedPrice(this SKProduct 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;
}
}
}

0 comments on commit fe31234

Please sign in to comment.