From 9096a283cde24c1e1943cbcaba271e202b01fbed Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Tue, 1 Oct 2024 11:32:37 -0300 Subject: [PATCH 1/3] feat: send free plan data when the beplic account is created --- doppler-beplic/Models/DTO/UserCreationDTO.cs | 4 +-- .../Services/Classes/BeplicService.cs | 31 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/doppler-beplic/Models/DTO/UserCreationDTO.cs b/doppler-beplic/Models/DTO/UserCreationDTO.cs index b9f0278..2a38fdb 100644 --- a/doppler-beplic/Models/DTO/UserCreationDTO.cs +++ b/doppler-beplic/Models/DTO/UserCreationDTO.cs @@ -44,8 +44,8 @@ public class CustomerUserAdmin public class UserCreationPlan { - [JsonProperty("idPlan")] - public int? IdPlan { get; set; } + [JsonProperty("id")] + public int? Id { get; set; } [JsonProperty("name")] public string? PlanName { get; set; } [JsonProperty("messageLimit")] diff --git a/doppler-beplic/Services/Classes/BeplicService.cs b/doppler-beplic/Services/Classes/BeplicService.cs index 474e529..bec94af 100644 --- a/doppler-beplic/Services/Classes/BeplicService.cs +++ b/doppler-beplic/Services/Classes/BeplicService.cs @@ -35,6 +35,28 @@ public BeplicService(IOptions options, BeplicSdk sdk, ILogg public async Task CreateUser(UserCreationDTO accountData) { + var result = new UserCreationResponse(); + + var planFree = (await GetPlans()).FirstOrDefault(x => x.IsFree ?? false); + + if (planFree?.Id is null) + { + LogInfoBadRequest(accountData.Customer.IdExternal, "Plan free not found", HttpStatusCode.InternalServerError.ToString()); + result.Success = false; + result.ErrorStatus = HttpStatusCode.InternalServerError.ToString(); + result.Error = "Plan free not found"; + + return result; + } + + var expirationData = accountData.Customer.Plan?.ExpirationDate is not null + ? Convert.ToDateTime(accountData.Customer.Plan.ExpirationDate, CultureInfo.InvariantCulture) + .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + : DateTime.UtcNow.Date + .AddDays(1) + .AddDays(planFree.TrialPeriod ?? 90) + .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); + accountData.Customer.Partner ??= _options.Customer.Partner; accountData.Customer.BusinessName ??= _options.Customer.BusinessName; accountData.Customer.LegalName ??= _options.Customer.LegalName; @@ -42,14 +64,11 @@ public async Task CreateUser(UserCreationDTO accountData) accountData.Customer.Cuit ??= _options.Customer.Cuit; accountData.Customer.Plan = new UserCreationPlan { - IdPlan = _options.Plan.Id, - PlanName = _options.Plan.Name, - MessageLimit = _options.Plan.MessageLimit, - ExpirationDate = accountData.Customer.Plan?.ExpirationDate + Id = planFree.Id.Value, + PlanName = planFree.Name, + ExpirationDate = expirationData }; - var result = new UserCreationResponse(); - try { var response = await _sdk.ExecuteApiResource("/services/beplicpartners/v1/integra/customers", accountData, RestSharp.Method.Post); From 36656ba3eb00660fa0c2b88cab0dec98743e01b5 Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Tue, 1 Oct 2024 11:32:56 -0300 Subject: [PATCH 2/3] refactor: remove unnecessary setting --- doppler-beplic/appsettings.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doppler-beplic/appsettings.json b/doppler-beplic/appsettings.json index 52b8edb..fb3e6c8 100644 --- a/doppler-beplic/appsettings.json +++ b/doppler-beplic/appsettings.json @@ -31,11 +31,6 @@ "Active": "ACTIVE", "Inactive": "INACTIVE", "Low": "LOW" - }, - "Plan": { - "Id": 5, - "Name": "Free", - "MessageLimit": 1000 } }, "DopplerSecurity": { From 5e835582b48c366d695e5a42d71757209141f732 Mon Sep 17 00:00:00 2001 From: HomeVarela Date: Tue, 1 Oct 2024 15:29:46 -0300 Subject: [PATCH 3/3] refactor: rename variable --- doppler-beplic/Services/Classes/BeplicService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doppler-beplic/Services/Classes/BeplicService.cs b/doppler-beplic/Services/Classes/BeplicService.cs index bec94af..ec9051b 100644 --- a/doppler-beplic/Services/Classes/BeplicService.cs +++ b/doppler-beplic/Services/Classes/BeplicService.cs @@ -49,7 +49,7 @@ public async Task CreateUser(UserCreationDTO accountData) return result; } - var expirationData = accountData.Customer.Plan?.ExpirationDate is not null + var expirationDate = accountData.Customer.Plan?.ExpirationDate is not null ? Convert.ToDateTime(accountData.Customer.Plan.ExpirationDate, CultureInfo.InvariantCulture) .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) : DateTime.UtcNow.Date @@ -66,7 +66,7 @@ public async Task CreateUser(UserCreationDTO accountData) { Id = planFree.Id.Value, PlanName = planFree.Name, - ExpirationDate = expirationData + ExpirationDate = expirationDate }; try