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

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Apis.AndroidPublisher.v3" Version="1.76.0.4277" />
</ItemGroup>
</Project>
+60
View File
@@ -0,0 +1,60 @@
using Google.Apis.AndroidPublisher.v3;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
const string PackageName = "it.liviomerola.lmemappecatastali.pro";
const string ProductId = "lme_pro";
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton(_ =>
{
var credential = GoogleCredential.GetApplicationDefault()
.CreateScoped(AndroidPublisherService.Scope.Androidpublisher);
return new AndroidPublisherService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "LME Play subscription verifier"
});
});
var app = builder.Build();
app.UseHttpsRedirection();
app.MapGet("/health", () => Results.Ok(new { status = "ok" }));
app.MapPost("/v1/google-play/subscriptions/verify", async (
VerifySubscriptionRequest request,
AndroidPublisherService publisher,
CancellationToken cancellationToken) =>
{
if (request.PackageName != PackageName || request.ProductId != ProductId
|| string.IsNullOrWhiteSpace(request.PurchaseToken))
{
return Results.BadRequest(new VerifySubscriptionResponse(false, null, "Richiesta non valida."));
}
try
{
var purchase = await publisher.Purchases.Subscriptionsv2
.Get(PackageName, request.PurchaseToken)
.ExecuteAsync(cancellationToken);
var active = purchase.SubscriptionState is "SUBSCRIPTION_STATE_ACTIVE"
or "SUBSCRIPTION_STATE_IN_GRACE_PERIOD";
var expiresAt = purchase.LineItems?
.Select(item => item.ExpiryTimeDateTimeOffset)
.Where(value => value.HasValue)
.Max();
return Results.Ok(new VerifySubscriptionResponse(
active,
expiresAt,
active ? "Abbonamento LME Pro verificato." : "L'abbonamento Google Play non risulta attivo."));
}
catch (Google.GoogleApiException error) when ((int)error.HttpStatusCode is 400 or 404)
{
return Results.Ok(new VerifySubscriptionResponse(false, null, "Acquisto Google Play non riconosciuto."));
}
});
app.Run();
internal sealed record VerifySubscriptionRequest(string PackageName, string ProductId, string PurchaseToken);
internal sealed record VerifySubscriptionResponse(bool Active, DateTimeOffset? ExpiresAt, string Message);
+18
View File
@@ -0,0 +1,18 @@
# LME Play verifier
Servizio HTTPS per verificare i token degli abbonamenti `lme_pro` con la Google Play Developer API.
## Configurazione
1. Creare un service account in Google Cloud e concedergli nella Play Console il permesso di visualizzare ordini e abbonamenti dell'app.
2. Conservare il JSON del service account solo sul server.
3. Impostare `GOOGLE_APPLICATION_CREDENTIALS` con il percorso assoluto del JSON.
4. Pubblicare il servizio dietro HTTPS.
5. Compilare l'app con:
```powershell
-p:PlayBillingVerificationUrl=https://example.test/v1/google-play/subscriptions/verify
-p:PlayBillingVerificationRequired=true
```
Non inserire il JSON del service account, token di acquisto o credenziali nel repository o nell'AAB.