Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: integração do sistema com os serviços do Stripe #123

Merged
merged 60 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
8e4f192
enhancement: propriedade StripeCustomerId para a entidade Customer
EduardoKroetz Jun 18, 2024
947782c
enhancement: interface de serviço do stripe(IStripeService)
EduardoKroetz Jun 18, 2024
1e8e2f6
Merge branch 'main' of https://github.com/EduardoKroetz/HotelSistem i…
EduardoKroetz Jun 19, 2024
739760b
feature: implementar métodos do serviço do stripe(StripeService)
EduardoKroetz Jun 19, 2024
31ae913
enhancement: adicionar propriedades as entidade Room, Service e Reser…
EduardoKroetz Jun 19, 2024
5d69ccb
enhancement: integrar os dados com o Stripe, sendo Room como um produto
EduardoKroetz Jun 21, 2024
991cec0
feature: endpoint para atualizar nome de um cômodo
EduardoKroetz Jun 21, 2024
079dfe2
enhancement: atualizar os serviços do stripe, métodos de repositório,…
EduardoKroetz Jun 21, 2024
c0aa0cc
tests: testar a funcionalidade de atualizar o nome de um quarto e tes…
EduardoKroetz Jun 21, 2024
aea2a59
enhancement: usando transaction na criacao de um cômodo para consistê…
EduardoKroetz Jun 21, 2024
e26dd71
enhancement: adicionar transação nos handlers ao lidar com serviço do…
EduardoKroetz Jun 22, 2024
916e5f1
Merge pull request #86 from EduardoKroetz/feature/stripe-room-integra…
EduardoKroetz Jun 22, 2024
37248df
feature: endpoint para realizar pagamentos com cartão de crédito e pá…
EduardoKroetz Jun 22, 2024
3bf1f50
feature: integrar a criação de um serviço com a criação de um produto…
EduardoKroetz Jun 22, 2024
f6ed1d9
enhancement: melhorar teste de criação de serviço com parâmetros invá…
EduardoKroetz Jun 22, 2024
9af1b79
feature: integrar o handler de deletar um serviço com o Stripe(desabi…
EduardoKroetz Jun 22, 2024
4a7c003
feature: integrar o handler de atualizar serviço com o Stripe
EduardoKroetz Jun 23, 2024
2cc32a5
Merge pull request #88 from EduardoKroetz/feature/stripe-service-inte…
EduardoKroetz Jun 23, 2024
add3715
feature: criar PaymentIntent ao criar uma reserva
EduardoKroetz Jun 23, 2024
b8a8d65
feature: integrar criação de customer no Stripe
EduardoKroetz Jun 23, 2024
40013e1
feature: integrar deleção de customer no stripe
EduardoKroetz Jun 23, 2024
707c2c4
Merge pull request #98 from EduardoKroetz/feature/create-stripe-customer
EduardoKroetz Jun 23, 2024
20bc1ca
tests: testar a deleção de um customer
EduardoKroetz Jun 23, 2024
c84107d
Merge pull request #100 from EduardoKroetz/feature/delete-stripe-cust…
EduardoKroetz Jun 23, 2024
c10d0e5
feature: integrar atualização de customer com o customer no Stripe
EduardoKroetz Jun 23, 2024
c3adad1
fix-test: ajustar teste UpdateLoggedCustomer
EduardoKroetz Jun 23, 2024
ab748aa
Merge pull request #101 from EduardoKroetz/feature/update-stripe-cust…
EduardoKroetz Jun 23, 2024
36a06ac
features: atualizar parâmetros no Stripe ao atualizar parâmetros no s…
EduardoKroetz Jun 23, 2024
2a86ec0
Merge pull request #102 from EduardoKroetz/features/update-stripe-cus…
EduardoKroetz Jun 23, 2024
6389cbc
Merge pull request #104 from EduardoKroetz/features/stripe-customer-i…
EduardoKroetz Jun 23, 2024
c9c2268
Merge branch 'feature/payment' of https://github.com/EduardoKroetz/Ho…
EduardoKroetz Jun 23, 2024
4a9e8e0
feature: criar intenção de pagamento no Stripe
EduardoKroetz Jun 23, 2024
eb0efad
Merge pull request #109 from EduardoKroetz/feature/create-payment-intent
EduardoKroetz Jun 23, 2024
141bfab
feature: cancelar PaymentIntent ao deletar uma reserva
EduardoKroetz Jun 23, 2024
75faf32
feature: cancelar um PaymentIntent ao cancelar uma reserva e refatora…
EduardoKroetz Jun 24, 2024
dcc9675
Merge pull request #110 from EduardoKroetz/feature/cancel-payment-intent
EduardoKroetz Jun 24, 2024
e79535b
feature: atualizar preço do PaymentIntent ao atualizar o ExpectedCheckIn
EduardoKroetz Jun 24, 2024
47cacc7
feature: atualizar preço do PaymentIntent ao atualizar o ExpectedChec…
EduardoKroetz Jun 24, 2024
1507f9d
Merge pull request #113 from EduardoKroetz/features/update-payment-in…
EduardoKroetz Jun 24, 2024
75ce624
feature: serviço de criar e adicionar produto nos metadados do Paymen…
EduardoKroetz Jun 24, 2024
5913819
feature: adicionar produto nos metadados do PaymentIntent ao adiciona…
EduardoKroetz Jun 24, 2024
8592413
Merge pull request #115 from EduardoKroetz/feature/add-payment-intent…
EduardoKroetz Jun 24, 2024
eb74c56
feature: criar o serviço para remover o produto do metadado do Paymen…
EduardoKroetz Jun 24, 2024
940df0c
feature: remover produto do PaymentIntent ao remover um serviço de um…
EduardoKroetz Jun 24, 2024
e0c9ece
Merge pull request #116 from EduardoKroetz/feature/remove-payment-int…
EduardoKroetz Jun 24, 2024
95a67d8
refactor: refatorando os testes de integração de ReservationController
EduardoKroetz Jun 25, 2024
c976b23
Merge pull request #117 from EduardoKroetz/refactor/reservation-integ…
EduardoKroetz Jun 25, 2024
a452b09
feature: criar handler para fazer Check-In e adicionar método de paga…
EduardoKroetz Jun 25, 2024
bd93d4d
feature: endpoint para fazer check-in em uma reserva e vincular métod…
EduardoKroetz Jun 25, 2024
17a9808
Merge pull request #118 from EduardoKroetz/feature/reservation-check-in
EduardoKroetz Jun 25, 2024
dce151c
feature: atualizar serviços do Stripe
EduardoKroetz Jun 26, 2024
130e0b8
feature: finalizar reserva e fazer a captura do PaymentIntent
EduardoKroetz Jun 26, 2024
7201a57
enhancement: confirmar o PaymentIntent ao fazer Check-In
EduardoKroetz Jun 26, 2024
8897c32
enhancement: catch de StripeException com mensagem padronizada
EduardoKroetz Jun 26, 2024
23f5fe2
Merge pull request #120 from EduardoKroetz/feature/confirm-and-captur…
EduardoKroetz Jun 26, 2024
72bc44f
Merge pull request #122 from EduardoKroetz/features/stripe-reservatio…
EduardoKroetz Jun 26, 2024
f9f3941
fix: ajustar testes e criar página html para CheckIn
EduardoKroetz Jun 26, 2024
2453f32
adicionar variáveis de ambiente das configs do stripe
EduardoKroetz Jun 26, 2024
6c4b910
habilitar logs de dados sensíveis do dbContext
EduardoKroetz Jun 26, 2024
7fb37f4
tests: alterar mensagem da resposta ao deletar customer
EduardoKroetz Jun 26, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
PasswordToSendEmail: ${{ secrets.PASSWORD_TO_SEND_EMAIL }}
EmailToSendEmail: ${{ secrets.EMAIL_TO_SEND_EMAIL }}
JwtKey: ${{ secrets.JWT_KEY }}

STRIPE__SECRETKEY: ${{ secrets.STRIPE__SECRETKEY }}
STRIPE__PUBLISHABLEKEY: ${{ secrets.STRIPE__PUBLISHABLEKEY }}

steps:
- name: Checkout
Expand Down
18 changes: 13 additions & 5 deletions Hotel.Domain/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ namespace Hotel.Domain;

public static class Configuration
{
public static string ConnectionString = "";
public static string JwtKey = "";
public static string EmailToSendEmail = "";
public static string PasswordToSendEmail = "";
}
public static string ConnectionString = null!;
public static string JwtKey = null!;
public static string EmailToSendEmail = null!;
public static string PasswordToSendEmail = null!;
public static StripeModel Stripe = new();
public static string BaseUrl = "https://localhost:7100";
}

