Add subscription pricing and Base drawing limit

This commit is contained in:
livio committed 2026-09-30 10:12:24 +02:00
1 parent ad64d6def0
commit 6a675ce635
15 files changed
+384 -37

No files matched your search

+55 -17
View File
@@ -24,6 +24,35 @@ public sealed class AndroidPlayBillingService : Java.Lang.Object, IPlayBillingSe
.Build();
}
public async Task<IReadOnlyList<PlaySubscriptionPlan>> GetSubscriptionPlansAsync(
CancellationToken cancellationToken = default)
{
try
{
var details = await GetProductDetailsAsync(cancellationToken);
return details?.GetSubscriptionOfferDetails()?
.Where(item => string.IsNullOrEmpty(item.OfferId))
.Select(item =>
{
var phase = item.PricingPhases.PricingPhaseList.LastOrDefault();
return phase is null
? null
: new PlaySubscriptionPlan(item.BasePlanId, phase.FormattedPrice, phase.BillingPeriod);
})
.Where(item => item is not null)
.Cast<PlaySubscriptionPlan>()
.ToArray() ?? [];
}
catch (OperationCanceledException)
{
throw;
}
catch
{
return [];
}
}
public async Task<PlayBillingResult> RestoreAsync(CancellationToken cancellationToken = default)
{
try
@@ -45,7 +74,9 @@ public sealed class AndroidPlayBillingService : Java.Lang.Object, IPlayBillingSe
}
var acknowledgement = await AcknowledgeIfNeededAsync(purchase);
return acknowledgement ?? PlayBillingResult.Active("Abbonamento LME Pro ripristinato da Google Play.");
return acknowledgement ?? PlayBillingResult.Active(
"Abbonamento LME Pro ripristinato da Google Play.",
purchase.PurchaseToken);
}
catch (OperationCanceledException)
{
@@ -61,21 +92,7 @@ public sealed class AndroidPlayBillingService : Java.Lang.Object, IPlayBillingSe
{
try
{
await EnsureConnectedAsync(cancellationToken);
var product = QueryProductDetailsParams.Product.NewBuilder()
.SetProductId(EntitlementService.ProductId)
.SetProductType(BillingClient.ProductType.Subs)
.Build();
var query = QueryProductDetailsParams.NewBuilder()
.SetProductList([product])
.Build();
var detailsResult = await _client.QueryProductDetailsAsync(query);
if (detailsResult.Result.ResponseCode != BillingResponseCode.Ok)
{
return PlayBillingResult.Failed(ToMessage(detailsResult.Result));
}
var details = detailsResult.ProductDetailsList.FirstOrDefault();
var details = await GetProductDetailsAsync(cancellationToken);
var offer = details?.GetSubscriptionOfferDetails()?
.FirstOrDefault(item => item.BasePlanId == basePlanId && string.IsNullOrEmpty(item.OfferId));
if (details is null || offer is null)
@@ -144,7 +161,28 @@ public sealed class AndroidPlayBillingService : Java.Lang.Object, IPlayBillingSe
}
var acknowledgement = await AcknowledgeIfNeededAsync(purchase);
completion.TrySetResult(acknowledgement ?? PlayBillingResult.Active("Abbonamento LME Pro attivato."));
completion.TrySetResult(acknowledgement ?? PlayBillingResult.Active(
"Abbonamento LME Pro attivato.",
purchase.PurchaseToken));
}
private async Task<ProductDetails?> GetProductDetailsAsync(CancellationToken cancellationToken)
{
await EnsureConnectedAsync(cancellationToken);
var product = QueryProductDetailsParams.Product.NewBuilder()
.SetProductId(EntitlementService.ProductId)
.SetProductType(BillingClient.ProductType.Subs)
.Build();
var query = QueryProductDetailsParams.NewBuilder()
.SetProductList([product])
.Build();
var result = await _client.QueryProductDetailsAsync(query);
if (result.Result.ResponseCode != BillingResponseCode.Ok)
{
throw new InvalidOperationException(ToMessage(result.Result));
}
return result.ProductDetailsList.FirstOrDefault();
}
private async Task EnsureConnectedAsync(CancellationToken cancellationToken)