This commit is contained in:
@@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.soune.ReferralService;
|
||||
import ru.soune.nocopy.entity.payment.Payment;
|
||||
import ru.soune.nocopy.entity.payment.PaymentOperationType;
|
||||
import ru.soune.nocopy.entity.payment.PaymentStatus;
|
||||
@@ -38,6 +39,8 @@ public class PaymentService {
|
||||
|
||||
private final TariffInfoService tariffInfoService;
|
||||
|
||||
private final ReferralService referralService;
|
||||
|
||||
@Transactional
|
||||
public Payment createPayment(String email, Long tariffId, String operationType, String paymentUuid) {
|
||||
User user = userRepository.findByEmail(email);
|
||||
@@ -70,9 +73,15 @@ public class PaymentService {
|
||||
.orElseThrow(() -> new PaymentNotFoundException("Payment not found"));
|
||||
|
||||
if ("payment.succeeded".equals(eventType)) {
|
||||
Tariff tariff = payment.getTariff();
|
||||
double price = tariff.getPrice();
|
||||
int intPrice = (int) Math.round(price);
|
||||
|
||||
payment.setStatus(PaymentStatus.SUCCEEDED);
|
||||
payment.setCancellationReason(null);
|
||||
activateTariffForUser(payment.getUser(), payment.getTariff());
|
||||
activateTariffForUser(payment.getUser(), tariff);
|
||||
|
||||
referralService.onUserAccountRefill(payment.getUser().getId(), intPrice);
|
||||
} else if ("payment.canceled".equals(eventType)) {
|
||||
payment.setStatus(PaymentStatus.CANCELED);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user