From b5fa38ccfbefb865c5ce8653311f5adc90659b30 Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 08:09:00 +0200 Subject: [PATCH 01/12] Introduce Slack message sending --- build.gradle.kts | 4 ++ .../com/carbonara/core/address/Address.kt | 8 +++ .../com/carbonara/core/order/OrderService.kt | 12 +++- .../carbonara/core/slack/SlackException.kt | 3 + .../core/slack/SlackMessageService.kt | 71 +++++++++++++++++++ .../SlackWebhookController.kt} | 4 +- .../resources/application-staging.properties | 3 + .../com/carbonara/core/address/AddressTest.kt | 27 +++++-- .../carbonara/core/order/OrderServiceTest.kt | 6 +- 9 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/com/carbonara/core/slack/SlackException.kt create mode 100644 src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt rename src/main/kotlin/com/carbonara/core/{delivery/SlackDeliveryWebhookController.kt => slack/SlackWebhookController.kt} (92%) diff --git a/build.gradle.kts b/build.gradle.kts index 65e3651..f7073af 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -49,6 +49,10 @@ dependencies { // Mollie implementation("be.woutschoovaerts:mollie:4.3.0") + // Slack + implementation("com.slack.api:slack-api-model-kotlin-extension:1.42.0") + implementation("com.slack.api:slack-api-client-kotlin-extension:1.42.0") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("io.mockk:mockk:1.13.11") } diff --git a/src/main/kotlin/com/carbonara/core/address/Address.kt b/src/main/kotlin/com/carbonara/core/address/Address.kt index 4443f1f..9c4ab75 100644 --- a/src/main/kotlin/com/carbonara/core/address/Address.kt +++ b/src/main/kotlin/com/carbonara/core/address/Address.kt @@ -12,5 +12,13 @@ data class Address( fun addressPropertiesComplete(): Boolean { return street != null && streetNumber != null && postCode != null && city != null && country != null } + + override fun toString(): String { + return "$street $streetNumber, $postCode $city" + } + + fun createGoogleMapsLink(): String { + return "https://www.google.com/maps/place/?q=place_id:$googlePlaceId" + } } diff --git a/src/main/kotlin/com/carbonara/core/order/OrderService.kt b/src/main/kotlin/com/carbonara/core/order/OrderService.kt index 18ce818..1ed4f5c 100644 --- a/src/main/kotlin/com/carbonara/core/order/OrderService.kt +++ b/src/main/kotlin/com/carbonara/core/order/OrderService.kt @@ -6,6 +6,7 @@ import com.carbonara.core.payment.MolliePaymentService import com.carbonara.core.payment.PaymentException import com.carbonara.core.product.ProductDao import com.carbonara.core.product.ProductService +import com.carbonara.core.slack.SlackMessageService import kotlinx.coroutines.reactor.awaitSingleOrNull import mu.KotlinLogging import org.bson.types.ObjectId @@ -16,7 +17,8 @@ import java.time.OffsetDateTime class OrderService( private val orderRepository: OrderRepository, private val productService: ProductService, - private val molliePaymentService: MolliePaymentService + private val molliePaymentService: MolliePaymentService, + private val slackMessageService: SlackMessageService ) { suspend fun createOrder( @@ -96,7 +98,13 @@ class OrderService( if (order.paymentDetails.internalPaymentStatus != InternalPaymentStatus.PAID) { updateOrderToPaid(order, paymentStatus) - // TODO: trigger delivery + slackMessageService.sendNewOrderMessage( + customerName = order.userName, + orderId = order.orderId.toString(), + address = order.deliveryAddress.toString(), + googleMapsLink = order.deliveryAddress.createGoogleMapsLink(), + productNames = order.products.map { it.productName } + ) } } diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackException.kt b/src/main/kotlin/com/carbonara/core/slack/SlackException.kt new file mode 100644 index 0000000..c2a1e81 --- /dev/null +++ b/src/main/kotlin/com/carbonara/core/slack/SlackException.kt @@ -0,0 +1,3 @@ +package com.carbonara.core.slack + +class SlackException(message: String) : RuntimeException(message) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt new file mode 100644 index 0000000..0dfffcf --- /dev/null +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -0,0 +1,71 @@ +package com.carbonara.core.slack + +import com.slack.api.Slack +import com.slack.api.methods.kotlin_extension.request.chat.blocks +import com.slack.api.model.block.composition.BlockCompositions.plainText +import org.springframework.beans.factory.annotation.Value +import org.springframework.stereotype.Service + +@Service +class SlackMessageService { + + @Value("\${slack.token}") + lateinit var slackToken: String + + @Value("\${slack.channel}") + lateinit var slackChannel: String + + fun sendNewOrderMessage( + customerName: String, + orderId: String, + address: String, + googleMapsLink: String, + productNames: List + ) { + val slack = Slack.getInstance() + val token = System.getenv(slackToken) + val response = slack.methods(token).chatPostMessage { req -> req + .channel(slackChannel) + .blocks { + header { + plainText("New order") + } + section { + markdownText("*Customer Name:*\n$customerName") + markdownText("*OrderId:*\n$orderId") + } + section { + markdownText("*Address:*\n$address\n$googleMapsLink") + markdownText("*Products:*\n${productNames}") + } + actions { + button { + text("ACCEPT", emoji = true) + style("primary") + value("processing_order") + } + button { + text("DELIVERY_IN_PROGRESS", emoji = true) + style("primary") + value("delivery_in_progress") + } + button { + text("DELIVERED", emoji = true) + style("primary") + value("delivered") + } + button { + text("CANCELLED", emoji = true) + style("danger") + value("cancelled") + } + } + } + } + + // TODO: test this + if (!response.isOk) { + throw SlackException("Failed to send slack message for orderId: $orderId") + } + } +} diff --git a/src/main/kotlin/com/carbonara/core/delivery/SlackDeliveryWebhookController.kt b/src/main/kotlin/com/carbonara/core/slack/SlackWebhookController.kt similarity index 92% rename from src/main/kotlin/com/carbonara/core/delivery/SlackDeliveryWebhookController.kt rename to src/main/kotlin/com/carbonara/core/slack/SlackWebhookController.kt index 73cd8e7..3282590 100644 --- a/src/main/kotlin/com/carbonara/core/delivery/SlackDeliveryWebhookController.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackWebhookController.kt @@ -1,4 +1,4 @@ -package com.carbonara.core.delivery +package com.carbonara.core.slack import com.carbonara.core.order.OrderService import mu.KotlinLogging @@ -12,6 +12,8 @@ class SlackDeliveryWebhookController( // Potential dos attack endpoint, introduce rate limiting + // TODO: Handle webhook + @PostMapping("/slack-delivery-status", "application/x-www-form-urlencoded") suspend fun handleSlackWebhook(requestBody: SlackWebhookRequestBody) { log.info("--Start Slack--") diff --git a/src/main/resources/application-staging.properties b/src/main/resources/application-staging.properties index b6e1ac4..ecc119f 100644 --- a/src/main/resources/application-staging.properties +++ b/src/main/resources/application-staging.properties @@ -16,3 +16,6 @@ mollie.redirectUrl=carbonara://order-status mollie.paymentWebhookUrl=https://carbonara-core-mkvkriomda-ew.a.run.app/mollie-payment-status google.apiKey=${sm://projects/897213585789/secrets/google-apiKey} + +slack.token=${sm://projects/897213585789/secrets/slack-token} +slack.channel=C07GLAASC5P diff --git a/src/test/kotlin/com/carbonara/core/address/AddressTest.kt b/src/test/kotlin/com/carbonara/core/address/AddressTest.kt index 48f3912..05a3455 100644 --- a/src/test/kotlin/com/carbonara/core/address/AddressTest.kt +++ b/src/test/kotlin/com/carbonara/core/address/AddressTest.kt @@ -2,19 +2,36 @@ package com.carbonara.core.address import com.carbonara.core.serviceAvailability.ServiceAvailabilityServiceTest.Companion.GOOGLE_PLACE_ID import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test class AddressTest { + @Nested + inner class AddressPropertiesCompleteTests { + + @Test + fun `Happy case - address complete`() { + assertEquals(true, ADDRESS.addressPropertiesComplete()) + } + + @Test + fun `Happy case - address incomplete`() { + val address = ADDRESS.copy(streetNumber = null) + assertEquals(false, address.addressPropertiesComplete()) + } + } + @Test - fun `Happy case - address complete`() { - assertEquals(true, ADDRESS.addressPropertiesComplete()) + fun `Happy case - address to string`() { + val result = ADDRESS.toString() + assertEquals("Baker Street 221b, 12345 London", result) } @Test - fun `Happy case - address incomplete`() { - val address = ADDRESS.copy(streetNumber = null) - assertEquals(false, address.addressPropertiesComplete()) + fun `Happy case - googleMapsLink`() { + val result = ADDRESS.createGoogleMapsLink() + assertEquals("https://www.google.com/maps/place/?q=place_id:$GOOGLE_PLACE_ID", result) } companion object { diff --git a/src/test/kotlin/com/carbonara/core/order/OrderServiceTest.kt b/src/test/kotlin/com/carbonara/core/order/OrderServiceTest.kt index e667ae5..12862ef 100644 --- a/src/test/kotlin/com/carbonara/core/order/OrderServiceTest.kt +++ b/src/test/kotlin/com/carbonara/core/order/OrderServiceTest.kt @@ -8,6 +8,7 @@ import com.carbonara.core.payment.MolliePaymentService import com.carbonara.core.payment.PaymentException import com.carbonara.core.product.ProductDao import com.carbonara.core.product.ProductService +import com.carbonara.core.slack.SlackMessageService import io.mockk.coEvery import io.mockk.coVerify import io.mockk.every @@ -31,16 +32,19 @@ class OrderServiceTest { private lateinit var orderRepository: OrderRepository private lateinit var productService: ProductService private lateinit var molliePaymentService: MolliePaymentService + private lateinit var slackMessageService: SlackMessageService @BeforeEach fun init() { orderRepository = mockk() productService = mockk() molliePaymentService = mockk() - orderService = OrderService(orderRepository, productService, molliePaymentService) + slackMessageService = mockk() + orderService = OrderService(orderRepository, productService, molliePaymentService, slackMessageService) mockkStatic(OffsetDateTime::class) every { OffsetDateTime.now() } returns TIME + every { slackMessageService.sendNewOrderMessage(any(), any(), any(), any(), any()) } returns Unit } @Nested From 53fd357e1ac4ef3ebe740bba7fb903b7d97ea6bf Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 08:32:47 +0200 Subject: [PATCH 02/12] Fix slack message token and body --- .../core/payment/MolliePaymentWebhookController.kt | 1 + .../com/carbonara/core/slack/SlackMessageService.kt | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/carbonara/core/payment/MolliePaymentWebhookController.kt b/src/main/kotlin/com/carbonara/core/payment/MolliePaymentWebhookController.kt index e30da89..d82de5b 100644 --- a/src/main/kotlin/com/carbonara/core/payment/MolliePaymentWebhookController.kt +++ b/src/main/kotlin/com/carbonara/core/payment/MolliePaymentWebhookController.kt @@ -11,6 +11,7 @@ class MolliePaymentWebhookController( ) { // Potential dos attack endpoint, introduce rate limiting + // TODO: Add response status @PostMapping("/mollie-payment-status", "application/x-www-form-urlencoded") suspend fun handleMollieWebhook(requestBody: MollieWebhookRequestBody) { diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 0dfffcf..07dbe3b 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -23,20 +23,17 @@ class SlackMessageService { productNames: List ) { val slack = Slack.getInstance() - val token = System.getenv(slackToken) - val response = slack.methods(token).chatPostMessage { req -> req + val response = slack.methods(slackToken).chatPostMessage { req -> req .channel(slackChannel) .blocks { header { plainText("New order") } section { - markdownText("*Customer Name:*\n$customerName") - markdownText("*OrderId:*\n$orderId") + markdownText("*Customer Name:*\n$customerName\n*OrderId:*\n$orderId") } section { - markdownText("*Address:*\n$address\n$googleMapsLink") - markdownText("*Products:*\n${productNames}") + markdownText("*Address:*\n$address\n$googleMapsLink\n*Products:*\n${productNames.joinToString(", ")}") } actions { button { @@ -63,7 +60,6 @@ class SlackMessageService { } } - // TODO: test this if (!response.isOk) { throw SlackException("Failed to send slack message for orderId: $orderId") } From b41c1a04f18804cdaa4482853ea43dcaf0a9b2d0 Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 08:44:20 +0200 Subject: [PATCH 03/12] Add error logging --- .../com/carbonara/core/slack/SlackMessageService.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 07dbe3b..5b7bd6b 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -3,6 +3,7 @@ package com.carbonara.core.slack import com.slack.api.Slack import com.slack.api.methods.kotlin_extension.request.chat.blocks import com.slack.api.model.block.composition.BlockCompositions.plainText +import mu.KotlinLogging import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service @@ -61,7 +62,13 @@ class SlackMessageService { } if (!response.isOk) { - throw SlackException("Failed to send slack message for orderId: $orderId") + log.error("Slack API error: ${response.error}") + log.error("Needed: ${response.needed}, Provided: ${response.provided}") + throw SlackException("Failed to send slack message for orderId: $orderId. Error: ${response.error}") } } + + companion object { + private val log = KotlinLogging.logger {} + } } From 3682a1d0858e8b0e4c5668438578c4ba170dd520 Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 12:54:45 +0200 Subject: [PATCH 04/12] Staging delivery channel --- src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt | 1 - src/main/resources/application-staging.properties | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 5b7bd6b..6d02774 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -63,7 +63,6 @@ class SlackMessageService { if (!response.isOk) { log.error("Slack API error: ${response.error}") - log.error("Needed: ${response.needed}, Provided: ${response.provided}") throw SlackException("Failed to send slack message for orderId: $orderId. Error: ${response.error}") } } diff --git a/src/main/resources/application-staging.properties b/src/main/resources/application-staging.properties index ecc119f..ae31f61 100644 --- a/src/main/resources/application-staging.properties +++ b/src/main/resources/application-staging.properties @@ -18,4 +18,4 @@ mollie.paymentWebhookUrl=https://carbonara-core-mkvkriomda-ew.a.run.app/mollie-p google.apiKey=${sm://projects/897213585789/secrets/google-apiKey} slack.token=${sm://projects/897213585789/secrets/slack-token} -slack.channel=C07GLAASC5P +slack.channel=C07KMKK3ZDX From 42298dabf5dc4a04345caa875c284a11c0092ada Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 13:07:28 +0200 Subject: [PATCH 05/12] Nest buttons within elements --- .../core/slack/SlackMessageService.kt | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 6d02774..00c3647 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -37,25 +37,27 @@ class SlackMessageService { markdownText("*Address:*\n$address\n$googleMapsLink\n*Products:*\n${productNames.joinToString(", ")}") } actions { - button { - text("ACCEPT", emoji = true) - style("primary") - value("processing_order") - } - button { - text("DELIVERY_IN_PROGRESS", emoji = true) - style("primary") - value("delivery_in_progress") - } - button { - text("DELIVERED", emoji = true) - style("primary") - value("delivered") - } - button { - text("CANCELLED", emoji = true) - style("danger") - value("cancelled") + elements { + button { + text("ACCEPT", emoji = true) + style("primary") + value("processing_order") + } + button { + text("DELIVERY_IN_PROGRESS", emoji = true) + style("primary") + value("delivery_in_progress") + } + button { + text("DELIVERED", emoji = true) + style("primary") + value("delivered") + } + button { + text("CANCELLED", emoji = true) + style("danger") + value("cancelled") + } } } } From 09f1091270ef2b1dd16d4129a877082b6114ed50 Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 13:18:22 +0200 Subject: [PATCH 06/12] Remove actions from message --- .../core/slack/SlackMessageService.kt | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 00c3647..2b78ea6 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -36,30 +36,31 @@ class SlackMessageService { section { markdownText("*Address:*\n$address\n$googleMapsLink\n*Products:*\n${productNames.joinToString(", ")}") } + /* actions { - elements { - button { - text("ACCEPT", emoji = true) - style("primary") - value("processing_order") - } - button { - text("DELIVERY_IN_PROGRESS", emoji = true) - style("primary") - value("delivery_in_progress") - } - button { - text("DELIVERED", emoji = true) - style("primary") - value("delivered") - } - button { - text("CANCELLED", emoji = true) - style("danger") - value("cancelled") - } + button { + text("ACCEPT", emoji = true) + style("primary") + value("processing_order") + } + button { + text("DELIVERY_IN_PROGRESS", emoji = true) + style("primary") + value("delivery_in_progress") + } + button { + text("DELIVERED", emoji = true) + style("primary") + value("delivered") + } + button { + text("CANCELLED", emoji = true) + style("danger") + value("cancelled") } } + + */ } } From b55bb9c479d6d9ead2022b06ab430eabd4a17979 Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 13:26:31 +0200 Subject: [PATCH 07/12] Only header in message --- src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 2b78ea6..842d452 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -30,13 +30,13 @@ class SlackMessageService { header { plainText("New order") } + /* section { markdownText("*Customer Name:*\n$customerName\n*OrderId:*\n$orderId") } section { markdownText("*Address:*\n$address\n$googleMapsLink\n*Products:*\n${productNames.joinToString(", ")}") } - /* actions { button { text("ACCEPT", emoji = true) From 66b61d6fb68e04a7ae3dce680ad7d21dfaa5c3d4 Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 15:05:44 +0200 Subject: [PATCH 08/12] Very simple sample message --- .../kotlin/com/carbonara/core/slack/SlackMessageService.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 842d452..1febd85 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -27,10 +27,14 @@ class SlackMessageService { val response = slack.methods(slackToken).chatPostMessage { req -> req .channel(slackChannel) .blocks { + divider() + section { + markdownText("*New Order*") + } + /* header { plainText("New order") } - /* section { markdownText("*Customer Name:*\n$customerName\n*OrderId:*\n$orderId") } From fd7bb6072872560152cbc4dce63108626bf66ccb Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 15:15:32 +0200 Subject: [PATCH 09/12] Full message without header --- .../kotlin/com/carbonara/core/slack/SlackMessageService.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 1febd85..7af7648 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -2,7 +2,6 @@ package com.carbonara.core.slack import com.slack.api.Slack import com.slack.api.methods.kotlin_extension.request.chat.blocks -import com.slack.api.model.block.composition.BlockCompositions.plainText import mu.KotlinLogging import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service @@ -27,7 +26,6 @@ class SlackMessageService { val response = slack.methods(slackToken).chatPostMessage { req -> req .channel(slackChannel) .blocks { - divider() section { markdownText("*New Order*") } @@ -35,6 +33,7 @@ class SlackMessageService { header { plainText("New order") } + */ section { markdownText("*Customer Name:*\n$customerName\n*OrderId:*\n$orderId") } @@ -63,8 +62,7 @@ class SlackMessageService { value("cancelled") } } - - */ + divider() } } From 75fd687a119d7507083c20f1aa6eec9616cb877d Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 15:49:01 +0200 Subject: [PATCH 10/12] Message format --- .../kotlin/com/carbonara/core/slack/SlackMessageService.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 7af7648..3da0b46 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -35,10 +35,12 @@ class SlackMessageService { } */ section { - markdownText("*Customer Name:*\n$customerName\n*OrderId:*\n$orderId") + markdownText("*Customer Name:*\n$customerName") + markdownText("*OrderId:*\n$orderId") } section { - markdownText("*Address:*\n$address\n$googleMapsLink\n*Products:*\n${productNames.joinToString(", ")}") + markdownText("*Address:*\n$address\n$googleMapsLink") + markdownText("*Products:*\n${productNames.joinToString(", ")}") } actions { button { From 6c4f85ff02716d3fae1451c66dec6b3be57836ba Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 16:01:27 +0200 Subject: [PATCH 11/12] Separate fields in message --- .../com/carbonara/core/slack/SlackMessageService.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 3da0b46..41114f3 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -35,12 +35,16 @@ class SlackMessageService { } */ section { - markdownText("*Customer Name:*\n$customerName") - markdownText("*OrderId:*\n$orderId") + fields { + markdownText("*Customer Name:*\n$customerName") + markdownText("*OrderId:*\n$orderId") + } } section { - markdownText("*Address:*\n$address\n$googleMapsLink") - markdownText("*Products:*\n${productNames.joinToString(", ")}") + fields { + markdownText("*Address:*\n$address\n$googleMapsLink") + markdownText("*Products:*\n${productNames.joinToString(", ")}") + } } actions { button { From 1d41f1f1564807b5d77af454b414ec88276e12da Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 16:12:08 +0200 Subject: [PATCH 12/12] Response status for mollie webhook and finish slack message --- .../core/payment/MolliePaymentWebhookController.kt | 7 ++++--- .../com/carbonara/core/slack/SlackMessageService.kt | 8 -------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/carbonara/core/payment/MolliePaymentWebhookController.kt b/src/main/kotlin/com/carbonara/core/payment/MolliePaymentWebhookController.kt index d82de5b..e34ab1b 100644 --- a/src/main/kotlin/com/carbonara/core/payment/MolliePaymentWebhookController.kt +++ b/src/main/kotlin/com/carbonara/core/payment/MolliePaymentWebhookController.kt @@ -2,6 +2,7 @@ package com.carbonara.core.payment import com.carbonara.core.order.OrderService import mu.KotlinLogging +import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RestController @@ -11,12 +12,12 @@ class MolliePaymentWebhookController( ) { // Potential dos attack endpoint, introduce rate limiting - // TODO: Add response status - @PostMapping("/mollie-payment-status", "application/x-www-form-urlencoded") - suspend fun handleMollieWebhook(requestBody: MollieWebhookRequestBody) { + @PostMapping("/mollie-payment-status", consumes = ["application/x-www-form-urlencoded"]) + suspend fun handleMollieWebhook(requestBody: MollieWebhookRequestBody): ResponseEntity { log.info("Webhook received for paymentId: {}", requestBody.id) orderService.handleOrderPayment(requestBody.id) + return ResponseEntity.ok().build() } companion object { diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 41114f3..f2db45f 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -26,14 +26,6 @@ class SlackMessageService { val response = slack.methods(slackToken).chatPostMessage { req -> req .channel(slackChannel) .blocks { - section { - markdownText("*New Order*") - } - /* - header { - plainText("New order") - } - */ section { fields { markdownText("*Customer Name:*\n$customerName")