Add PayU payment link API
Some checks failed
build-and-deploy / build-deploy (push) Failing after 30s

This commit is contained in:
androidlover5842
2026-01-30 07:38:53 +05:30
parent 8263bd9212
commit 1e795bc62f
6 changed files with 377 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
package com.android.trisolarisserver.controller
import com.android.trisolarisserver.component.PropertyAccess
import com.android.trisolarisserver.controller.dto.PayuPaymentLinkSettingsResponse
import com.android.trisolarisserver.controller.dto.PayuPaymentLinkSettingsUpsertRequest
import com.android.trisolarisserver.models.payment.PayuPaymentLinkSettings
import com.android.trisolarisserver.models.property.Role
import com.android.trisolarisserver.repo.PayuPaymentLinkSettingsRepo
import com.android.trisolarisserver.repo.PropertyRepo
import com.android.trisolarisserver.security.MyPrincipal
import org.springframework.http.HttpStatus
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
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-payment-link-settings")
class PayuPaymentLinkSettingsController(
private val propertyAccess: PropertyAccess,
private val propertyRepo: PropertyRepo,
private val settingsRepo: PayuPaymentLinkSettingsRepo
) {
@GetMapping
fun getSettings(
@PathVariable propertyId: UUID,
@AuthenticationPrincipal principal: MyPrincipal?
): PayuPaymentLinkSettingsResponse {
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER)
val settings = settingsRepo.findByPropertyId(propertyId)
if (settings == null) {
return PayuPaymentLinkSettingsResponse(
propertyId = propertyId,
configured = false,
merchantId = null,
isTest = false,
hasAccessToken = false
)
}
return settings.toResponse()
}
@PutMapping
fun upsertSettings(
@PathVariable propertyId: UUID,
@AuthenticationPrincipal principal: MyPrincipal?,
@RequestBody request: PayuPaymentLinkSettingsUpsertRequest
): PayuPaymentLinkSettingsResponse {
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER)
val property = propertyRepo.findById(propertyId).orElseThrow {
ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
}
val merchantId = request.merchantId.trim().ifBlank {
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "merchantId required")
}
val accessToken = request.accessToken.trim().ifBlank {
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "accessToken required")
}
val isTest = request.isTest ?: false
val existing = settingsRepo.findByPropertyId(propertyId)
val updated = if (existing == null) {
PayuPaymentLinkSettings(
property = property,
merchantId = merchantId,
accessToken = accessToken,
isTest = isTest,
updatedAt = OffsetDateTime.now()
)
} else {
existing.merchantId = merchantId
existing.accessToken = accessToken
existing.isTest = isTest
existing.updatedAt = OffsetDateTime.now()
existing
}
return settingsRepo.save(updated).toResponse()
}
}
private fun PayuPaymentLinkSettings.toResponse(): PayuPaymentLinkSettingsResponse {
val propertyId = property.id ?: throw ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Property id missing")
return PayuPaymentLinkSettingsResponse(
propertyId = propertyId,
configured = true,
merchantId = merchantId,
isTest = isTest,
hasAccessToken = accessToken.isNotBlank()
)
}