public class StripeModel
{
public string SecretKey { get; set; } = null!;
public string PublishableKey { get; set; } = null!;
};
4 changes: 2 additions & 2 deletions Hotel.Domain/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public async Task<IActionResult> UpdateNameAsync([FromBody] Name name)

// Endpoint para editar o e-mail do cliente (usando ID do token)
[HttpPatch("email")]
public async Task<IActionResult> UpdateEmailAsync([FromBody] Email email)
public async Task<IActionResult> UpdateEmailAsync([FromBody] Email email, [FromQuery] string code)
{
var customerId = _userService.GetUserIdentifier(User);
return Ok(await _handler.HandleUpdateEmailAsync(customerId, email));
return Ok(await _handler.HandleUpdateEmailAsync(customerId, email, code));
}

// Endpoint para editar o telefone do cliente (usando ID do token)
Expand Down
53 changes: 53 additions & 0 deletions Hotel.Domain/Controllers/PaymentController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Hotel.Domain.DTOs;
using Microsoft.AspNetCore.Mvc;
using Stripe;
using Stripe.Checkout;

namespace Hotel.Domain.Controllers;

[ApiController]
[Route("v1/payments")]
public class PaymentController : ControllerBase
{
[HttpPost("checkout/card/{priceId}")]
public async Task<IActionResult> CreateCheckout([FromRoute] string priceId)
{
if (string.IsNullOrEmpty(priceId))
{
return BadRequest(new Response("ID de preço inválido"));
}

var options = new SessionCreateOptions
{
PaymentMethodTypes = new List<string>
{
"card"
},

LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = priceId,
Quantity = 1,
}
},
Mode = "payment",
SuccessUrl = "https://localhost:7100/success.html",
CancelUrl = "https://localhost:7100/cancel.html"
};

