From 24d227d0756d0c2836936545bfa390213205ed33 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:10:07 +0100 Subject: [PATCH] [PM 237] Test Clock Error in Production when attempting to view Stripe Subscription page (#2745) * Check for environment before hitting TestClock * Getting the environment from WebHotsEnvironment * Dotnet format changes --- src/Admin/Controllers/ToolsController.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Admin/Controllers/ToolsController.cs b/src/Admin/Controllers/ToolsController.cs index b18864d371..6f9c557341 100644 --- a/src/Admin/Controllers/ToolsController.cs +++ b/src/Admin/Controllers/ToolsController.cs @@ -27,6 +27,7 @@ public class ToolsController : Controller private readonly IPaymentService _paymentService; private readonly ITaxRateRepository _taxRateRepository; private readonly IStripeAdapter _stripeAdapter; + private readonly IWebHostEnvironment _environment; public ToolsController( GlobalSettings globalSettings, @@ -38,7 +39,8 @@ public class ToolsController : Controller IOrganizationUserRepository organizationUserRepository, ITaxRateRepository taxRateRepository, IPaymentService paymentService, - IStripeAdapter stripeAdapter) + IStripeAdapter stripeAdapter, + IWebHostEnvironment environment) { _globalSettings = globalSettings; _organizationRepository = organizationRepository; @@ -50,6 +52,7 @@ public class ToolsController : Controller _taxRateRepository = taxRateRepository; _paymentService = paymentService; _stripeAdapter = stripeAdapter; + _environment = environment; } public IActionResult ChargeBraintree() @@ -450,11 +453,12 @@ public class ToolsController : Controller subscriptions.FirstOrDefault()?.Id : null; + var isProduction = _environment.IsProduction(); var model = new StripeSubscriptionsModel() { Items = subscriptions.Select(s => new StripeSubscriptionRowModel(s)).ToList(), Prices = (await _stripeAdapter.PriceListAsync(new Stripe.PriceListOptions() { Limit = 100 })).Data, - TestClocks = await _stripeAdapter.TestClockListAsync(), + TestClocks = isProduction ? new List() : await _stripeAdapter.TestClockListAsync(), Filter = options }; return View(model); @@ -465,8 +469,9 @@ public class ToolsController : Controller { if (!ModelState.IsValid) { + var isProduction = _environment.IsProduction(); model.Prices = (await _stripeAdapter.PriceListAsync(new Stripe.PriceListOptions() { Limit = 100 })).Data; - model.TestClocks = await _stripeAdapter.TestClockListAsync(); + model.TestClocks = isProduction ? new List() : await _stripeAdapter.TestClockListAsync(); return View(model); }