Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete unused payment links on order payment and update related #1578

Merged

Conversation

Cr1stal423
Copy link
Contributor

@Cr1stal423 Cr1stal423 commented Jan 4, 2025

😎 GreenCityUBS PR 😎

Issue Link:
7981
Changes:

Added functionality to remove the link to pay for the notification, which was previously with the unpaid status, from the notification_parameters table after it is paid
Update related tests

Summary by CodeRabbit

  • New Features

    • Enhanced notification management for payment processing.
    • Added ability to retrieve specific notification parameters by key.
    • Improved order payment link handling.
  • Bug Fixes

    • Implemented mechanism to remove payment links after successful order confirmation.
  • Tests

    • Added new test scenarios for payment validation and notification handling.
    • Enhanced tests for user notifications and notification parameters related to payments.

Copy link

coderabbitai bot commented Jan 4, 2025

Walkthrough

The pull request introduces enhancements to notification and payment processing functionality across multiple service components. The changes focus on improving the handling of user notifications related to order payments, specifically adding methods to retrieve and manage notification parameters. A new repository method allows fetching specific notification parameters by user notification and key, while the service implementation adds logic to remove payment links after successful order payment processing. Additionally, utility methods and tests have been updated to support these functionalities.

Changes

File Change Summary
dao/.../NotificationParameterRepository.java Added method findNotificationParameterByUserNotificationAndKey() to retrieve a specific notification parameter
service/.../UBSClientServiceImpl.java Added removePaymentLinkForOrder() method and PAY_BUTTON constant for managing payment-related notifications
service/.../ModelUtils.java Added utility method getNotificationPaymentLink() to generate a sample notification parameter
service/.../UBSClientServiceImplTest.java Updated test methods to include notification-related validation checks

Sequence Diagram

sequenceDiagram
    participant Client
    participant UBSClientService
    participant UserNotificationRepo
    participant NotificationParameterRepo
    
    Client->>UBSClientService: Process Payment
    UBSClientService->>UserNotificationRepo: Find User Notification
    UserNotificationRepo-->>UBSClientService: Return Notification
    UBSClientService->>NotificationParameterRepo: Remove Payment Link
    NotificationParameterRepo-->>UBSClientService: Confirm Removal
    UBSClientService-->>Client: Payment Processed
Loading

Poem

🐰 A Rabbit's Ode to Payment Flows

Notifications dance, a digital ballet,
Payment links vanish without delay,
Repositories sing their coded song,
Linking orders where they belong,
A service that knows just what to say! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9149317 and 081716a.

📒 Files selected for processing (1)
  • service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java (10 hunks)
🔇 Additional comments (3)
service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java (3)

406-411: LGTM! Repository mocks are properly initialized.

The new repository mocks for UserNotificationRepository and NotificationParameterRepository are correctly set up using @mock annotation.


3806-3811: LGTM! Payment validation test verifies notification cleanup.

The test case properly verifies that payment links are cleaned up after successful payment by:

  1. Mocking the retrieval of user notification for unpaid order
  2. Mocking the retrieval of notification parameters
  3. Verifying that both repository methods were called

Also applies to: 3822-3825


4266-4271: LGTM! MonoBank payment validation test is comprehensive.

The test case for MonoBank payment validation properly verifies the notification cleanup flow, similar to the regular payment validation test. The verification steps ensure that the notification repositories are called with correct parameters.

Also applies to: 4279-4282


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
service/src/test/java/greencity/ModelUtils.java (1)

2871-2875: Consider using Optional.of() and extracting constants.
Since there is no scenario where the NotificationParameter is null, Optional.of() is more explicit than ofNullable(). Also, to improve consistency and reduce duplication, consider extracting "payButton" and the URL into constants.

-        return Optional
-            .ofNullable(NotificationParameter.builder().key("payButton").value("https://pay.monobank.ua/api").build());
+        return Optional.of(
+            NotificationParameter.builder()
+                .key(PAY_BUTTON_KEY)
+                .value(MONOBANK_URL)
+                .build()
+        );
service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java (2)

239-239: Prefer descriptive naming for the constant 'PAY_BUTTON'.
While PAY_BUTTON is fine, consider a name like PAYMENT_LINK_KEY to clarify that it represents a particular notification key.

- private static final String PAY_BUTTON = "payButton";
+ private static final String PAYMENT_LINK_KEY = "payButton";

2225-2234: Method removePaymentLinkForOrder is well-structured.

  1. Retrieves the user notification for an unpaid order.
  2. Looks for the payment link parameter.
  3. Deletes it if present.

Potential improvement: Log or handle scenarios where the notification or parameter is not found, so there's a clear audit trail.

+ log.debug("Removing payment link for order {}", order.getId());
Optional<UserNotification> userNotification = ...
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 129809e and 9149317.

📒 Files selected for processing (4)
  • dao/src/main/java/greencity/repository/NotificationParameterRepository.java (1 hunks)
  • service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java (9 hunks)
  • service/src/test/java/greencity/ModelUtils.java (1 hunks)
  • service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java (10 hunks)
🔇 Additional comments (20)
dao/src/main/java/greencity/repository/NotificationParameterRepository.java (2)

13-13: No issues found.


14-15: Ensure null safety in search parameters.
If either userNotification or key can be null, consider using defensive checks or documenting the expected behavior when these inputs are invalid to avoid potential NullPointerException or unintended queries.

service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java (7)

66-67: Imports look good.


97-97: Minor naming alignment check.
Consider whether the existing enums in NotificationType are consistent with naming conventions (e.g., uppercase constants). If everything is in order, proceed.


121-121: New repository import.
This import is used to fetch and delete payment links. No issues found here.


134-134: New import for user notifications.
No concerns; the usage of a separate repository for user notifications keeps responsibilities clear.


276-277: Injected repositories.
Good job injecting both UserNotificationRepository and NotificationParameterRepository for removing unused payment links. No further changes recommended.


1700-1700: Removing payment links on successful order payment.
This call to removePaymentLinkForOrder(order) ensures the link is cleaned up once the order is paid. No issues found.


2190-2190: MonoBank flow calls removePaymentLinkForOrder(order).
Ensures consistency between different payment providers. Looks good.

service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java (11)

51-52: Imports for notification-related entities.
These additions align with new test coverage for removing payment links.


74-74: Confirm test coverage for NotificationType.
Ensure that tests verify the correct NotificationType usage (e.g., UNPAID_ORDER).


96-96: New import for NotificationParameterRepository.
No code smells; properly aligns with the new test implementation.


109-109: New import for UserNotificationRepository.
Ensures the test coverage extends to user notifications references.


195-196: New utility references for test objects.
Ensures consistent test data creation. No issues found.


236-236: Extended test coverage with user notifications.
Good approach to reusing existing model utility methods.


408-413: Mocking new repositories in test.
Defining mocks for UserNotificationRepository and NotificationParameterRepository ensures thorough coverage of new logic.


3808-3813: Tests for validatePayment now check for user notifications.

  1. Use of userNotificationRepository to retrieve the notification.
  2. Use of notificationParameterRepository to retrieve the payment link.
    No immediate issues; ensures proper coverage.

3824-3827: Verifications for user notifications in success flow.
Ensures the link is found and deleted. Looks correct.


4268-4273: Testing MonoBank flow for user notifications.
Covers new code that deletes notification parameters. No issues found.


4281-4284: Ensures cleanup is triggered in MonoBank paths.
Verifies the link removal logic is called upon payment success. Completes coverage for all providers.

@Cr1stal423 Cr1stal423 merged commit 4aa31f5 into dev Jan 5, 2025
5 checks passed
@Cr1stal423 Cr1stal423 deleted the feature/7981/remove-payment-llink-from-DB-when-order-is-paid branch January 5, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants