private static void CheckSubscriptionStart(SubscribableEdition edition, ESubscriptionStartType subscriptionStartType) { switch (subscriptionStartType) { case ESubscriptionStartType.Free: if (!edition.IsFree) { throw new Exception("This is not a free edition !"); } break; case ESubscriptionStartType.Trial: if (!edition.HasTrial()) { throw new Exception("Trial is not available for this edition !"); } break; case ESubscriptionStartType.Paid: if (edition.IsFree) { throw new Exception("This is a free edition and cannot be subscribed as paid !"); } break; } }
private async Task CheckEditionSubscriptionAsync(int editionId, ESubscriptionStartType subscriptionStartType, ESubscriptionPaymentGatewayType?gateway, string paymentId) { var edition = await _editionManager.GetByIdAsync(editionId) as SubscribableEdition; CheckSubscriptionStart(edition, subscriptionStartType); CheckPaymentCache(edition, subscriptionStartType, gateway, paymentId); }
private void CheckPaymentCache(SubscribableEdition edition, ESubscriptionStartType subscriptionStartType, ESubscriptionPaymentGatewayType?gateway, string paymentId) { if (edition.IsFree || subscriptionStartType != ESubscriptionStartType.Paid) { return; } if (!gateway.HasValue) { throw new Exception("Gateway cannot be empty !"); } if (paymentId.IsNullOrEmpty()) { throw new Exception("PaymentId cannot be empty !"); } var paymentCacheItem = _paymentCache.GetCacheItemOrNull(gateway.Value, paymentId); if (paymentCacheItem == null) { throw new UserFriendlyException(L("PaymentMightBeExpiredWarning")); } }