For MAUI I have create a simple wrapper around iOS and Android bindings:
https://github.com/Kebechet/Maui.RevenueCat.InAppBilling
you can inspire from the code or simply install it through nuget
Here is the simple example how to get offerings from RevenueCat for Android:
public class RevenueCatBilling
{
private Purchases _purchases = default!;
private static Activity? _currentActivityContext => Platform.CurrentActivity;
public void Initialize(string apiKey)
{
if (_currentActivityContext is null)
{
throw new Exception("You must call this code in App.xaml->OnStart");
}
try
{
_purchases = Purchases.Configure(
new PurchasesConfiguration(
new PurchasesConfiguration.Builder(
_currentActivityContext,
apiKey)
)
);
_isInitialized = true;
}
catch
{
throw;
}
}
public async Task<List<Offering>> LoadOfferings(CancellationToken cancellationToken)
{
try
{
using var offerings = await Purchases.SharedInstance.GetOfferingsAsync(cancellationToken);
if (offerings is null)
{
return new();
}
using var currentOffering = offerings.Current;
if (currentOffering is null)
{
return new();
}
return currentOffering.AvailablePackages.ToList();
}
catch
{
return new();
}
}
public static Task<Offerings> GetOfferingsAsync(this Purchases purchases,
CancellationToken cancellationToken = default)
{
var listener = new DelegatingReceiveOfferingsCallback(cancellationToken);
purchases.GetOfferings(listener);
return listener.Task;
}
}
internal sealed class DelegatingReceiveOfferingsCallback : DelegatingListenerBase<Offerings>, IReceiveOfferingsCallback
{
public DelegatingReceiveOfferingsCallback(CancellationToken cancellationToken) : base(cancellationToken)
{
}
public void OnError(PurchasesError purchasesError)
{
ReportException(new PurchasesErrorException(purchasesError, false));
}
public void OnReceived(Offerings offerings)
{
ReportSuccess(offerings);
}
}
internal abstract class DelegatingListenerBase<TResult> : Java.Lang.Object
{
private readonly TaskCompletionSource<TResult> _taskCompletionSource;
public DelegatingListenerBase(CancellationToken cancellationToken)
{
_taskCompletionSource = new TaskCompletionSource<TResult>();
cancellationToken.Register(() => _taskCompletionSource.TrySetCanceled());
}
public Task<TResult> Task => _taskCompletionSource.Task;
protected void ReportSuccess(TResult result)
{
_taskCompletionSource.TrySetResult(result);
}
protected void ReportException(Exception exception)
{
_taskCompletionSource.TrySetException(exception);
}
}