From 1aafbf5c6d3f0f1a702fd16fbbd84b160e802665 Mon Sep 17 00:00:00 2001
From: paula_rodriguezslash <paula.rodriguez@slashmobility.com>
Date: Tue, 23 Apr 2024 15:49:30 +0100
Subject: [PATCH] Gateway updated

---
 .../Controllers/BookingController.cs                |  3 ++-
 .../Clients/BookingService/BookingServiceClient.cs  |  4 ++++
 .../Clients/BookingService/IBookingServiceClient.cs |  1 +
 GatewayAPI/Controllers/BookingController.cs         |  7 +++++++
 GatewayAPI/Models/PaymentIntentCreateRequest.cs     | 13 +++++++++++++
 5 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 GatewayAPI/Models/PaymentIntentCreateRequest.cs

diff --git a/BookingMicroservice/Controllers/BookingController.cs b/BookingMicroservice/Controllers/BookingController.cs
index c9cfa21..9d8953a 100644
--- a/BookingMicroservice/Controllers/BookingController.cs
+++ b/BookingMicroservice/Controllers/BookingController.cs
@@ -142,8 +142,9 @@ namespace BookingMicroservice.Controllers
             }
         }
 
+        [Authorize]
         [HttpPost("create-payment-intent")]
-        public ActionResult CreatePaymentIntent([FromBody] PaymentIntentCreateRequest request)
+        public async Task<IActionResult> CreatePaymentIntent([FromBody] PaymentIntentCreateRequest request)
         {
             var paymentIntentService = new PaymentIntentService();
             var paymentIntent = paymentIntentService.Create(new PaymentIntentCreateOptions
diff --git a/GatewayAPI/Clients/BookingService/BookingServiceClient.cs b/GatewayAPI/Clients/BookingService/BookingServiceClient.cs
index be1534f..d6b89c3 100644
--- a/GatewayAPI/Clients/BookingService/BookingServiceClient.cs
+++ b/GatewayAPI/Clients/BookingService/BookingServiceClient.cs
@@ -57,6 +57,10 @@ namespace GatewayAPI.Clients.BookingService
             return httpClient.GetAsync($"{API_PATH}/history");
         }
 
+        public Task<HttpResponseMessage> CreatePaymentIntent(PaymentIntentCreateRequest request)
+        {
+            return httpClient.PostAsJsonAsync($"{API_PATH}/create-payment-intent", request);
+        }
 
     }
 }
diff --git a/GatewayAPI/Clients/BookingService/IBookingServiceClient.cs b/GatewayAPI/Clients/BookingService/IBookingServiceClient.cs
index be2db11..669bf30 100644
--- a/GatewayAPI/Clients/BookingService/IBookingServiceClient.cs
+++ b/GatewayAPI/Clients/BookingService/IBookingServiceClient.cs
@@ -10,5 +10,6 @@ namespace GatewayAPI.Clients.BookingService
         Task<HttpResponseMessage> UpdateBookingAsync(int bookindId, BookingUpdate bookingModel);
         Task<HttpResponseMessage> GetUpcomingFlightBookingsAsync();
         Task<HttpResponseMessage> GetPreviousFlightBookingsAsync();
+        Task<HttpResponseMessage> CreatePaymentIntent(PaymentIntentCreateRequest request);
     }
 }
diff --git a/GatewayAPI/Controllers/BookingController.cs b/GatewayAPI/Controllers/BookingController.cs
index b6ce381..857ce7a 100644
--- a/GatewayAPI/Controllers/BookingController.cs
+++ b/GatewayAPI/Controllers/BookingController.cs
@@ -57,5 +57,12 @@ namespace GatewayAPI.Controllers
             HttpResponseMessage response = await bookingServiceClient.GetPreviousFlightBookingsAsync();
             return new HttpResponseMessageResult(response);
         }
+
+        [HttpPost("create-payment-intent")]
+        public async  Task<IActionResult> CreatePaymentIntent([FromBody] PaymentIntentCreateRequest request)
+        {
+            HttpResponseMessage response = await bookingServiceClient.CreatePaymentIntent(request);
+            return new HttpResponseMessageResult(response);
+        }
     }
 }
diff --git a/GatewayAPI/Models/PaymentIntentCreateRequest.cs b/GatewayAPI/Models/PaymentIntentCreateRequest.cs
new file mode 100644
index 0000000..6ebf13a
--- /dev/null
+++ b/GatewayAPI/Models/PaymentIntentCreateRequest.cs
@@ -0,0 +1,13 @@
+namespace GatewayAPI.Models
+{
+    public class PaymentIntentCreateRequest 
+    {
+        public List<Item> Items { get; set; }
+    }
+
+    public class Item
+    {
+        public int Price { get; set; }
+    }
+
+}
\ No newline at end of file
-- 
GitLab