Add subscription pricing and Base drawing limit
This commit is contained in:
1 parent
ad64d6def0
commit
6a675ce635
15 files changed
+384
-37
No files matched your search
@@ -1,10 +1,14 @@
|
||||
namespace LMEMappeCatastaliApp.Services;
|
||||
|
||||
public sealed class EntitlementService(ManualLicenseService manualLicenses, IPlayBillingService playBilling)
|
||||
public sealed class EntitlementService(
|
||||
ManualLicenseService manualLicenses,
|
||||
IPlayBillingService playBilling,
|
||||
PlayPurchaseVerificationService purchaseVerification)
|
||||
{
|
||||
public const string ProductId = "lme_pro";
|
||||
public const string MonthlyBasePlanId = "monthly";
|
||||
public const string YearlyBasePlanId = "yearly";
|
||||
public const int BaseDrawingObjectLimit = 15;
|
||||
|
||||
private const string GoogleProActivePreference = "entitlement_google_pro_active";
|
||||
private const string GoogleExpiresAtPreference = "entitlement_google_pro_expires_at";
|
||||
@@ -53,6 +57,10 @@ public sealed class EntitlementService(ManualLicenseService manualLicenses, IPla
|
||||
public bool RequiresPro(string feature) => ProFeatures.Contains(feature);
|
||||
public bool CanUse(string feature) => !RequiresPro(feature) || HasProAccess;
|
||||
|
||||
public Task<IReadOnlyList<PlaySubscriptionPlan>> GetSubscriptionPlansAsync(
|
||||
CancellationToken cancellationToken = default) =>
|
||||
playBilling.GetSubscriptionPlansAsync(cancellationToken);
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
IsGoogleProActive = Preferences.Default.Get(GoogleProActivePreference, false);
|
||||
@@ -85,32 +93,60 @@ public sealed class EntitlementService(ManualLicenseService manualLicenses, IPla
|
||||
public async Task<PlayBillingResult> RestorePurchasesAsync()
|
||||
{
|
||||
var result = await playBilling.RestoreAsync();
|
||||
ApplyPlayBillingResult(result);
|
||||
return result;
|
||||
return await ApplyPlayBillingResultAsync(result);
|
||||
}
|
||||
|
||||
public async Task<PlayBillingResult> PurchaseGoogleProAsync(string basePlanId)
|
||||
{
|
||||
var result = await playBilling.PurchaseAsync(basePlanId);
|
||||
ApplyPlayBillingResult(result);
|
||||
return result;
|
||||
return await ApplyPlayBillingResultAsync(result);
|
||||
}
|
||||
|
||||
private void ApplyPlayBillingResult(PlayBillingResult result)
|
||||
private async Task<PlayBillingResult> ApplyPlayBillingResultAsync(PlayBillingResult result)
|
||||
{
|
||||
if (!result.Completed)
|
||||
{
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (result.HasActiveSubscription)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(result.PurchaseToken))
|
||||
{
|
||||
var verification = await purchaseVerification.VerifyAsync(result.PurchaseToken);
|
||||
if (verification.Verified)
|
||||
{
|
||||
if (verification.Active)
|
||||
{
|
||||
ApplyVerifiedGooglePro(verification.ExpiresAt);
|
||||
return result with
|
||||
{
|
||||
Message = string.IsNullOrWhiteSpace(verification.Message)
|
||||
? result.Message
|
||||
: verification.Message
|
||||
};
|
||||
}
|
||||
|
||||
ApplyGoogleBase();
|
||||
return PlayBillingResult.Base(string.IsNullOrWhiteSpace(verification.Message)
|
||||
? "L'abbonamento Google Play non risulta attivo."
|
||||
: verification.Message);
|
||||
}
|
||||
|
||||
if (purchaseVerification.IsRequired)
|
||||
{
|
||||
return PlayBillingResult.Failed(verification.Message);
|
||||
}
|
||||
}
|
||||
|
||||
ApplyVerifiedGooglePro(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyGoogleBase();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SaveGoogleState()
|
||||
|
||||
Reference in new issue
Block a user