|
|
@ -46,32 +46,36 @@ public class RefundController { |
|
|
return jdbcTemplate.queryForList(sql, tempid); |
|
|
return jdbcTemplate.queryForList(sql, tempid); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// @PostMapping("/triggerPaymentStatus") |
|
|
|
|
|
// public ResponseEntity<String> triggerPaymentStatusCheck(@RequestParam("tempid") String tempid) { |
|
|
|
|
|
// try { |
|
|
|
|
|
// // Step 1: Get order_id from order_log |
|
|
|
|
|
// String sql = "SELECT order_id FROM order_log WHERE temp_booking_id = ? AND (order_status IS NULL OR order_status = '')"; |
|
|
|
|
|
// List<Map<String, Object>> results = refundScheduler.jdbcTemplate.queryForList(sql, tempid); |
|
|
|
|
|
// |
|
|
|
|
|
// if (results.isEmpty()) { |
|
|
|
|
|
// return ResponseEntity.ok("No pending order found for this tempid."); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// List<String> orderIds = new ArrayList<>(); |
|
|
|
|
|
// for (Map<String, Object> row : results) { |
|
|
|
|
|
// orderIds.add((String) row.get("order_id")); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 2: Call existing logic to fetch and update |
|
|
|
|
|
// refundScheduler.fetchAndUpdatePaymentStatus(orderIds); |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity.ok("Payment status updated successfully for " + orderIds.size() + " order(s)."); |
|
|
|
|
|
// |
|
|
|
|
|
// } catch (Exception e) { |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// return ResponseEntity.status(500).body("Error: " + e.getMessage()); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
// @PostMapping("/triggerPaymentStatus") |
|
|
|
|
|
// public ResponseEntity<String> |
|
|
|
|
|
// triggerPaymentStatusCheck(@RequestParam("tempid") String tempid) { |
|
|
|
|
|
// try { |
|
|
|
|
|
// // Step 1: Get order_id from order_log |
|
|
|
|
|
// String sql = "SELECT order_id FROM order_log WHERE temp_booking_id = ? AND |
|
|
|
|
|
// (order_status IS NULL OR order_status = '')"; |
|
|
|
|
|
// List<Map<String, Object>> results = |
|
|
|
|
|
// refundScheduler.jdbcTemplate.queryForList(sql, tempid); |
|
|
|
|
|
// |
|
|
|
|
|
// if (results.isEmpty()) { |
|
|
|
|
|
// return ResponseEntity.ok("No pending order found for this tempid."); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// List<String> orderIds = new ArrayList<>(); |
|
|
|
|
|
// for (Map<String, Object> row : results) { |
|
|
|
|
|
// orderIds.add((String) row.get("order_id")); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 2: Call existing logic to fetch and update |
|
|
|
|
|
// refundScheduler.fetchAndUpdatePaymentStatus(orderIds); |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity.ok("Payment status updated successfully for " + |
|
|
|
|
|
// orderIds.size() + " order(s)."); |
|
|
|
|
|
// |
|
|
|
|
|
// } catch (Exception e) { |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// return ResponseEntity.status(500).body("Error: " + e.getMessage()); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
@PostMapping("/triggerPaymentStatus") |
|
|
@PostMapping("/triggerPaymentStatus") |
|
|
public ResponseEntity<Map<String, Object>> triggerPaymentStatusCheck(@RequestParam("tempid") String tempid) { |
|
|
public ResponseEntity<Map<String, Object>> triggerPaymentStatusCheck(@RequestParam("tempid") String tempid) { |
|
|
@ -119,7 +123,8 @@ public class RefundController { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (!isSlotAvailable) break; |
|
|
|
|
|
|
|
|
if (!isSlotAvailable) |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
response.put("available", isSlotAvailable); |
|
|
response.put("available", isSlotAvailable); |
|
|
@ -132,159 +137,170 @@ public class RefundController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// @PostMapping("/initiateRefund") |
|
|
|
|
|
// public ResponseEntity<?> initiateRefund( |
|
|
|
|
|
// @RequestParam("orderId") String orderId, |
|
|
|
|
|
// @RequestParam("bookingId") int bookingId, |
|
|
|
|
|
// @RequestParam(value = "reason", defaultValue = "Manual refund") String reason |
|
|
|
|
|
// ) { |
|
|
|
|
|
// try { |
|
|
|
|
|
// // Step 1: Get payment ID and amount using orderId |
|
|
|
|
|
// String sql = "SELECT id, payment_id, amount FROM payment WHERE order_id = ?"; |
|
|
|
|
|
// Map<String, Object> result = jdbcTemplate.queryForMap(sql, orderId); |
|
|
|
|
|
// |
|
|
|
|
|
// int pid = (int) result.get("id"); |
|
|
|
|
|
// String paymentId = (String) result.get("payment_id"); |
|
|
|
|
|
// double amount = Double.parseDouble(result.get("amount").toString()); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 2: Initiate refund via Razorpay |
|
|
|
|
|
// RazorpayClient razorpayClient = new RazorpayClient(AppConstants.key_id, AppConstants.key_secret); |
|
|
|
|
|
// JSONObject refundRequest = new JSONObject(); |
|
|
|
|
|
// refundRequest.put("amount", (int)(amount * 100)); // Razorpay expects paise |
|
|
|
|
|
// |
|
|
|
|
|
// Refund refund = razorpayClient.payments.refund(paymentId, refundRequest); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 3: Extract refund response |
|
|
|
|
|
// String refundId = refund.get("id"); |
|
|
|
|
|
// String refundStatus = refund.get("status"); |
|
|
|
|
|
// double refundAmount = Double.parseDouble(refund.get("amount").toString()) / 100.0; |
|
|
|
|
|
// |
|
|
|
|
|
// long createdAtEpoch; |
|
|
|
|
|
// Object createdAtObj = refund.get("created_at"); |
|
|
|
|
|
// |
|
|
|
|
|
// if (createdAtObj instanceof Number) { |
|
|
|
|
|
// createdAtEpoch = ((Number) createdAtObj).longValue(); |
|
|
|
|
|
// } else if (createdAtObj instanceof Date) { |
|
|
|
|
|
// createdAtEpoch = ((Date) createdAtObj).toInstant().getEpochSecond(); |
|
|
|
|
|
// } else { |
|
|
|
|
|
// throw new IllegalArgumentException("Unexpected type for created_at: " + createdAtObj.getClass()); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// LocalDateTime createdAt = Instant.ofEpochSecond(createdAtEpoch) |
|
|
|
|
|
// .atZone(ZoneId.of("Asia/Kolkata")) |
|
|
|
|
|
// .toLocalDateTime(); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 4: Save to refund_info table |
|
|
|
|
|
// bookingService.saveRefund(bookingId, pid, refundAmount, refundId, refundStatus, reason); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 5: Print to console |
|
|
|
|
|
// System.out.println("✅ Refund initiated successfully:"); |
|
|
|
|
|
// System.out.println("Refund ID : " + refundId); |
|
|
|
|
|
// System.out.println("Payment ID : " + paymentId); |
|
|
|
|
|
// System.out.println("Refund Amount : ₹" + refundAmount); |
|
|
|
|
|
// System.out.println("Refund Status : " + refundStatus); |
|
|
|
|
|
// System.out.println("Refunded At : " + createdAt); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 6: Return JSON response |
|
|
|
|
|
// Map<String, Object> responseMap = new HashMap<>(); |
|
|
|
|
|
// responseMap.put("refund_id", refundId); |
|
|
|
|
|
// responseMap.put("status", refundStatus); |
|
|
|
|
|
// responseMap.put("amount", refundAmount); |
|
|
|
|
|
// responseMap.put("created_at", createdAt); |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity.ok(responseMap); |
|
|
|
|
|
// |
|
|
|
|
|
// } catch (RazorpayException e) { |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// return ResponseEntity.status(500).body("Razorpay Error: " + e.getMessage()); |
|
|
|
|
|
// } catch (Exception e) { |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// return ResponseEntity.status(500).body("Error: " + e.getMessage()); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
@PostMapping("/initiateRefund") |
|
|
|
|
|
public ResponseEntity<?> initiateRefund( |
|
|
|
|
|
@RequestParam("orderId") String orderId, |
|
|
|
|
|
@RequestParam("bookingId") int bookingId, |
|
|
|
|
|
@RequestParam(value = "reason", defaultValue = "Manual refund") String reason |
|
|
|
|
|
) { |
|
|
|
|
|
try { |
|
|
|
|
|
// Step 1: Get payment ID and amount using orderId |
|
|
|
|
|
String sql = "SELECT id, payment_id, amount FROM payment WHERE order_id = ?"; |
|
|
|
|
|
Map<String, Object> result = jdbcTemplate.queryForMap(sql, orderId); |
|
|
|
|
|
|
|
|
|
|
|
int pid = (int) result.get("id"); |
|
|
|
|
|
String paymentId = (String) result.get("payment_id"); |
|
|
|
|
|
double amount = Double.parseDouble(result.get("amount").toString()); |
|
|
|
|
|
|
|
|
|
|
|
// Step 2: Initiate refund via Razorpay |
|
|
|
|
|
RazorpayClient razorpayClient = new RazorpayClient(AppConstants.key_id, AppConstants.key_secret); |
|
|
|
|
|
JSONObject refundRequest = new JSONObject(); |
|
|
|
|
|
refundRequest.put("amount", (int)(amount * 100)); // Razorpay expects paise |
|
|
|
|
|
|
|
|
|
|
|
Refund refund = razorpayClient.payments.refund(paymentId, refundRequest); |
|
|
|
|
|
|
|
|
|
|
|
// Step 3: Extract refund response details |
|
|
|
|
|
String refundId = refund.get("id"); |
|
|
|
|
|
String refundStatus = refund.get("status"); |
|
|
|
|
|
double refundAmount = Double.parseDouble(refund.get("amount").toString()) / 100.0; |
|
|
|
|
|
|
|
|
|
|
|
Object createdAtObj = refund.get("created_at"); |
|
|
|
|
|
long createdAtEpoch; |
|
|
|
|
|
if (createdAtObj instanceof Number) { |
|
|
|
|
|
createdAtEpoch = ((Number) createdAtObj).longValue(); |
|
|
|
|
|
} else if (createdAtObj instanceof Date) { |
|
|
|
|
|
createdAtEpoch = ((Date) createdAtObj).toInstant().getEpochSecond(); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new IllegalArgumentException("Unexpected type for created_at: " + createdAtObj.getClass()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LocalDateTime createdAt = Instant.ofEpochSecond(createdAtEpoch) |
|
|
|
|
|
.atZone(ZoneId.of("Asia/Kolkata")) |
|
|
|
|
|
.toLocalDateTime(); |
|
|
|
|
|
|
|
|
|
|
|
// Step 4: Save refund record |
|
|
|
|
|
refundService.saveRefund(bookingId, pid, refundAmount, refundId, refundStatus, reason); |
|
|
|
|
|
|
|
|
|
|
|
// Step 5: Update status in payment and order_log tables |
|
|
|
|
|
//jdbcTemplate.update("UPDATE order_log SET order_status = ? WHERE order_id = ?", "" orderId); |
|
|
|
|
|
jdbcTemplate.update("UPDATE payment SET payment_status = ? WHERE order_id = ?", "refunded", orderId); |
|
|
|
|
|
|
|
|
|
|
|
// Step 6: Print refund info to console |
|
|
|
|
|
System.out.println("✅ Refund initiated successfully:"); |
|
|
|
|
|
System.out.println("Refund ID : " + refundId); |
|
|
|
|
|
System.out.println("Payment ID : " + paymentId); |
|
|
|
|
|
System.out.println("Refund Amount : ₹" + refundAmount); |
|
|
|
|
|
System.out.println("Refund Status : " + refundStatus); |
|
|
|
|
|
System.out.println("Refunded At : " + createdAt); |
|
|
|
|
|
System.out.println("📝 payment tables updated to 'refund'."); |
|
|
|
|
|
|
|
|
|
|
|
// Step 7: Return response |
|
|
|
|
|
Map<String, Object> responseMap = new HashMap<>(); |
|
|
|
|
|
responseMap.put("refund_id", refundId); |
|
|
|
|
|
responseMap.put("status", refundStatus); |
|
|
|
|
|
responseMap.put("amount", refundAmount); |
|
|
|
|
|
responseMap.put("created_at", createdAt.toString()); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(responseMap); |
|
|
|
|
|
|
|
|
|
|
|
} catch (RazorpayException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
String errorMsg = e.getMessage(); |
|
|
|
|
|
System.err.println("Razorpay Error: " + errorMsg); |
|
|
|
|
|
|
|
|
|
|
|
if (errorMsg.contains("already")) { |
|
|
|
|
|
return ResponseEntity.status(400).body("Refund already completed for this payment."); |
|
|
|
|
|
|
|
|
@PostMapping("/initiateRefundBrokenTrans") |
|
|
|
|
|
public String initiateRefundBrokenTrans() { |
|
|
|
|
|
try { |
|
|
|
|
|
refundScheduler.updateOrderPaymentStatus(); |
|
|
|
|
|
return "Sucess"; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
} |
|
|
} |
|
|
return ResponseEntity.status(500).body("Razorpay Error: " + e.getMessage()); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return ResponseEntity.status(500).body("Error: " + e.getMessage()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @PostMapping("/initiateRefund") |
|
|
|
|
|
// public ResponseEntity<?> initiateRefund( |
|
|
|
|
|
// @RequestParam("orderId") String orderId, |
|
|
|
|
|
// @RequestParam("bookingId") int bookingId, |
|
|
|
|
|
// @RequestParam(value = "reason", defaultValue = "Manual refund") String reason |
|
|
|
|
|
// ) { |
|
|
|
|
|
// try { |
|
|
|
|
|
// // Step 1: Get payment ID and amount using orderId |
|
|
|
|
|
// String sql = "SELECT id, payment_id, amount FROM payment WHERE order_id = ?"; |
|
|
|
|
|
// Map<String, Object> result = jdbcTemplate.queryForMap(sql, orderId); |
|
|
|
|
|
// |
|
|
|
|
|
// int pid = (int) result.get("id"); |
|
|
|
|
|
// String paymentId = (String) result.get("payment_id"); |
|
|
|
|
|
// double amount = Double.parseDouble(result.get("amount").toString()); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 2: Initiate refund via Razorpay |
|
|
|
|
|
// RazorpayClient razorpayClient = new RazorpayClient(AppConstants.key_id, |
|
|
|
|
|
// AppConstants.key_secret); |
|
|
|
|
|
// JSONObject refundRequest = new JSONObject(); |
|
|
|
|
|
// refundRequest.put("amount", (int)(amount * 100)); // Razorpay expects paise |
|
|
|
|
|
// |
|
|
|
|
|
// Refund refund = razorpayClient.payments.refund(paymentId, refundRequest); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 3: Extract refund response |
|
|
|
|
|
// String refundId = refund.get("id"); |
|
|
|
|
|
// String refundStatus = refund.get("status"); |
|
|
|
|
|
// double refundAmount = Double.parseDouble(refund.get("amount").toString()) / |
|
|
|
|
|
// 100.0; |
|
|
|
|
|
// |
|
|
|
|
|
// long createdAtEpoch; |
|
|
|
|
|
// Object createdAtObj = refund.get("created_at"); |
|
|
|
|
|
// |
|
|
|
|
|
// if (createdAtObj instanceof Number) { |
|
|
|
|
|
// createdAtEpoch = ((Number) createdAtObj).longValue(); |
|
|
|
|
|
// } else if (createdAtObj instanceof Date) { |
|
|
|
|
|
// createdAtEpoch = ((Date) createdAtObj).toInstant().getEpochSecond(); |
|
|
|
|
|
// } else { |
|
|
|
|
|
// throw new IllegalArgumentException("Unexpected type for created_at: " + |
|
|
|
|
|
// createdAtObj.getClass()); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// LocalDateTime createdAt = Instant.ofEpochSecond(createdAtEpoch) |
|
|
|
|
|
// .atZone(ZoneId.of("Asia/Kolkata")) |
|
|
|
|
|
// .toLocalDateTime(); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 4: Save to refund_info table |
|
|
|
|
|
// bookingService.saveRefund(bookingId, pid, refundAmount, refundId, |
|
|
|
|
|
// refundStatus, reason); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 5: Print to console |
|
|
|
|
|
// System.out.println("✅ Refund initiated successfully:"); |
|
|
|
|
|
// System.out.println("Refund ID : " + refundId); |
|
|
|
|
|
// System.out.println("Payment ID : " + paymentId); |
|
|
|
|
|
// System.out.println("Refund Amount : ₹" + refundAmount); |
|
|
|
|
|
// System.out.println("Refund Status : " + refundStatus); |
|
|
|
|
|
// System.out.println("Refunded At : " + createdAt); |
|
|
|
|
|
// |
|
|
|
|
|
// // Step 6: Return JSON response |
|
|
|
|
|
// Map<String, Object> responseMap = new HashMap<>(); |
|
|
|
|
|
// responseMap.put("refund_id", refundId); |
|
|
|
|
|
// responseMap.put("status", refundStatus); |
|
|
|
|
|
// responseMap.put("amount", refundAmount); |
|
|
|
|
|
// responseMap.put("created_at", createdAt); |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity.ok(responseMap); |
|
|
|
|
|
// |
|
|
|
|
|
// } catch (RazorpayException e) { |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// return ResponseEntity.status(500).body("Razorpay Error: " + e.getMessage()); |
|
|
|
|
|
// } catch (Exception e) { |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// return ResponseEntity.status(500).body("Error: " + e.getMessage()); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
@PostMapping("/initiateRefund") |
|
|
|
|
|
public ResponseEntity<?> initiateRefund( |
|
|
|
|
|
@RequestParam("orderId") String orderId, |
|
|
|
|
|
@RequestParam("bookingId") int bookingId, |
|
|
|
|
|
@RequestParam(value = "reason", defaultValue = "Manual refund") String reason) { |
|
|
|
|
|
try { |
|
|
|
|
|
// Step 1: Get payment ID and amount using orderId |
|
|
|
|
|
String sql = "SELECT id, payment_id, amount FROM payment WHERE order_id = ?"; |
|
|
|
|
|
Map<String, Object> result = jdbcTemplate.queryForMap(sql, orderId); |
|
|
|
|
|
|
|
|
|
|
|
int pid = (int) result.get("id"); |
|
|
|
|
|
String paymentId = (String) result.get("payment_id"); |
|
|
|
|
|
double amount = Double.parseDouble(result.get("amount").toString()); |
|
|
|
|
|
|
|
|
|
|
|
// Step 2: Initiate refund via Razorpay |
|
|
|
|
|
RazorpayClient razorpayClient = new RazorpayClient(AppConstants.key_id, AppConstants.key_secret); |
|
|
|
|
|
JSONObject refundRequest = new JSONObject(); |
|
|
|
|
|
refundRequest.put("amount", (int) (amount * 100)); // Razorpay expects paise |
|
|
|
|
|
|
|
|
|
|
|
Refund refund = razorpayClient.payments.refund(paymentId, refundRequest); |
|
|
|
|
|
|
|
|
|
|
|
// Step 3: Extract refund response details |
|
|
|
|
|
String refundId = refund.get("id"); |
|
|
|
|
|
String refundStatus = refund.get("status"); |
|
|
|
|
|
double refundAmount = Double.parseDouble(refund.get("amount").toString()) / 100.0; |
|
|
|
|
|
|
|
|
|
|
|
Object createdAtObj = refund.get("created_at"); |
|
|
|
|
|
long createdAtEpoch; |
|
|
|
|
|
if (createdAtObj instanceof Number) { |
|
|
|
|
|
createdAtEpoch = ((Number) createdAtObj).longValue(); |
|
|
|
|
|
} else if (createdAtObj instanceof Date) { |
|
|
|
|
|
createdAtEpoch = ((Date) createdAtObj).toInstant().getEpochSecond(); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new IllegalArgumentException("Unexpected type for created_at: " + createdAtObj.getClass()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LocalDateTime createdAt = Instant.ofEpochSecond(createdAtEpoch) |
|
|
|
|
|
.atZone(ZoneId.of("Asia/Kolkata")) |
|
|
|
|
|
.toLocalDateTime(); |
|
|
|
|
|
|
|
|
|
|
|
// Step 4: Save refund record |
|
|
|
|
|
refundService.saveRefund(bookingId, pid, refundAmount, refundId, refundStatus, reason); |
|
|
|
|
|
|
|
|
|
|
|
// Step 5: Update status in payment and order_log tables |
|
|
|
|
|
// jdbcTemplate.update("UPDATE order_log SET order_status = ? WHERE order_id = |
|
|
|
|
|
// ?", "" orderId); |
|
|
|
|
|
jdbcTemplate.update("UPDATE payment SET payment_status = ? WHERE order_id = ?", "refunded", orderId); |
|
|
|
|
|
|
|
|
|
|
|
// Step 6: Print refund info to console |
|
|
|
|
|
System.out.println("✅ Refund initiated successfully:"); |
|
|
|
|
|
System.out.println("Refund ID : " + refundId); |
|
|
|
|
|
System.out.println("Payment ID : " + paymentId); |
|
|
|
|
|
System.out.println("Refund Amount : ₹" + refundAmount); |
|
|
|
|
|
System.out.println("Refund Status : " + refundStatus); |
|
|
|
|
|
System.out.println("Refunded At : " + createdAt); |
|
|
|
|
|
System.out.println("📝 payment tables updated to 'refund'."); |
|
|
|
|
|
|
|
|
|
|
|
// Step 7: Return response |
|
|
|
|
|
Map<String, Object> responseMap = new HashMap<>(); |
|
|
|
|
|
responseMap.put("refund_id", refundId); |
|
|
|
|
|
responseMap.put("status", refundStatus); |
|
|
|
|
|
responseMap.put("amount", refundAmount); |
|
|
|
|
|
responseMap.put("created_at", createdAt.toString()); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(responseMap); |
|
|
|
|
|
|
|
|
|
|
|
} catch (RazorpayException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
String errorMsg = e.getMessage(); |
|
|
|
|
|
System.err.println("Razorpay Error: " + errorMsg); |
|
|
|
|
|
|
|
|
|
|
|
if (errorMsg.contains("already")) { |
|
|
|
|
|
return ResponseEntity.status(400).body("Refund already completed for this payment."); |
|
|
|
|
|
} |
|
|
|
|
|
return ResponseEntity.status(500).body("Razorpay Error: " + e.getMessage()); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return ResponseEntity.status(500).body("Error: " + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@PostMapping("/confirmBooking") |
|
|
@PostMapping("/confirmBooking") |
|
|
public ResponseEntity<?> confirmBooking(@RequestParam int tempid, @RequestParam int pid) { |
|
|
public ResponseEntity<?> confirmBooking(@RequestParam int tempid, @RequestParam int pid) { |
|
|
@ -325,18 +341,16 @@ public ResponseEntity<?> initiateRefund( |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/getBookingIdByOrderId") |
|
|
|
|
|
public ResponseEntity<Integer> getBookingId(@RequestParam String orderId) { |
|
|
|
|
|
String sql = "select booking_id from payment where order_id=?"; |
|
|
|
|
|
try { |
|
|
|
|
|
Integer bookingId = jdbcTemplate.queryForObject(sql, Integer.class, orderId); |
|
|
|
|
|
return ResponseEntity.ok(bookingId); |
|
|
|
|
|
} catch (EmptyResultDataAccessException e) { |
|
|
|
|
|
return ResponseEntity.ok(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@GetMapping("/getBookingIdByOrderId") |
|
|
|
|
|
public ResponseEntity<Integer> getBookingId(@RequestParam String orderId) { |
|
|
|
|
|
String sql = "select booking_id from payment where order_id=?"; |
|
|
|
|
|
try { |
|
|
|
|
|
Integer bookingId = jdbcTemplate.queryForObject(sql, Integer.class, orderId); |
|
|
|
|
|
return ResponseEntity.ok(bookingId); |
|
|
|
|
|
} catch (EmptyResultDataAccessException e) { |
|
|
|
|
|
return ResponseEntity.ok(0); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@GetMapping("/getOrderIdByPaymentId") |
|
|
@GetMapping("/getOrderIdByPaymentId") |
|
|
public ResponseEntity<String> getOrderIdByPaymentId(@RequestParam("paymentId") int paymentId) { |
|
|
public ResponseEntity<String> getOrderIdByPaymentId(@RequestParam("paymentId") int paymentId) { |
|
|
@ -364,10 +378,4 @@ public ResponseEntity<?> initiateRefund( |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|