var service = new SessionService();

try
{
var session = await service.CreateAsync(options);

return Ok(new Response("Sessão criada com sucesso!", new { sessionId = session.Id }));
}
catch (StripeException)
{
throw new StripeException("Algum erro ocorreu ao criar a sessão de pagamento");
}
}
}
8 changes: 8 additions & 0 deletions Hotel.Domain/Controllers/ReservationControllers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hotel.Domain.Attributes;
using Hotel.Domain.DTOs.PaymentDTOs;
using Hotel.Domain.DTOs.ReservationDTOs;
using Hotel.Domain.Enums;
using Hotel.Domain.Handlers.ReservationHandlers;
Expand Down Expand Up @@ -127,6 +128,13 @@ public async Task<IActionResult> AddServiceAsync([FromRoute] Guid id, [FromRoute
public async Task<IActionResult> RemoveServiceAsync([FromRoute] Guid id, [FromRoute] Guid serviceId)
=> Ok(await _handler.HandleRemoveServiceAsync(id, serviceId));

[HttpPost("check-in/{Id:guid}")]
[AuthorizePermissions([EPermissions.ReservationCheckIn,EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission])]
public async Task<IActionResult> ReservationCheckInAsync([FromRoute] Guid Id, [FromBody] CardOptions cardOptions)
{
return Ok(await _handler.HandleReservationCheckInAsync(Id, cardOptions.TokenId));
}

[HttpPatch("finish/{Id:guid}")]
public async Task<IActionResult> FinishReservationAsync([FromRoute] Guid Id)
{
Expand Down
35 changes: 21 additions & 14 deletions Hotel.Domain/Controllers/RoomController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ public RoomController(RoomHandler handler)
// Endpoint para buscar todos os quartos
[HttpGet]
public async Task<IActionResult> GetAsync(
[FromQuery] int? skip,
[FromQuery] int? take,
[FromQuery] int? number,
[FromQuery] string? numberOperator,
[FromQuery] decimal? price,
[FromQuery] string? priceOperator,
[FromQuery] ERoomStatus? status,
[FromQuery] int? capacity,
[FromQuery] string? capacityOperator,
[FromQuery] Guid? serviceId,
[FromQuery] Guid? categoryId,
[FromQuery] DateTime? createdAt,
[FromQuery] string? createdAtOperator
[FromQuery] int? skip,
[FromQuery] int? take,
[FromQuery] string? name,
[FromQuery] int? number,
[FromQuery] string? numberOperator,
[FromQuery] decimal? price,
[FromQuery] string? priceOperator,
[FromQuery] ERoomStatus? status,
[FromQuery] int? capacity,
[FromQuery] string? capacityOperator,
[FromQuery] Guid? serviceId,
[FromQuery] Guid? categoryId,
[FromQuery] DateTime? createdAt,
[FromQuery] string? createdAtOperator
)
{
var queryParameters = new RoomQueryParameters(
skip, take, number, numberOperator, price, priceOperator, status,
skip, take, name, number, numberOperator, price, priceOperator, status,
capacity, capacityOperator, serviceId, categoryId, createdAt, createdAtOperator
);

Expand Down Expand Up @@ -85,6 +86,12 @@ public async Task<IActionResult> RemoveServiceAsync([FromRoute] Guid id, [FromRo
public async Task<IActionResult> UpdateNumberAsync([FromRoute] Guid id, [FromRoute] int number)
=> Ok(await _handler.HandleUpdateNumberAsync(id, number));

// Endpoint para atualizar o nome de um quarto (com permissão)
[HttpPatch("{id:guid}")]
[AuthorizePermissions([EPermissions.UpdateRoomName, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission])]
public async Task<IActionResult> UpdateNameAsync([FromRoute] Guid id, [FromQuery] string name)
=> Ok(await _handler.HandleUpdateNameAsync(id, name));

// Endpoint para atualizar a capacidade de um quarto (com permissão)
[HttpPatch("{id:guid}/capacity/{capacity:int}")]
[AuthorizePermissions([EPermissions.UpdateRoomCapacity, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission])]
Expand Down
3 changes: 3 additions & 0 deletions Hotel.Domain/DTOs/PaymentDTOs/CardOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Hotel.Domain.DTOs.PaymentDTOs;

public record CardOptions(string TokenId);
4 changes: 3 additions & 1 deletion Hotel.Domain/DTOs/RoomDTOs/EditorRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ namespace Hotel.Domain.DTOs.RoomDTOs;

public class EditorRoom : IDataTransferObject
{
public EditorRoom(int number, decimal price, int capacity, string description, Guid categoryId)
public EditorRoom(string name ,int number, decimal price, int capacity, string description, Guid categoryId)
{
Name = name;
Number = number;
Price = price;
Capacity = capacity;
Description = description;
CategoryId = categoryId;
}

public string Name { get; private set; }
public int Number { get; private set; }
public decimal Price { get; private set; }
public int Capacity { get; private set; }
Expand Down
6 changes: 3 additions & 3 deletions Hotel.Domain/DTOs/RoomDTOs/GetRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ namespace Hotel.Domain.DTOs.RoomDTOs;

public class GetRoom : IDataTransferObject
{
public GetRoom(Guid id, int number, decimal price, ERoomStatus status, int capacity, string description, ICollection<Service> services, Guid categoryId, ICollection<Image> images, DateTime createdAt)
public GetRoom(Guid id,string name , int number, decimal price, ERoomStatus status, int capacity, string description, Guid categoryId, ICollection<Image> images, DateTime createdAt)
{
Id = id;
Name = name;
Number = number;
Price = price;
Status = status;
Capacity = capacity;
Description = description;
Services = services;
CategoryId = categoryId;
Images = images;
CreatedAt = createdAt;
}

public Guid Id { get; set; }
public string Name { get; private set; }
public int Number { get; private set; }
public decimal Price { get; private set; }
public ERoomStatus Status { get; private set; }
public int Capacity { get; private set; }
public string Description { get; private set; }
public ICollection<Service> Services { get; private set; }
public Guid CategoryId { get; private set; }
public ICollection<Image> Images { get; private set; }
public DateTime CreatedAt { get; private set; }
Expand Down
28 changes: 0 additions & 28 deletions Hotel.Domain/DTOs/RoomDTOs/GetRoomCollection.cs

This file was deleted.

4 changes: 3 additions & 1 deletion Hotel.Domain/DTOs/RoomDTOs/RoomQueryParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ namespace Hotel.Domain.DTOs.RoomDTOs;

public class RoomQueryParameters : QueryParameters
{
public RoomQueryParameters(int? skip, int? take, int? number, string? numberOperator, decimal? price, string? priceOperator, ERoomStatus? status, int? capacity, string? capacityOperator, Guid? serviceId, Guid? categoryId, DateTime? createdAt, string? createdAtOperator) : base(skip, take, createdAt, createdAtOperator)
public RoomQueryParameters(int? skip, int? take, string? name, int? number, string? numberOperator, decimal? price, string? priceOperator, ERoomStatus? status, int? capacity, string? capacityOperator, Guid? serviceId, Guid? categoryId, DateTime? createdAt, string? createdAtOperator) : base(skip, take, createdAt, createdAtOperator)
{
Name = name;
Number = number;
NumberOperator = numberOperator;
Price = price;
Expand All @@ -18,6 +19,7 @@ public RoomQueryParameters(int? skip, int? take, int? number, string? numberOper
CategoryId = categoryId;
}

public string? Name { get; private set; }
public int? Number { get; private set; }
public string? NumberOperator { get; private set; }
public decimal? Price { get; private set; }
Expand Down
4 changes: 3 additions & 1 deletion Hotel.Domain/DTOs/ServiceDTOs/EditorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ namespace Hotel.Domain.DTOs.ServiceDTOs;

public class EditorService : IDataTransferObject
{
public EditorService(string name, decimal price, EPriority priority, int timeInMinutes)
public EditorService(string name, string description, decimal price, EPriority priority, int timeInMinutes)
{
Name = name;
Description = description;
Price = price;
Priority = priority;
TimeInMinutes = timeInMinutes;
}

public string Name { get; private set; }
public string Description { get; private set; }
public decimal Price { get; private set; }
public EPriority Priority { get; private set; }
public int TimeInMinutes { get; private set; }
Expand Down
5 changes: 5 additions & 0 deletions Hotel.Domain/Data/HotelDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public HotelDbContext(DbContextOptions<HotelDbContext> options) : base(options)
public DbSet<Like> Likes { get; set; }
public DbSet<Dislike> Dislikes { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.EnableSensitiveDataLogging();
}

protected override void OnModelCreating(ModelBuilder model)
{

Expand Down
4 changes: 4 additions & 0 deletions Hotel.Domain/Data/Mappings/CustomerMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ public void Configure(EntityTypeBuilder<Customer> builder)
{
BaseMapping(builder);


builder.ToTable("Customers");

builder.Property(x => x.StripeCustomerId)
.HasColumnType("NVARCHAR(120)");

builder.HasMany(c => c.Feedbacks)
.WithOne(f => f.Customer)
.HasForeignKey(f => f.CustomerId)
Expand Down
3 changes: 3 additions & 0 deletions Hotel.Domain/Data/Mappings/ReservationMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void Configure(EntityTypeBuilder<Reservation> builder)
builder.Property(x => x.Capacity)
.IsRequired();

builder.Property(x => x.StripePaymentIntentId)
.IsRequired();

builder.Property(x => x.RoomId)
.IsRequired();

Expand Down
9 changes: 9 additions & 0 deletions Hotel.Domain/Data/Mappings/RoomMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public void Configure(EntityTypeBuilder<Room> builder)

builder.ToTable("Rooms");

builder.Property(x => x.Name)
.IsRequired();

builder.HasIndex(x => x.Name)
.IsUnique();

builder.Property(x => x.Number)
.IsRequired();

Expand All @@ -36,6 +42,9 @@ public void Configure(EntityTypeBuilder<Room> builder)
builder.Property(x => x.Description)
.IsRequired();

builder.Property(x => x.StripeProductId)
.IsRequired();

builder.Property(x => x.CategoryId);
builder.HasOne(x => x.Category)
.WithMany(x => x.Rooms)
Expand Down
1 change: 1 addition & 0 deletions Hotel.Domain/Entities/CustomerEntity/Customer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public Customer(Name name, Email email, Phone phone, string password, EGender? g
{
}

public string StripeCustomerId { get; set; } = "";
public ICollection<Feedback> Feedbacks { get; private set; } = [];
public ICollection<Reservation> Reservations { get; private set; } = [];
public ICollection<Invoice> Invoices { get; private set; } = [];
Expand Down
Loading