Add Razorpay active QR fetch and close
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s

This commit is contained in:
androidlover5842
2026-02-01 10:52:46 +05:30
parent 132c3b19c0
commit d53d179963
2 changed files with 60 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
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.PostMapping
import org.springframework.web.bind.annotation.RequestBody
@@ -140,6 +141,60 @@ class RazorpayQrPayments(
)
}
@GetMapping("/qr/active")
fun getActiveQr(
@PathVariable propertyId: UUID,
@PathVariable bookingId: UUID,
@AuthenticationPrincipal principal: MyPrincipal?
): RazorpayQrGenerateResponse? {
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 active = qrRequestRepo.findTopByBookingIdAndStatusOrderByCreatedAtDesc(bookingId, "active") ?: return null
return RazorpayQrGenerateResponse(
qrId = active.qrId,
amount = active.amount,
currency = active.currency,
imageUrl = active.imageUrl
)
}
@PostMapping("/qr/close")
@Transactional
fun closeActiveQr(
@PathVariable propertyId: UUID,
@PathVariable bookingId: UUID,
@AuthenticationPrincipal principal: MyPrincipal?
): RazorpayQrGenerateResponse? {
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 active = qrRequestRepo.findTopByBookingIdAndStatusOrderByCreatedAtDesc(bookingId, "active") ?: return null
val settings = settingsRepo.findByPropertyId(propertyId)
?: throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Razorpay settings not configured")
val qrId = active.qrId ?: return null
val response = postJson(resolveBaseUrl(settings.isTest) + "/payments/qr_codes/$qrId/close", settings, "{}")
if (!response.statusCode.is2xxSuccessful) {
throw ResponseStatusException(HttpStatus.BAD_GATEWAY, "Razorpay close request failed")
}
active.status = "closed"
qrRequestRepo.save(active)
return RazorpayQrGenerateResponse(
qrId = active.qrId,
amount = active.amount,
currency = active.currency,
imageUrl = active.imageUrl
)
}
private fun postJson(url: String, settings: com.android.trisolarisserver.models.payment.RazorpaySettings, json: String): ResponseEntity<String> {
val headers = HttpHeaders()
headers.contentType = MediaType.APPLICATION_JSON

View File

@@ -11,4 +11,9 @@ interface RazorpayQrRequestRepo : JpaRepository<RazorpayQrRequest, UUID> {
currency: String,
status: String
): RazorpayQrRequest?
fun findTopByBookingIdAndStatusOrderByCreatedAtDesc(
bookingId: UUID,
status: String
): RazorpayQrRequest?
}