1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Added checks for billing enabled.

This commit is contained in:
Uncled1023 2021-11-20 22:15:30 -08:00
parent a706b3836e
commit 2bb1a1a500
5 changed files with 66 additions and 34 deletions

View File

@ -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
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
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);

View File

@ -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
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
public IActionResult EditSubscription(string priceId)
{
if (!_config.BillingConfig.Enabled)
throw new UnauthorizedAccessException();
// Get Subscription Info
var billingService = BillingFactory.GetBillingService(_config.BillingConfig);

View File

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

View File

@ -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>

View File

@ -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>