Add Razorpay QR event fetch endpoint
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:
@@ -2,6 +2,7 @@ package com.android.trisolarisserver.controller
|
||||
|
||||
import com.android.trisolarisserver.component.PropertyAccess
|
||||
import com.android.trisolarisserver.controller.dto.RazorpayQrGenerateRequest
|
||||
import com.android.trisolarisserver.controller.dto.RazorpayQrEventResponse
|
||||
import com.android.trisolarisserver.controller.dto.RazorpayQrGenerateResponse
|
||||
import com.android.trisolarisserver.models.booking.BookingStatus
|
||||
import com.android.trisolarisserver.models.payment.RazorpayQrRequest
|
||||
@@ -9,6 +10,7 @@ import com.android.trisolarisserver.models.property.Role
|
||||
import com.android.trisolarisserver.db.repo.BookingRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayQrRequestRepo
|
||||
import com.android.trisolarisserver.repo.RazorpaySettingsRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayWebhookLogRepo
|
||||
import com.android.trisolarisserver.security.MyPrincipal
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.http.HttpEntity
|
||||
@@ -38,6 +40,7 @@ class RazorpayQrPayments(
|
||||
private val bookingRepo: BookingRepo,
|
||||
private val settingsRepo: RazorpaySettingsRepo,
|
||||
private val qrRequestRepo: RazorpayQrRequestRepo,
|
||||
private val webhookLogRepo: RazorpayWebhookLogRepo,
|
||||
private val restTemplate: RestTemplate,
|
||||
private val objectMapper: ObjectMapper
|
||||
) {
|
||||
@@ -193,6 +196,35 @@ class RazorpayQrPayments(
|
||||
)
|
||||
}
|
||||
|
||||
@GetMapping("/qr/{qrId}/events")
|
||||
fun qrEvents(
|
||||
@PathVariable propertyId: UUID,
|
||||
@PathVariable qrId: String,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?
|
||||
): List<RazorpayQrEventResponse> {
|
||||
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER, Role.STAFF)
|
||||
val logs = webhookLogRepo.findByPropertyIdOrderByReceivedAtDesc(propertyId)
|
||||
val out = mutableListOf<RazorpayQrEventResponse>()
|
||||
for (log in logs) {
|
||||
val payload = log.payload ?: continue
|
||||
val node = runCatching { objectMapper.readTree(payload) }.getOrNull() ?: continue
|
||||
val event = node.path("event").asText(null)
|
||||
val qrEntity = node.path("payload").path("qr_code").path("entity")
|
||||
val eventQrId = qrEntity.path("id").asText(null)
|
||||
if (eventQrId != qrId) continue
|
||||
val status = qrEntity.path("status").asText(null)
|
||||
out.add(
|
||||
RazorpayQrEventResponse(
|
||||
event = event,
|
||||
qrId = eventQrId,
|
||||
status = status,
|
||||
receivedAt = log.receivedAt.toString()
|
||||
)
|
||||
)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
private fun postJson(url: String, settings: com.android.trisolarisserver.models.payment.RazorpaySettings, json: String): ResponseEntity<String> {
|
||||
val headers = HttpHeaders()
|
||||
headers.contentType = MediaType.APPLICATION_JSON
|
||||
|
||||
@@ -56,3 +56,10 @@ data class RazorpayPaymentLinkCreateResponse(
|
||||
val currency: String,
|
||||
val paymentLink: String?
|
||||
)
|
||||
|
||||
data class RazorpayQrEventResponse(
|
||||
val event: String?,
|
||||
val qrId: String?,
|
||||
val status: String?,
|
||||
val receivedAt: String
|
||||
)
|
||||
|
||||
@@ -4,4 +4,6 @@ import com.android.trisolarisserver.models.payment.RazorpayWebhookLog
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import java.util.UUID
|
||||
|
||||
interface RazorpayWebhookLogRepo : JpaRepository<RazorpayWebhookLog, UUID>
|
||||
interface RazorpayWebhookLogRepo : JpaRepository<RazorpayWebhookLog, UUID> {
|
||||
fun findByPropertyIdOrderByReceivedAtDesc(propertyId: UUID): List<RazorpayWebhookLog>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user