I am working on .NET MAUI Mobile Application, and I need to check the subscription status of iOS and Android users to ensure access to premium features. The code successfully handles purchasing subscriptions, but I need to check the user’s subscription status through the Apple Developer API. The same way I need to check the user’s subscription status through the Google Developer API.
Here’s the relevant part of my code where I handle the subscription purchase:
private async void PlanClicked(Object sender, EventArgs e)
{
UserDialogs.Instance.ShowLoading("");
if (IsBusy)
return;
IsBusy = true;
try
{
// check internet first with Essentials
if (Connectivity.NetworkAccess != NetworkAccess.Internet)
return;
// connect to the app store api
var connected = await CrossInAppBilling.Current.ConnectAsync();
if (!connected)
return;
UserDialogs.Instance.HideHud();
//try to make purchase, this will return a purchase, empty, or throw an exception
var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.Subscription);
if (purchase == null)
{
//nothing was purchased
return;
}
if (purchase.State == PurchaseState.Purchased)
{
Debug.WriteLine("Purchase successfull");
Debug.WriteLine("Purchase token:>>" + purchase.PurchaseToken);
Debug.WriteLine("Purchase id:>>" + purchase.Id);
}
else
{
throw new InAppBillingPurchaseException(PurchaseError.GeneralError);
}
}
catch (InAppBillingPurchaseException purchaseEx)
{
// Handle all the different error codes that can occure and do a pop up
Debug.WriteLine("purchaseEx:>>" + purchaseEx);
}
catch (Exception ex)
{
// Handle a generic exception as something really went wrong
Debug.WriteLine("exception:>>" + ex);
}
finally
{
await CrossInAppBilling.Current.DisconnectAsync();
IsBusy = false;
}
}
The subscription purchasing process works fine, but now I want to verify the subscription status for a user after the purchase.
I tried using the Get All Subscription Statuses API from Apple, but I received an "Unauthorized" response when calling the API.
Which Apple developer APIs and Google developer APIs for validating and checking the user’s subscription status?
Can anyone provide a solution or guidance?
Thanks in advance for your help!
You need to sign in to view this answers