From cc402067c7d5a9e57534b680f9305491b8e48cfd Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Sun, 1 Feb 2026 10:32:00 +0530 Subject: [PATCH] Allow partial Razorpay settings updates --- .../controller/RazorpaySettingsController.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/RazorpaySettingsController.kt b/src/main/kotlin/com/android/trisolarisserver/controller/RazorpaySettingsController.kt index 2605c09..cbc2997 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/RazorpaySettingsController.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/RazorpaySettingsController.kt @@ -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 }