Skip to content

Commit

Permalink
Merge pull request #67 from KjellBerlin/Introduce-order-status-paymen…
Browse files Browse the repository at this point in the history
…t-failed

Introduce order status payment failed
  • Loading branch information
KjellBerlin authored Aug 28, 2024
2 parents 4f4ad61 + 166157d commit eab5d3e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/com/carbonara/core/order/OrderService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class OrderService(

private suspend fun handleUnpaidOrder(paymentId: String, paymentStatus: PaymentStatus) {
val order = retrieveOrderFromDatabase(paymentId)
updateOrderToFailed(order, paymentStatus)
updateOrderToPaymentFailed(order, paymentStatus)
}

private suspend fun updateOrderToPaid(order: OrderDao, paymentStatus: PaymentStatus) {
Expand All @@ -118,12 +118,12 @@ class OrderService(
}
}

private suspend fun updateOrderToFailed(order: OrderDao, paymentStatus: PaymentStatus) {
private suspend fun updateOrderToPaymentFailed(order: OrderDao, paymentStatus: PaymentStatus) {
log.info("Retrieved payment status={} for orderId={}, now processing order", paymentStatus, order.orderId)
val updatedOrder = order.copy(
paymentDetails = order.paymentDetails.copy(internalPaymentStatus = InternalPaymentStatus.FAILED),
updatedAt = OffsetDateTime.now().toString(),
orderStatus = OrderStatus.CANCELLED
orderStatus = OrderStatus.PAYMENT_FAILED
)
orderRepository.save(updatedOrder).awaitSingleOrNull() ?: run {
log.error("Failed to update payment status to failed for orderId={}", order.orderId)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/carbonara/core/order/OrderStatus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ enum class OrderStatus {
FINDING_AVAILABLE_RIDER,
DELIVERY_IN_PROGRESS,
DELIVERED,
CANCELLED
PAYMENT_FAILED,
CANCELLED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class OrderServiceTest {
val ORDER_DAO_PAYMENT_FAILED = ORDER_DAO.copy(
paymentDetails = ORDER_DAO.paymentDetails.copy(
internalPaymentStatus = InternalPaymentStatus.FAILED),
orderStatus = OrderStatus.CANCELLED
orderStatus = OrderStatus.PAYMENT_FAILED
)
}
}

0 comments on commit eab5d3e

Please sign in to comment.