Allow partial Razorpay settings updates
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s

This commit is contained in:
androidlover5842
2026-02-01 10:32:00 +05:30
parent 58e8cffe9b
commit cc402067c7

View File

@@ -59,6 +59,7 @@ class RazorpaySettingsController(
val property = propertyRepo.findById(propertyId).orElseThrow {
ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
}
val existing = settingsRepo.findByPropertyId(propertyId)
val keyId = request.keyId?.trim()?.ifBlank { null } ?: request.merchantKey?.trim()?.ifBlank { null }
val keySecret = request.keySecret?.trim()?.ifBlank { null }
?: run {
@@ -66,24 +67,25 @@ class RazorpaySettingsController(
val candidate = if (prefer256) request.salt256 else request.salt32
candidate?.trim()?.ifBlank { null } ?: request.salt256?.trim()?.ifBlank { null } ?: request.salt32?.trim()?.ifBlank { null }
}
if (keyId == null || keySecret == null) {
val webhookSecret = request.webhookSecret?.trim()?.ifBlank { null }
val isTest = request.isTest
if (existing == null && (keyId == null || keySecret == null)) {
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "keyId/keySecret required")
}
val existing = settingsRepo.findByPropertyId(propertyId)
val updated = if (existing == null) {
RazorpaySettings(
property = property,
keyId = keyId,
keySecret = keySecret,
webhookSecret = request.webhookSecret?.trim(),
isTest = request.isTest ?: false,
keyId = keyId!!,
keySecret = keySecret!!,
webhookSecret = webhookSecret,
isTest = isTest ?: false,
updatedAt = OffsetDateTime.now()
)
} else {
existing.keyId = keyId
existing.keySecret = keySecret
existing.webhookSecret = request.webhookSecret?.trim()
request.isTest?.let { existing.isTest = it }
if (keyId != null) existing.keyId = keyId
if (keySecret != null) existing.keySecret = keySecret
if (webhookSecret != null) existing.webhookSecret = webhookSecret
isTest?.let { existing.isTest = it }
existing.updatedAt = OffsetDateTime.now()
existing
}