@@ -58,8 +58,9 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/auto-renewal/disable")
|
@PostMapping("/auto-renewal")
|
||||||
public ResponseEntity<?> disableAutoRenewal(@RequestHeader(value = "Authorization", required = false) String tokenHeader) {
|
public ResponseEntity<?> disableAutoRenewal(@RequestParam(value = "renewal") Boolean renewal,
|
||||||
|
@RequestHeader(value = "Authorization", required = false) String tokenHeader) {
|
||||||
try {
|
try {
|
||||||
if (tokenHeader == null || tokenHeader.isBlank()) {
|
if (tokenHeader == null || tokenHeader.isBlank()) {
|
||||||
Map<String, Object> errorData = new HashMap<>();
|
Map<String, Object> errorData = new HashMap<>();
|
||||||
@@ -68,7 +69,7 @@ public class PaymentController {
|
|||||||
return ResponseEntity.ok().body(Map.of("error", errorData));
|
return ResponseEntity.ok().body(Map.of("error", errorData));
|
||||||
}
|
}
|
||||||
|
|
||||||
paymentService.disableAutoRenewal(authService.useUserAuthToken(tokenHeader));
|
paymentService.changeAutoRenewal(authService.useUserAuthToken(tokenHeader), renewal);
|
||||||
return ResponseEntity.ok(Map.of("message", "Auto-renewal disabled"));
|
return ResponseEntity.ok(Map.of("message", "Auto-renewal disabled"));
|
||||||
} catch (UserNotFoundException e) {
|
} catch (UserNotFoundException e) {
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||||
|
|||||||
@@ -120,12 +120,12 @@ public class PaymentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void disableAutoRenewal(Long userId) {
|
public void changeAutoRenewal(Long userId, boolean autoRenewal) {
|
||||||
User user = userRepository.findById(userId).orElseThrow();
|
User user = userRepository.findById(userId).orElseThrow();
|
||||||
|
|
||||||
TariffInfo tariffInfo = user.getActiveTariffInfo();
|
TariffInfo tariffInfo = user.getActiveTariffInfo();
|
||||||
if (tariffInfo != null) {
|
if (tariffInfo != null) {
|
||||||
tariffInfo.setAutoRenewal(false);
|
tariffInfo.setAutoRenewal(autoRenewal);
|
||||||
tariffInfoRepository.save(tariffInfo);
|
tariffInfoRepository.save(tariffInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user