Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Web/Resgrid.Web/Areas/User/Controllers/SubscriptionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public SubscriptionController(IDepartmentsService departmentsService, IUsersServ

#endregion Private Members and Constructors

private static bool ShouldUsePaddleForSubscriptionFlow(Payment currentPayment, string paddleCustomerId)
{
if (!string.IsNullOrWhiteSpace(paddleCustomerId))
return true;

if (currentPayment != null && !currentPayment.IsFreePlan())
return currentPayment.Method == (int)PaymentMethods.Paddle;

return Config.PaymentProviderConfig.IsPaddleActive();
}

[HttpGet]
[Authorize]
public async Task<IActionResult> SelectRegistrationPlan(string discountCode = null)
Expand All @@ -81,7 +92,7 @@ public async Task<IActionResult> SelectRegistrationPlan(string discountCode = nu
model.DiscountCode = discountCode;

var paddleCustomerId = await _departmentSettingsService.GetPaddleCustomerIdForDepartmentAsync(DepartmentId);
bool isPaddleDepartment = !string.IsNullOrWhiteSpace(paddleCustomerId);
bool isPaddleDepartment = ShouldUsePaddleForSubscriptionFlow(currentPayment, paddleCustomerId);
model.IsPaddleDepartment = isPaddleDepartment;
model.PaddleEnvironment = Config.PaymentProviderConfig.GetPaddleEnvironment();
model.PaddleClientToken = Config.PaymentProviderConfig.GetPaddleClientToken();
Expand Down Expand Up @@ -232,8 +243,7 @@ public async Task<IActionResult> Index()
model.AddonCost = "0";

var paddleCustomerId = await _departmentSettingsService.GetPaddleCustomerIdForDepartmentAsync(DepartmentId);
bool isPaddleDepartment = !string.IsNullOrWhiteSpace(paddleCustomerId)
|| (model.Payment != null && model.Payment.Method == (int)PaymentMethods.Paddle);
bool isPaddleDepartment = ShouldUsePaddleForSubscriptionFlow(model.Payment, paddleCustomerId);
model.IsPaddleDepartment = isPaddleDepartment;

if (isPaddleDepartment)
Expand Down
Loading