Add unified Razorpay payment requests list
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.android.trisolarisserver.controller
|
||||
|
||||
import com.android.trisolarisserver.component.PropertyAccess
|
||||
import com.android.trisolarisserver.controller.dto.RazorpayPaymentRequestResponse
|
||||
import com.android.trisolarisserver.db.repo.BookingRepo
|
||||
import com.android.trisolarisserver.models.property.Role
|
||||
import com.android.trisolarisserver.repo.RazorpayPaymentLinkRequestRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayQrRequestRepo
|
||||
import com.android.trisolarisserver.security.MyPrincipal
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import java.util.UUID
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/properties/{propertyId}/bookings/{bookingId}/payments/razorpay")
|
||||
class RazorpayPaymentRequestsController(
|
||||
private val propertyAccess: PropertyAccess,
|
||||
private val bookingRepo: BookingRepo,
|
||||
private val qrRequestRepo: RazorpayQrRequestRepo,
|
||||
private val paymentLinkRequestRepo: RazorpayPaymentLinkRequestRepo
|
||||
) {
|
||||
|
||||
@GetMapping("/requests")
|
||||
fun listRequests(
|
||||
@PathVariable propertyId: UUID,
|
||||
@PathVariable bookingId: UUID,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?
|
||||
): List<RazorpayPaymentRequestResponse> {
|
||||
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER, Role.STAFF)
|
||||
val booking = bookingRepo.findById(bookingId).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Booking not found")
|
||||
}
|
||||
if (booking.property.id != propertyId) {
|
||||
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Booking not found for property")
|
||||
}
|
||||
|
||||
val qrItems = qrRequestRepo.findByBookingIdOrderByCreatedAtDesc(bookingId).map { qr ->
|
||||
RazorpayPaymentRequestResponse(
|
||||
type = "QR",
|
||||
requestId = qr.id!!,
|
||||
amount = qr.amount,
|
||||
currency = qr.currency,
|
||||
status = qr.status,
|
||||
createdAt = qr.createdAt.toString(),
|
||||
qrId = qr.qrId,
|
||||
imageUrl = qr.imageUrl,
|
||||
expiryAt = qr.expiryAt?.toString()
|
||||
)
|
||||
}
|
||||
|
||||
val linkItems = paymentLinkRequestRepo.findByBookingIdOrderByCreatedAtDesc(bookingId).map { link ->
|
||||
RazorpayPaymentRequestResponse(
|
||||
type = "PAYMENT_LINK",
|
||||
requestId = link.id!!,
|
||||
amount = link.amount,
|
||||
currency = link.currency,
|
||||
status = link.status,
|
||||
createdAt = link.createdAt.toString(),
|
||||
paymentLinkId = link.paymentLinkId,
|
||||
paymentLink = link.shortUrl
|
||||
)
|
||||
}
|
||||
|
||||
return (qrItems + linkItems).sortedByDescending { it.createdAt }
|
||||
}
|
||||
}
|
||||
@@ -74,3 +74,17 @@ data class RazorpayQrRecordResponse(
|
||||
val createdAt: String,
|
||||
val responsePayload: String?
|
||||
)
|
||||
|
||||
data class RazorpayPaymentRequestResponse(
|
||||
val type: String,
|
||||
val requestId: UUID,
|
||||
val amount: Long,
|
||||
val currency: String,
|
||||
val status: String,
|
||||
val createdAt: String,
|
||||
val qrId: String? = null,
|
||||
val imageUrl: String? = null,
|
||||
val expiryAt: String? = null,
|
||||
val paymentLinkId: String? = null,
|
||||
val paymentLink: String? = null
|
||||
)
|
||||
|
||||
@@ -11,4 +11,6 @@ interface RazorpayPaymentLinkRequestRepo : JpaRepository<RazorpayPaymentLinkRequ
|
||||
currency: String,
|
||||
status: String
|
||||
): RazorpayPaymentLinkRequest?
|
||||
|
||||
fun findByBookingIdOrderByCreatedAtDesc(bookingId: UUID): List<RazorpayPaymentLinkRequest>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user