diff --git a/BillingCore/BillingFactory.cs b/BillingCore/BillingFactory.cs index f6d0135..9ceffe8 100644 --- a/BillingCore/BillingFactory.cs +++ b/BillingCore/BillingFactory.cs @@ -11,6 +11,9 @@ namespace Teknik.BillingCore { public static BillingService GetBillingService(BillingConfig config) { + if (config == null) + return null; + switch (config.Type) { case BillingType.Stripe: diff --git a/BillingCore/BillingService.cs b/BillingCore/BillingService.cs index e4ff59c..7bc9561 100644 --- a/BillingCore/BillingService.cs +++ b/BillingCore/BillingService.cs @@ -20,6 +20,7 @@ namespace Teknik.BillingCore public abstract List GetCustomers(); public abstract Customer GetCustomer(string id); + public abstract string GetCustomerProfileUrl(string id); public abstract string CreateCustomer(string username, string email); public abstract List GetProductList(); diff --git a/BillingCore/StripeService.cs b/BillingCore/StripeService.cs index 621f1b0..54830f5 100644 --- a/BillingCore/StripeService.cs +++ b/BillingCore/StripeService.cs @@ -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)) diff --git a/Teknik/Areas/Admin/Controllers/AdminController.cs b/Teknik/Areas/Admin/Controllers/AdminController.cs index 619f04e..d84de97 100644 --- a/Teknik/Areas/Admin/Controllers/AdminController.cs +++ b/Teknik/Areas/Admin/Controllers/AdminController.cs @@ -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 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; diff --git a/Teknik/Areas/Admin/ViewModels/UserInfoViewModel.cs b/Teknik/Areas/Admin/ViewModels/UserInfoViewModel.cs index 6c4b0fd..44dfde4 100644 --- a/Teknik/Areas/Admin/ViewModels/UserInfoViewModel.cs +++ b/Teknik/Areas/Admin/ViewModels/UserInfoViewModel.cs @@ -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; } diff --git a/Teknik/Areas/Admin/Views/Admin/UserInfo.cshtml b/Teknik/Areas/Admin/Views/Admin/UserInfo.cshtml index 382736f..fbb617e 100644 --- a/Teknik/Areas/Admin/Views/Admin/UserInfo.cshtml +++ b/Teknik/Areas/Admin/Views/Admin/UserInfo.cshtml @@ -53,6 +53,15 @@
+
+
+ Customer ID: +
+ +
+
Email: diff --git a/Teknik/Scripts/Admin/UserInfo.js b/Teknik/Scripts/Admin/UserInfo.js index 5057eac..f2952be 100644 --- a/Teknik/Scripts/Admin/UserInfo.js +++ b/Teknik/Scripts/Admin/UserInfo.js @@ -1,4 +1,4 @@ -/* globals editAccountType, editAccountStatus, createInviteCode, deleteUserURL, homeUrl, username */ +/* globals editAccountType, editAccountStatus, editEmailActive, createInviteCode, deleteUserURL, homeUrl, username */ $(function () { $('.userAccountType').on('change', function () {