Skip to content

Commit 0f133bb

Browse files
committed
RE1-T115 Fixing Paddle new sub issue
1 parent d68ba7f commit 0f133bb

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Web/Resgrid.Web/Areas/User/Controllers/SubscriptionController.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ public SubscriptionController(IDepartmentsService departmentsService, IUsersServ
6767

6868
#endregion Private Members and Constructors
6969

70+
private static bool ShouldUsePaddleForSubscriptionFlow(Payment currentPayment, string paddleCustomerId)
71+
{
72+
if (!string.IsNullOrWhiteSpace(paddleCustomerId))
73+
return true;
74+
75+
if (currentPayment != null && !currentPayment.IsFreePlan())
76+
return currentPayment.Method == (int)PaymentMethods.Paddle;
77+
78+
return Config.PaymentProviderConfig.IsPaddleActive();
79+
}
80+
7081
[HttpGet]
7182
[Authorize]
7283
public async Task<IActionResult> SelectRegistrationPlan(string discountCode = null)
@@ -81,7 +92,7 @@ public async Task<IActionResult> SelectRegistrationPlan(string discountCode = nu
8192
model.DiscountCode = discountCode;
8293

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

234245
var paddleCustomerId = await _departmentSettingsService.GetPaddleCustomerIdForDepartmentAsync(DepartmentId);
235-
bool isPaddleDepartment = !string.IsNullOrWhiteSpace(paddleCustomerId)
236-
|| (model.Payment != null && model.Payment.Method == (int)PaymentMethods.Paddle);
246+
bool isPaddleDepartment = ShouldUsePaddleForSubscriptionFlow(model.Payment, paddleCustomerId);
237247
model.IsPaddleDepartment = isPaddleDepartment;
238248

239249
if (isPaddleDepartment)

0 commit comments

Comments
 (0)