Skip to content

Commit

Permalink
Add PresentCodeRedemption
Browse files Browse the repository at this point in the history
Fixes #383 and family share
  • Loading branch information
jamesmontemagno committed Feb 14, 2022
1 parent 2cb604b commit a58e0a7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Plugin.InAppBilling/Converters.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Plugin.InAppBilling
{
public static class Converters
internal static class Converters
{
public static InAppBillingPurchase ToIABPurchase(this Purchase purchase)
internal static InAppBillingPurchase ToIABPurchase(this Purchase purchase)
{
var finalPurchase = new InAppBillingPurchase
{
Expand Down Expand Up @@ -35,7 +35,7 @@ public static InAppBillingPurchase ToIABPurchase(this Purchase purchase)
return finalPurchase;
}

public static InAppBillingPurchase ToIABPurchase(this PurchaseHistoryRecord purchase)
internal static InAppBillingPurchase ToIABPurchase(this PurchaseHistoryRecord purchase)
{
return new InAppBillingPurchase
{
Expand All @@ -52,7 +52,7 @@ public static InAppBillingPurchase ToIABPurchase(this PurchaseHistoryRecord purc
};
}

public static InAppBillingProduct ToIAPProduct(this SkuDetails product)
internal static InAppBillingProduct ToIAPProduct(this SkuDetails product)
{
return new InAppBillingProduct
{
Expand Down
13 changes: 13 additions & 0 deletions src/Plugin.InAppBilling/InAppBilling.apple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ internal static bool HasFamilyShareable
}
#endif


/// <summary>
/// iOS: Displays a sheet that enables users to redeem subscription offer codes that you configure in App Store Connect.
/// </summary>
public override void PresentCodeRedemption()
{
#if __IOS__ && !__MACCATALYST__
if(HasFamilyShareable)
SKPaymentQueue.DefaultQueue.PresentCodeRedemptionSheet();
#endif
}

/// <summary>
/// Gets if user can make payments
/// </summary>
Expand Down Expand Up @@ -148,6 +160,7 @@ public async override Task<IEnumerable<InAppBillingProduct>> GetProductInfoAsync
CurrencyCode = p.PriceLocale?.CurrencyCode ?? string.Empty,
AppleExtras = new InAppBillingProductAppleExtras
{
IsFamilyShareable = HasFamilyShareable && p.IsFamilyShareable,
SubscriptionGroupId = HasSubscriptionGroupId ? p.SubscriptionGroupIdentifier : null,
SubscriptionPeriod = p.ToSubscriptionPeriod(),
IntroductoryOffer = HasIntroductoryOffer ? p.IntroductoryPrice?.ToProductDiscount() : null,
Expand Down
21 changes: 13 additions & 8 deletions src/Plugin.InAppBilling/Shared/BaseInAppBilling.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public abstract class BaseInAppBilling : IInAppBilling, IDisposable
public abstract Task<IEnumerable<InAppBillingProduct>> GetProductInfoAsync(ItemType itemType, params string[] productIds);


/// <summary>
/// Get all current purchases for a specific product type. If verification fails for some purchase, it's not contained in the result.
/// </summary>
/// <param name="itemType">Type of product</param>

/// <summary>
/// Get all current purchases for a specific product type. If verification fails for some purchase, it's not contained in the result.
/// </summary>
/// <param name="itemType">Type of product</param>
/// <param name="doNotFinishTransactionIds">List of ids not to finish (iOS only)</param>
/// <returns>The current purchases</returns>
public abstract Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(ItemType itemType, List<string> doNotFinishTransactionIds = null);
/// <returns>The current purchases</returns>
public abstract Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(ItemType itemType, List<string> doNotFinishTransactionIds = null);



Expand All @@ -67,7 +67,7 @@ public abstract class BaseInAppBilling : IInAppBilling, IDisposable
/// </summary>
/// <param name="itemType">Type of product</param>
/// <returns>The current purchases</returns>
public virtual Task<IEnumerable<InAppBillingPurchase>> GetPurchasesHistoryAsync(ItemType itemType) =>
public virtual Task<IEnumerable<InAppBillingPurchase>> GetPurchasesHistoryAsync(ItemType itemType) =>
Task.FromResult<IEnumerable<InAppBillingPurchase>>(new List<InAppBillingPurchase>());

/// <summary>
Expand Down Expand Up @@ -154,5 +154,10 @@ public virtual void Dispose(bool disposing)
/// <param name="purchaseToken"></param>
/// <returns></returns>
public virtual Task<bool> AcknowledgePurchaseAsync(string purchaseToken) => Task.FromResult(true);

/// <summary>
/// iOS: Displays a sheet that enables users to redeem subscription offer codes that you configure in App Store Connect.
/// </summary>
public virtual void PresentCodeRedemption() { }
}
}
7 changes: 6 additions & 1 deletion src/Plugin.InAppBilling/Shared/IInAppBilling.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,10 @@ public interface IInAppBilling : IDisposable
/// </summary>
bool CanMakePayments { get; }

}

/// <summary>
/// iOS: Displays a sheet that enables users to redeem subscription offer codes that you configure in App Store Connect.
/// </summary>
void PresentCodeRedemption();
}
}

0 comments on commit a58e0a7

Please sign in to comment.