Fix unavailable Play subscription handling

This commit is contained in:
livio committed 2026-09-30 20:59:24 +02:00
1 parent 6a675ce635
commit 01da7efc2f
4 files changed
+26 -7

No files matched your search

+13 -4
View File
@@ -92,12 +92,20 @@ public sealed class AndroidPlayBillingService : Java.Lang.Object, IPlayBillingSe
{
try
{
if (string.IsNullOrWhiteSpace(basePlanId))
{
return PlayBillingResult.Failed("Piano LME Pro non valido.");
}
var details = await GetProductDetailsAsync(cancellationToken);
var offer = details?.GetSubscriptionOfferDetails()?
.FirstOrDefault(item => item.BasePlanId == basePlanId && string.IsNullOrEmpty(item.OfferId));
.FirstOrDefault(item => item.BasePlanId == basePlanId
&& string.IsNullOrEmpty(item.OfferId)
&& !string.IsNullOrWhiteSpace(item.OfferToken));
if (details is null || offer is null)
{
return PlayBillingResult.Failed("Piano LME Pro non disponibile. Verifica prodotto e base plan nella Play Console.");
return PlayBillingResult.Failed(
$"Piano {basePlanId} non disponibile su Google Play. Verifica che l'abbonamento lme_pro e il piano siano attivi per il tuo Paese.");
}
var productParams = BillingFlowParams.ProductDetailsParams.NewBuilder()
@@ -113,7 +121,8 @@ public sealed class AndroidPlayBillingService : Java.Lang.Object, IPlayBillingSe
var completion = new TaskCompletionSource<PlayBillingResult>(TaskCreationOptions.RunContinuationsAsynchronously);
_purchaseCompletion = completion;
using var registration = cancellationToken.Register(() => completion.TrySetCanceled(cancellationToken));
var launchResult = _client.LaunchBillingFlow(activity, flow);
var launchResult = await MainThread.InvokeOnMainThreadAsync(() =>
_client.LaunchBillingFlow(activity, flow));
if (launchResult.ResponseCode != BillingResponseCode.Ok)
{
_purchaseCompletion = null;
@@ -182,7 +191,7 @@ public sealed class AndroidPlayBillingService : Java.Lang.Object, IPlayBillingSe
throw new InvalidOperationException(ToMessage(result.Result));
}
return result.ProductDetailsList.FirstOrDefault();
return result.ProductDetailsList?.FirstOrDefault();
}
private async Task EnsureConnectedAsync(CancellationToken cancellationToken)