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..ec9051b 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 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 + .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 = expirationDate }; - var result = new UserCreationResponse(); - try { var response = await _sdk.ExecuteApiResource("/services/beplicpartners/v1/integra/customers", accountData, RestSharp.Method.Post); 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": {