Return payment link in API response
Some checks failed
build-and-deploy / build-deploy (push) Failing after 28s

This commit is contained in:
androidlover5842
2026-01-30 07:52:57 +05:30
parent b80206b04d
commit fef3752b9d
2 changed files with 17 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import com.android.trisolarisserver.repo.PaymentRepo
import com.android.trisolarisserver.repo.PayuPaymentLinkSettingsRepo
import com.android.trisolarisserver.repo.RoomStayRepo
import com.android.trisolarisserver.security.MyPrincipal
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
@@ -32,7 +33,8 @@ class PayuPaymentLinksController(
private val roomStayRepo: RoomStayRepo,
private val paymentRepo: PaymentRepo,
private val settingsRepo: PayuPaymentLinkSettingsRepo,
private val restTemplate: RestTemplate
private val restTemplate: RestTemplate,
private val objectMapper: ObjectMapper
) {
@PostMapping("/link")
@@ -126,9 +128,11 @@ class PayuPaymentLinksController(
throw ResponseStatusException(HttpStatus.BAD_GATEWAY, "PayU request failed")
}
val paymentLink = extractPaymentLink(responseBody)
return PayuPaymentLinkCreateResponse(
amount = amountLong ?: pending,
currency = booking.property.currency,
paymentLink = paymentLink,
payuResponse = responseBody
)
}
@@ -141,6 +145,17 @@ class PayuPaymentLinksController(
}
}
private fun extractPaymentLink(body: String): String? {
if (body.isBlank()) return null
return try {
val node = objectMapper.readTree(body)
val link = node.path("result").path("paymentLink").asText(null)
link?.takeIf { it.isNotBlank() }
} catch (_: Exception) {
null
}
}
private fun buildReturnUrl(propertyId: UUID, success: Boolean): String {
val path = if (success) "success" else "failure"
return "https://api.hoteltrisolaris.in/properties/$propertyId/payu/return/$path"

View File

@@ -80,5 +80,6 @@ data class PayuPaymentLinkCreateRequest(
data class PayuPaymentLinkCreateResponse(
val amount: Long,
val currency: String,
val paymentLink: String?,
val payuResponse: String
)