Skip to content

Commit

Permalink
add introductory price ios
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Creytens committed Mar 5, 2018
1 parent 0caadb6 commit ebfd855
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs
Expand Up @@ -56,14 +56,15 @@ public async override Task<IEnumerable<InAppBillingProduct>> 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
});
}

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

0 comments on commit ebfd855

Please sign in to comment.