Handle Razorpay QR code webhook events
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
This commit is contained in:
@@ -8,6 +8,7 @@ import com.android.trisolarisserver.models.payment.RazorpayWebhookLog
|
||||
import com.android.trisolarisserver.repo.PaymentRepo
|
||||
import com.android.trisolarisserver.repo.PropertyRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayPaymentAttemptRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayQrRequestRepo
|
||||
import com.android.trisolarisserver.repo.RazorpaySettingsRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayWebhookLogRepo
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
@@ -34,6 +35,7 @@ class RazorpayWebhookCapture(
|
||||
private val paymentRepo: PaymentRepo,
|
||||
private val settingsRepo: RazorpaySettingsRepo,
|
||||
private val razorpayPaymentAttemptRepo: RazorpayPaymentAttemptRepo,
|
||||
private val razorpayQrRequestRepo: RazorpayQrRequestRepo,
|
||||
private val razorpayWebhookLogRepo: RazorpayWebhookLogRepo,
|
||||
private val objectMapper: ObjectMapper
|
||||
) {
|
||||
@@ -77,6 +79,7 @@ class RazorpayWebhookCapture(
|
||||
val event = root.path("event").asText(null)
|
||||
val paymentEntity = root.path("payload").path("payment").path("entity")
|
||||
val orderEntity = root.path("payload").path("order").path("entity")
|
||||
val qrEntity = root.path("payload").path("qr_code").path("entity")
|
||||
val paymentId = paymentEntity.path("id").asText(null)
|
||||
val orderId = paymentEntity.path("order_id").asText(null)?.takeIf { it.isNotBlank() }
|
||||
?: orderEntity.path("id").asText(null)?.takeIf { it.isNotBlank() }
|
||||
@@ -89,6 +92,18 @@ class RazorpayWebhookCapture(
|
||||
val booking = bookingId?.let { bookingRepo.findById(it).orElse(null) }
|
||||
if (booking != null && booking.property.id != propertyId) return
|
||||
|
||||
val qrId = qrEntity.path("id").asText(null)
|
||||
val qrStatus = qrEntity.path("status").asText(null)
|
||||
if (event != null && event.startsWith("qr_code.") && qrId != null) {
|
||||
val existingQr = razorpayQrRequestRepo.findTopByQrIdOrderByCreatedAtDesc(qrId)
|
||||
if (existingQr != null) {
|
||||
if (!qrStatus.isNullOrBlank()) {
|
||||
existingQr.status = qrStatus
|
||||
razorpayQrRequestRepo.save(existingQr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
razorpayPaymentAttemptRepo.save(
|
||||
RazorpayPaymentAttempt(
|
||||
property = property,
|
||||
|
||||
@@ -16,4 +16,6 @@ interface RazorpayQrRequestRepo : JpaRepository<RazorpayQrRequest, UUID> {
|
||||
bookingId: UUID,
|
||||
status: String
|
||||
): RazorpayQrRequest?
|
||||
|
||||
fun findTopByQrIdOrderByCreatedAtDesc(qrId: String): RazorpayQrRequest?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user