Require paymentId for Razorpay refunds
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
This commit is contained in:
@@ -53,27 +53,23 @@ class RazorpayRefundsController(
|
||||
}
|
||||
|
||||
val paymentId = request.paymentId
|
||||
val razorpayPaymentId = request.razorpayPaymentId?.trim()?.ifBlank { null }
|
||||
if ((paymentId == null && razorpayPaymentId == null) || (paymentId != null && razorpayPaymentId != null)) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Provide exactly one of paymentId or razorpayPaymentId")
|
||||
}
|
||||
?: throw ResponseStatusException(HttpStatus.BAD_REQUEST, "paymentId is required")
|
||||
|
||||
val gatewayPaymentId = if (razorpayPaymentId != null) {
|
||||
razorpayPaymentId
|
||||
} else {
|
||||
val payment = paymentRepo.findById(paymentId!!).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Payment not found")
|
||||
val payment = paymentRepo.findById(paymentId).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Payment not found")
|
||||
}
|
||||
if (payment.booking.id != bookingId || payment.property.id != propertyId) {
|
||||
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Payment not found for booking")
|
||||
}
|
||||
request.amount?.let {
|
||||
if (it > payment.amount) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "amount must be <= payment amount")
|
||||
}
|
||||
if (payment.booking.id != bookingId || payment.property.id != propertyId) {
|
||||
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Payment not found for booking")
|
||||
}
|
||||
request.amount?.let {
|
||||
if (it > payment.amount) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "amount must be <= payment amount")
|
||||
}
|
||||
}
|
||||
payment.gatewayPaymentId
|
||||
?: throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Payment is missing gateway id")
|
||||
}
|
||||
val gatewayPaymentId = payment.gatewayPaymentId
|
||||
?: throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Payment is missing gateway id")
|
||||
if (!gatewayPaymentId.startsWith("pay_")) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Payment is not a Razorpay payment")
|
||||
}
|
||||
|
||||
val settings = settingsRepo.findByPropertyId(propertyId)
|
||||
|
||||
@@ -109,7 +109,6 @@ data class RazorpayPaymentRequestCloseResponse(
|
||||
|
||||
data class RazorpayRefundRequest(
|
||||
val paymentId: UUID? = null,
|
||||
val razorpayPaymentId: String? = null,
|
||||
val amount: Long? = null,
|
||||
val notes: String? = null
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user