Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added IdentifyAsync convenience method #8

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions Xamarin.RevenueCat.iOS.Extensions/RCPurchasesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ namespace Xamarin.RevenueCat.iOS.Extensions
{
public static class RCPurchasesExtensions
{
public static Task<RCPurchaserInfo> IdentifyAsync(this RCPurchases purchases, string appUserId,
CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCPurchaserInfo>();
cancellationToken.Register(() => tcs.TrySetCanceled());
purchases.Identify(appUserId, (purchaserInfo, error) =>
{
if (error != null)
{
tcs.TrySetException(new PurchasesErrorException(error, false));
}
else
{
tcs.TrySetResult(purchaserInfo);
}
});
return tcs.Task;
}

public static Task<RCOfferings> GetOfferingsAsync(this RCPurchases purchases,
CancellationToken cancellationToken = default)
{
Expand All @@ -20,8 +39,10 @@ public static Task<RCOfferings> GetOfferingsAsync(this RCPurchases purchases,
{
tcs.TrySetException(new PurchasesErrorException(error, false));
}

tcs.TrySetResult(offerings);
else
{
tcs.TrySetResult(offerings);
}
});
return tcs.Task;
}
Expand All @@ -38,18 +59,20 @@ public static Task<PurchaseSuccessInfo> PurchasePackageAsync(this RCPurchases pu
{
tcs.TrySetException(new PurchasesErrorException(error, userCancelled));
}

if (userCancelled)
else if (userCancelled)
{
tcs.TrySetException(new PurchasesErrorException(null, true));
}

tcs.TrySetResult(new PurchaseSuccessInfo(transaction, purchaserInfo));
else
{
tcs.TrySetResult(new PurchaseSuccessInfo(transaction, purchaserInfo));
}
});
return tcs.Task;
}

public static Task<RCPurchaserInfo> RestoreTransactionsAsync(this RCPurchases purchases, CancellationToken cancellationToken = default)
public static Task<RCPurchaserInfo> RestoreTransactionsAsync(this RCPurchases purchases,
CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCPurchaserInfo>();
cancellationToken.Register(() => tcs.TrySetCanceled());
Expand All @@ -59,13 +82,16 @@ public static Task<RCPurchaserInfo> RestoreTransactionsAsync(this RCPurchases pu
{
tcs.TrySetException(new PurchasesErrorException(error, false));
}

tcs.TrySetResult(purchaserInfo);
else
{
tcs.TrySetResult(purchaserInfo);
}
});
return tcs.Task;
}

public static Task<RCPurchaserInfo> GetPurchaserInfoAsync(this RCPurchases purchases, CancellationToken cancellationToken = default)
public static Task<RCPurchaserInfo> GetPurchaserInfoAsync(this RCPurchases purchases,
CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCPurchaserInfo>();
cancellationToken.Register(() => tcs.TrySetCanceled());
Expand All @@ -75,8 +101,10 @@ public static Task<RCPurchaserInfo> GetPurchaserInfoAsync(this RCPurchases purch
{
tcs.TrySetException(new PurchasesErrorException(error, false));
}

tcs.TrySetResult(purchaserInfo);
else
{
tcs.TrySetResult(purchaserInfo);
}
});
return tcs.Task;
}
Expand Down