Add PayU webhook capture per property
Some checks failed
build-and-deploy / build-deploy (push) Failing after 29s
Some checks failed
build-and-deploy / build-deploy (push) Failing after 29s
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package com.android.trisolarisserver.controller
|
||||
|
||||
import com.android.trisolarisserver.models.payment.PayuWebhookLog
|
||||
import com.android.trisolarisserver.repo.PayuWebhookLogRepo
|
||||
import com.android.trisolarisserver.repo.PropertyRepo
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.ResponseStatus
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import java.time.OffsetDateTime
|
||||
import java.util.UUID
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/properties/{propertyId}/payu/webhook")
|
||||
class PayuWebhookCapture(
|
||||
private val propertyRepo: PropertyRepo,
|
||||
private val payuWebhookLogRepo: PayuWebhookLogRepo
|
||||
) {
|
||||
|
||||
@PostMapping
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
fun capture(
|
||||
@PathVariable propertyId: UUID,
|
||||
@RequestBody(required = false) body: String?,
|
||||
request: HttpServletRequest
|
||||
) {
|
||||
val property = propertyRepo.findById(propertyId).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
|
||||
}
|
||||
val headers = request.headerNames.toList().associateWith { request.getHeader(it) }
|
||||
val headersText = headers.entries.joinToString("\n") { (k, v) -> "$k: $v" }
|
||||
payuWebhookLogRepo.save(
|
||||
PayuWebhookLog(
|
||||
property = property,
|
||||
headers = headersText,
|
||||
payload = body,
|
||||
contentType = request.contentType,
|
||||
receivedAt = OffsetDateTime.now()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user