Skip to content

Commit

Permalink
Merge pull request #118 from FromDoppler/DAT-2195
Browse files Browse the repository at this point in the history
Dat 2195
  • Loading branch information
homecavs authored Oct 4, 2024
2 parents 26382ce + 5e83558 commit 654a8e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions doppler-beplic/Models/DTO/UserCreationDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
31 changes: 25 additions & 6 deletions doppler-beplic/Services/Classes/BeplicService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,40 @@ public BeplicService(IOptions<DefaulValuesOptions> options, BeplicSdk sdk, ILogg

public async Task<UserCreationResponse> 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;
accountData.Customer.Address ??= _options.Customer.Address;
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);
Expand Down
5 changes: 0 additions & 5 deletions doppler-beplic/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
"Active": "ACTIVE",
"Inactive": "INACTIVE",
"Low": "LOW"
},
"Plan": {
"Id": 5,
"Name": "Free",
"MessageLimit": 1000
}
},
"DopplerSecurity": {
Expand Down

0 comments on commit 654a8e9

Please sign in to comment.