Browse Source

Added checks for billing enabled.

feature/billing
Teknikode 7 months ago
parent
commit
2bb1a1a500
  1. 9
      Teknik/Areas/API/V1/Controllers/BillingAPIv1Controller.cs
  2. 9
      Teknik/Areas/Billing/Controllers/BillingController.cs
  3. 4
      Teknik/Areas/Billing/Views/Billing/ViewSubscription.cshtml
  4. 73
      Teknik/Areas/User/Views/User/Settings/BillingSettings.cshtml
  5. 5
      Teknik/Areas/User/Views/User/Settings/Settings.cshtml

9
Teknik/Areas/API/V1/Controllers/BillingAPIv1Controller.cs

@ -23,6 +23,9 @@ namespace Teknik.Areas.API.V1.Controllers @@ -23,6 +23,9 @@ namespace Teknik.Areas.API.V1.Controllers
public async Task<IActionResult> HandleCheckoutCompleteEvent()
{
if (!_config.BillingConfig.Enabled)
return Forbid();
var billingService = BillingFactory.GetBillingService(_config.BillingConfig);
var billingEvent = await billingService.ParseEvent(Request, _config.BillingConfig.StripeCheckoutWebhookSecret);
@ -43,6 +46,9 @@ namespace Teknik.Areas.API.V1.Controllers @@ -43,6 +46,9 @@ namespace Teknik.Areas.API.V1.Controllers
public async Task<IActionResult> HandleSubscriptionChange()
{
if (!_config.BillingConfig.Enabled)
return Forbid();
var billingService = BillingFactory.GetBillingService(_config.BillingConfig);
var billingEvent = await billingService.ParseEvent(Request, _config.BillingConfig.StripeSubscriptionWebhookSecret);
@ -61,6 +67,9 @@ namespace Teknik.Areas.API.V1.Controllers @@ -61,6 +67,9 @@ namespace Teknik.Areas.API.V1.Controllers
public async Task<IActionResult> HandleCustomerDeletion()
{
if (!_config.BillingConfig.Enabled)
return Forbid();
var billingService = BillingFactory.GetBillingService(_config.BillingConfig);
var billingEvent = await billingService.ParseEvent(Request, _config.BillingConfig.StripeCustomerWebhookSecret);

9
Teknik/Areas/Billing/Controllers/BillingController.cs

@ -172,6 +172,9 @@ namespace Teknik.Areas.Billing.Controllers @@ -172,6 +172,9 @@ namespace Teknik.Areas.Billing.Controllers
public IActionResult Checkout(string priceId)
{
if (!_config.BillingConfig.Enabled)
throw new UnauthorizedAccessException();
// Get Subscription Info
var billingService = BillingFactory.GetBillingService(_config.BillingConfig);
@ -192,6 +195,9 @@ namespace Teknik.Areas.Billing.Controllers @@ -192,6 +195,9 @@ namespace Teknik.Areas.Billing.Controllers
public IActionResult CheckoutComplete(string productId, string session_id)
{
if (!_config.BillingConfig.Enabled)
throw new UnauthorizedAccessException();
// Get Checkout Info
var billingService = BillingFactory.GetBillingService(_config.BillingConfig);
var checkoutSession = billingService.GetCheckoutSession(session_id);
@ -224,6 +230,9 @@ namespace Teknik.Areas.Billing.Controllers @@ -224,6 +230,9 @@ namespace Teknik.Areas.Billing.Controllers
public IActionResult EditSubscription(string priceId)
{
if (!_config.BillingConfig.Enabled)
throw new UnauthorizedAccessException();
// Get Subscription Info
var billingService = BillingFactory.GetBillingService(_config.BillingConfig);

4
Teknik/Areas/Billing/Views/Billing/ViewSubscription.cshtml

@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
}
var btnClass = "";
if (Model.CurrentSubMonthly)
if (Model.CurrentSubMonthly || !Config.BillingConfig.Enabled)
{
btnClass = "disabled";
}
@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
@if (Model.BasePriceYearly != null)
{
var yearBtnClass = "";
if (Model.CurrentSubYearly)
if (Model.CurrentSubYearly || !Config.BillingConfig.Enabled)
{
yearBtnClass = "disabled";
}

73
Teknik/Areas/User/Views/User/Settings/BillingSettings.cshtml

@ -10,48 +10,59 @@ @@ -10,48 +10,59 @@
var cancelSubscriptionURL = '@Url.SubRouteUrl("billing", "User.Action", new { action = "CancelSubscription" })';
</script>
@if (!string.IsNullOrEmpty(Model.PortalUrl))
@if (Config.BillingConfig.Enabled)
{
if (!string.IsNullOrEmpty(Model.PortalUrl))
{
<div class="row">
<div class="col-sm-12">
<h2>Billing Information</h2>
<hr />
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<a href="@Model.PortalUrl">Click here</a> to view/modify your billing information and invoices.
</div>
</div>
}
<div class="row">
<div class="col-sm-12">
<h2>Billing Information</h2>
<h2>Active Subscriptions</h2>
<hr />
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<a href="@Model.PortalUrl">Click here</a> to view/modify your billing information and invoices.
<div class="col-sm-12">
<div id="activeSubscriptions" style="overflow-y: auto; max-height: 400px;">
<ul class="list-group" id="activeSubscriptionList">
@if (Model.Subscriptions.Any())
{
foreach (var subscription in Model.Subscriptions)
{
<li class="list-group-item" id="@subscription.SubscriptionId">
<h4 class="list-group-item-heading pull-left">@subscription.ProductName: <strong>@(StringHelper.GetBytesReadable(subscription.Storage))</strong> for <strong>@($"${subscription.Price:0.00} / {subscription.Interval}")</strong></h4>
<button role="button" class="btn btn-default cancel-subscription-button pull-right" data-subscription-id="@subscription.SubscriptionId" data-product-id="@subscription.ProductId">Cancel Subscription</button>
<div class="clearfix"></div>
</li>
}
}
else
{
<li class="list-group-item text-center">No Active Subscriptions</li>
}
</ul>
</div>
</div>
</div>
}
<div class="row">
<div class="col-sm-12">
<h2>Active Subscriptions</h2>
<hr />
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div id="activeSubscriptions" style="overflow-y: auto; max-height: 400px;">
<ul class="list-group" id="activeSubscriptionList">
@if (Model.Subscriptions.Any())
{
foreach (var subscription in Model.Subscriptions)
{
<li class="list-group-item" id="@subscription.SubscriptionId">
<h4 class="list-group-item-heading pull-left">@subscription.ProductName: <strong>@(StringHelper.GetBytesReadable(subscription.Storage))</strong> for <strong>@($"${subscription.Price:0.00} / {subscription.Interval}")</strong></h4>
<button role="button" class="btn btn-default cancel-subscription-button pull-right" data-subscription-id="@subscription.SubscriptionId" data-product-id="@subscription.ProductId">Cancel Subscription</button>
<div class="clearfix"></div>
</li>
}
}
else
{
<li class="list-group-item text-center">No Active Subscriptions</li>
}
</ul>
else
{
<div class="row">
<div class="form-group col-sm-12">
<p>Billing System Disabled</p>
</div>
</div>
</div>
}
<bundle src="js/user.settings.billing.min.js" append-version="true"></bundle>

5
Teknik/Areas/User/Views/User/Settings/Settings.cshtml

@ -17,7 +17,10 @@ @@ -17,7 +17,10 @@
<div class="panel-heading text-center"><strong>Personal Settings</strong></div>
<a href="@Url.SubRouteUrl("account", "User.ProfileSettings")" class="list-group-item @(Model.Page == "Profile" ? "active" : string.Empty)">Profile</a>
<a href="@Url.SubRouteUrl("account", "User.AccountSettings")" class="list-group-item @(Model.Page == "Account" ? "active" : string.Empty)">Account</a>
<a href="@Url.SubRouteUrl("account", "User.BillingSettings")" class="list-group-item @(Model.Page == "Billing" ? "active" : string.Empty)">Billing</a>
@if (Config.BillingConfig.Enabled)
{
<a href="@Url.SubRouteUrl("account", "User.BillingSettings")" class="list-group-item @(Model.Page == "Billing" ? "active" : string.Empty)">Billing</a>
}
<a href="@Url.SubRouteUrl("account", "User.SecuritySettings")" class="list-group-item @(Model.Page == "Security" ? "active" : string.Empty)">Security</a>
<a href="@Url.SubRouteUrl("account", "User.InviteSettings")" class="list-group-item @(Model.Page == "Invite" ? "active" : string.Empty)">Invite Codes</a>
<a href="@Url.SubRouteUrl("account", "User.BlogSettings")" class="list-group-item @(Model.Page == "Blog" ? "active" : string.Empty)">Blogging</a>

Loading…
Cancel
Save