Update payment link status from webhooks
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:
@@ -11,6 +11,7 @@ import com.android.trisolarisserver.controller.dto.RazorpayQrEventResponse
|
||||
import com.android.trisolarisserver.repo.PaymentRepo
|
||||
import com.android.trisolarisserver.repo.PropertyRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayPaymentAttemptRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayPaymentLinkRequestRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayQrRequestRepo
|
||||
import com.android.trisolarisserver.repo.RazorpaySettingsRepo
|
||||
import com.android.trisolarisserver.repo.RazorpayWebhookLogRepo
|
||||
@@ -38,6 +39,7 @@ class RazorpayWebhookCapture(
|
||||
private val paymentRepo: PaymentRepo,
|
||||
private val settingsRepo: RazorpaySettingsRepo,
|
||||
private val razorpayPaymentAttemptRepo: RazorpayPaymentAttemptRepo,
|
||||
private val razorpayPaymentLinkRequestRepo: RazorpayPaymentLinkRequestRepo,
|
||||
private val razorpayQrRequestRepo: RazorpayQrRequestRepo,
|
||||
private val razorpayWebhookLogRepo: RazorpayWebhookLogRepo,
|
||||
private val razorpayQrEvents: RazorpayQrEvents,
|
||||
@@ -85,6 +87,7 @@ class RazorpayWebhookCapture(
|
||||
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 paymentLinkEntity = root.path("payload").path("payment_link").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() }
|
||||
@@ -119,6 +122,18 @@ class RazorpayWebhookCapture(
|
||||
)
|
||||
}
|
||||
|
||||
val paymentLinkId = paymentLinkEntity.path("id").asText(null)
|
||||
val paymentLinkStatus = paymentLinkEntity.path("status").asText(null)
|
||||
if (event != null && event.startsWith("payment_link.") && paymentLinkId != null) {
|
||||
val existingLink = razorpayPaymentLinkRequestRepo.findTopByPaymentLinkIdOrderByCreatedAtDesc(paymentLinkId)
|
||||
if (existingLink != null) {
|
||||
if (!paymentLinkStatus.isNullOrBlank()) {
|
||||
existingLink.status = paymentLinkStatus
|
||||
razorpayPaymentLinkRequestRepo.save(existingLink)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
razorpayPaymentAttemptRepo.save(
|
||||
RazorpayPaymentAttempt(
|
||||
property = property,
|
||||
|
||||
Reference in New Issue
Block a user