tarmogoyf

code_review

Sep 28th, 2023 (edited)
1,187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | Source Code | 0 0
  1.  
  2. @Service
  3. public class PaymentService {
  4. @Autowired
  5. private PaymentRepository paymentRepository;
  6. @Autowired
  7. private FeeRepository feeRepository;
  8. @Autowired
  9. private UserRepository userRepository;
  10. @Autowired
  11. private NotificationRestClient notificationRestClient;
  12. @Autowired
  13. private CbrRestClient cbrRestClient;
  14.  
  15. @Transactional
  16. public void processPayment(double amount, Currency currency, Long recipientId) {
  17. double amountInUsd = amount * cbrRestClient.doRequest().getRates().get(currency.getCode());
  18. Long userId = (Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  19. User user = userRepository.findUserById(userId);
  20. Payment payment = new Payment(amountInUsd, user, recipientId);
  21. paymentRepository.save(payment);
  22. if (amountInUsd < 1000) {
  23. Fee fee = new Fee(amountInUsd * 0.015, user);
  24. feeRepository.save(fee);
  25. }
  26. if (amountInUsd > 1000) {
  27. Fee fee = new Fee(amountInUsd * 0.01, user);
  28. feeRepository.save(fee);
  29. }
  30. if (amountInUsd > 5000) {
  31. Fee fee = new Fee(amountInUsd * 0.005, user);
  32. feeRepository.save(fee);
  33. }
  34. try {
  35. notificationRestClient.notify(payment);
  36. } catch (Exception e) {
  37. // do nothing
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment