-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NT] PayPal integration, Redis/RabbitMQ
- Loading branch information
Showing
31 changed files
with
380 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/java/com/archivision/community/dto/PaymentRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/archivision/community/event/PaymentEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.archivision.community.event; | ||
|
||
import java.io.Serializable; | ||
|
||
public record PaymentEvent(String paymentId, String status, String amount) implements Serializable { | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/archivision/community/listener/PaymentEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.archivision.community.listener; | ||
|
||
import com.archivision.community.entity.User; | ||
import com.archivision.community.event.PaymentEvent; | ||
import com.archivision.community.service.NotificationService; | ||
import com.archivision.community.service.UserService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class PaymentEventListener { | ||
private final NotificationService notificationService; | ||
private final RedisTemplate<String, String> redisTemplate; | ||
private final UserService userService; | ||
|
||
@RabbitListener(queues = "payment-events") | ||
public void handleSuccessPayment(PaymentEvent event) { | ||
String chatId = redisTemplate.opsForValue().getAndDelete(event.paymentId()); | ||
userService.changeSubscription(chatId, User.Subscription.VIP); | ||
notificationService.notifyUserAboutSuccessfulPayment(chatId, "Успішний платіж!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/archivision/community/model/FilterResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.archivision.community.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class FilterResult { | ||
private String message; | ||
private boolean processNext; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/archivision/community/model/Subscription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.archivision.community.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class Subscription { | ||
private String name; | ||
private int price; | ||
private String description; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/archivision/community/service/ServiceCommandChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.archivision.community.service; | ||
|
||
import com.archivision.community.messagesender.MessageSender; | ||
import com.archivision.community.model.FilterResult; | ||
import com.archivision.community.model.Subscription; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.telegram.telegrambots.meta.api.objects.Message; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ServiceCommandChecker { | ||
private final Set<String> commands = new HashSet<>(); | ||
private final MessageSender messageSender; | ||
private final SubscriptionService subscriptionService; | ||
|
||
@PostConstruct | ||
public void init() { | ||
commands.add("/subscriptions"); | ||
} | ||
|
||
public FilterResult filter(Message message) { | ||
Long chatId = message.getChatId(); | ||
String text = message.getText(); | ||
if (commands.contains(text)) { | ||
List<Subscription> subscriptionTypes = subscriptionService.getAvailableSubscriptionTypes(); | ||
messageSender.sendTextMessage(chatId, formMessage(subscriptionTypes)); | ||
} | ||
return FilterResult.builder().processNext(true).message("Success").build(); | ||
} | ||
|
||
private String formMessage(List<Subscription> subscriptionTypes) { | ||
return subscriptionTypes.stream() | ||
.map(Subscription::getName) | ||
.collect(Collectors.joining(", ")); | ||
} | ||
} |
Oops, something went wrong.