Skip to content

Commit

Permalink
Implement storefront
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Mar 7, 2022
1 parent cd325bb commit 64e5d17
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
31 changes: 29 additions & 2 deletions src/Plugin.InAppBilling/InAppBilling.apple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ public class InAppBillingImplementation : BaseInAppBilling
internal static bool HasIntroductoryOffer => UIKit.UIDevice.CurrentDevice.CheckSystemVersion(11, 2);
internal static bool HasProductDiscounts => UIKit.UIDevice.CurrentDevice.CheckSystemVersion(12, 2);
internal static bool HasSubscriptionGroupId => UIKit.UIDevice.CurrentDevice.CheckSystemVersion(12, 0);
internal static bool HasStorefront => UIKit.UIDevice.CurrentDevice.CheckSystemVersion(13, 0);
internal static bool HasFamilyShareable => UIKit.UIDevice.CurrentDevice.CheckSystemVersion(14, 0);
#else
static bool initIntro, hasIntro, initDiscounts, hasDiscounts, initFamily, hasFamily, initSubGroup, hasSubGroup;
static bool initIntro, hasIntro, initDiscounts, hasDiscounts, initFamily, hasFamily, initSubGroup, hasSubGroup, initStore, hasStore;
internal static bool HasIntroductoryOffer
{
get
Expand All @@ -37,7 +38,23 @@ internal static bool HasIntroductoryOffer

}
}
internal static bool HasProductDiscounts
internal static bool HasStorefront
{
get
{
if (initStore)
return hasStore;

initStore = true;


using var info = new NSProcessInfo();
hasStore = info.IsOperatingSystemAtLeastVersion(new NSOperatingSystemVersion(10, 15, 0));
return hasStore;

}
}
internal static bool HasProductDiscounts
{
get
{
Expand Down Expand Up @@ -101,6 +118,16 @@ public override void PresentCodeRedemption()
#endif
}

Storefront storefront;
/// <summary>
/// Returns representation of storefront on iOS 13+
/// </summary>
public override Storefront Storefront => HasStorefront ? (storefront ??= new Storefront
{
CountryCode = SKPaymentQueue.DefaultQueue.Storefront.CountryCode,
Id = SKPaymentQueue.DefaultQueue.Storefront.Identifier
}) : null;

/// <summary>
/// Gets if user can make payments
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Plugin.InAppBilling/Plugin.InAppBilling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@
<ItemGroup Condition=" $(TargetFramework.Contains('-mac')) ">
<Compile Include="**\*.apple.cs" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/Plugin.InAppBilling/Shared/BaseInAppBilling.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace Plugin.InAppBilling

public abstract class BaseInAppBilling : IInAppBilling, IDisposable
{

/// <summary>
/// Gets a representation of the storefront
/// </summary>
public virtual Storefront Storefront { get; } = null;

/// <summary>
/// Gets if the user can make payments
/// </summary>
Expand Down
15 changes: 10 additions & 5 deletions src/Plugin.InAppBilling/Shared/IInAppBilling.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace Plugin.InAppBilling
{
/// <summary>
/// Interface for InAppBilling
/// </summary>
[Preserve(AllMembers = true)]
public interface IInAppBilling : IDisposable
/// <summary>
/// Interface for InAppBilling
/// </summary>
[Preserve(AllMembers = true)]
public interface IInAppBilling : IDisposable
{
/// <summary>
/// Determines if it is connected to the backend actively (Android).
Expand All @@ -20,6 +20,11 @@ public interface IInAppBilling : IDisposable
/// </summary>
bool InTestingMode { get; set; }

/// <summary>
/// Represenation of the storefront if available
/// </summary>
Storefront Storefront { get; }


/// <summary>
/// Manually acknowledge a purchase
Expand Down
21 changes: 21 additions & 0 deletions src/Plugin.InAppBilling/Shared/Storefront.shared.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Plugin.InAppBilling
{
/// <summary>
/// An object containing the location and unique identifier of an App Store storefront.
/// </summary>
public class Storefront
{
/// <summary>
/// A value defined by Apple that uniquely identifies an App Store storefront.
/// </summary>
public string Id { get; set; }
/// <summary>
/// The three-letter code representing the country or region associated with the App Store storefront.
/// </summary>
public string CountryCode { get; set; }
}
}

0 comments on commit 64e5d17

Please sign in to comment.