Browse Source

Added customer ID to admin view

master
Teknikode 1 month ago
parent
commit
4e5dd269bd
  1. 3
      BillingCore/BillingFactory.cs
  2. 1
      BillingCore/BillingService.cs
  3. 13
      BillingCore/StripeService.cs
  4. 15
      Teknik/Areas/Admin/Controllers/AdminController.cs
  5. 2
      Teknik/Areas/Admin/ViewModels/UserInfoViewModel.cs
  6. 9
      Teknik/Areas/Admin/Views/Admin/UserInfo.cshtml
  7. 2
      Teknik/Scripts/Admin/UserInfo.js

3
BillingCore/BillingFactory.cs

@ -11,6 +11,9 @@ namespace Teknik.BillingCore @@ -11,6 +11,9 @@ namespace Teknik.BillingCore
{
public static BillingService GetBillingService(BillingConfig config)
{
if (config == null)
return null;
switch (config.Type)
{
case BillingType.Stripe:

1
BillingCore/BillingService.cs

@ -20,6 +20,7 @@ namespace Teknik.BillingCore @@ -20,6 +20,7 @@ namespace Teknik.BillingCore
public abstract List<Customer> GetCustomers();
public abstract Customer GetCustomer(string id);
public abstract string GetCustomerProfileUrl(string id);
public abstract string CreateCustomer(string username, string email);
public abstract List<Product> GetProductList();

13
BillingCore/StripeService.cs

@ -47,6 +47,19 @@ namespace Teknik.BillingCore @@ -47,6 +47,19 @@ namespace Teknik.BillingCore
return null;
}
public override string GetCustomerProfileUrl(string email)
{
if (!string.IsNullOrEmpty(email))
{
var service = new CustomerService();
var foundCustomer = service.Get(email);
if (foundCustomer != null)
return $"https://dashboard.stripe.com/customers/{foundCustomer.Id}";
}
return null;
}
public override string CreateCustomer(string username, string email)
{
if (string.IsNullOrEmpty(username))

15
Teknik/Areas/Admin/Controllers/AdminController.cs

@ -19,6 +19,8 @@ using Teknik.Logging; @@ -19,6 +19,8 @@ using Teknik.Logging;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Teknik.MailService;
using Teknik.Areas.Billing;
using Teknik.BillingCore;
namespace Teknik.Areas.Admin.Controllers
{
@ -61,6 +63,19 @@ namespace Teknik.Areas.Admin.Controllers @@ -61,6 +63,19 @@ namespace Teknik.Areas.Admin.Controllers
if (info.AccountStatus.HasValue)
model.AccountStatus = info.AccountStatus.Value;
// Get Biling Service
var billingService = BillingFactory.GetBillingService(_config.BillingConfig);
if (billingService != null &&
user.BillingCustomer != null)
{
var customer = billingService.GetCustomer(user.BillingCustomer?.CustomerId);
if (customer != null)
{
model.CustomerId = customer.CustomerId;
model.CustomerProfileUrl = billingService.GetCustomerProfileUrl(customer.CustomerId);
}
}
var email = UserHelper.GetUserEmailAddress(_config, username);
if (UserHelper.UserEmailExists(mailService, _config, email))
model.Email = email;

2
Teknik/Areas/Admin/ViewModels/UserInfoViewModel.cs

@ -12,6 +12,8 @@ namespace Teknik.Areas.Admin.ViewModels @@ -12,6 +12,8 @@ namespace Teknik.Areas.Admin.ViewModels
public string Username { get; set; }
public AccountType AccountType { get; set; }
public AccountStatus AccountStatus { get; set; }
public string CustomerId { get; set; }
public string CustomerProfileUrl { get; set; }
public string Email { get; set; }
public bool EmailEnabled { get; set; }
public long MaxEmailStorage { get; set; }

9
Teknik/Areas/Admin/Views/Admin/UserInfo.cshtml

@ -53,6 +53,15 @@ @@ -53,6 +53,15 @@
</div>
</div>
<br />
<div class="row">
<div class="col-sm-2 col-sm-offset-1">
Customer ID:
</div>
<div class="col-sm-8">
<a href="@Model.CustomerProfileUrl">@Model.CustomerId</a>
</div>
</div>
<br />
<div class="row">
<div class="col-sm-2 col-sm-offset-1">
Email:

2
Teknik/Scripts/Admin/UserInfo.js

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
/* globals editAccountType, editAccountStatus, createInviteCode, deleteUserURL, homeUrl, username */
/* globals editAccountType, editAccountStatus, editEmailActive, createInviteCode, deleteUserURL, homeUrl, username */
$(function () {
$('.userAccountType').on('change', function () {

Loading…
Cancel
Save