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

chore(application-system): Payments updates to lifecycle on callback, UX fixes. #15883

Merged
merged 5 commits into from
Sep 24, 2024

Conversation

obmagnusson
Copy link
Member

@obmagnusson obmagnusson commented Sep 4, 2024

What

  • Extending the lifecycle for payment states on payment callback success.
  • Added loading dots when waiting on payment callback
  • UI updates when applicaiton fails to transition from payment state.

Why

Better UX.
Problem: Application users may experience disruptions after a successful payment due to a service failure. Currently, the payment state lifecycle is limited to 24 hours, which may not be enough time to resolve the issue.

Solution: We will extend the payment state lifecycle, allowing users to continue with the application once the fault is resolved.

Screenshots / Gifs

image
image

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced a new tag for payment callback endpoints in the API documentation for better organization.
    • Enhanced the Callback structure with validation and documentation annotations.
    • Improved payment approval logic to manage application data retention based on payment status.
    • Added a new error message for payment submission failures to enhance user feedback.
  • Bug Fixes

    • Improved error handling in the payment processing component for clearer user notifications.

Copy link
Contributor

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes involve enhancements to the API documentation by adding a new tag for payment callbacks, restructuring the Callback interface into a class with validation, and updating the payment callback processing logic. New error messages related to payment submissions have been introduced, and the payment approval process has been improved by integrating application data management. Overall, these modifications aim to improve the clarity, structure, and robustness of the application.

Changes

File Change Summary
apps/application-system/api/src/openApi.ts Added a new tag payment-callback to the OpenAPI document builder configuration.
libs/api/domains/payment/src/lib/api-domains-payment.types.ts Transformed Callback interface into a class, added validation decorators, and introduced PaidStatus enum.
libs/application/api/core/src/lib/application/application.service.ts Added new string literal type 'pruneAt' to a union type in ApplicationService.
libs/application/api/payment/src/lib/payment-callback.controller.ts Modified PaymentCallbackController to include ApplicationService and updated payment approval logic.
libs/application/core/src/lib/messages.ts Introduced a new error message paymentSubmitFailedDescription for payment submission failures.
apps/application-system/api/src/app/modules/application/e2e/payment/payment-callback.spec.ts Updated payload structure in API tests for payment callbacks, including a real UUID format.

Possibly related PRs

Suggested reviewers

  • sigruntg
  • Toti91
  • baering
  • Hauxii

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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 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.

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.

@obmagnusson obmagnusson changed the title chore(application-system) Payments updates to lifecycle on callback, UX fixes. chore(application-system): Payments updates to lifecycle on callback, UX fixes. Sep 4, 2024
@obmagnusson obmagnusson marked this pull request as ready for review September 4, 2024 13:22
@obmagnusson obmagnusson requested review from a team as code owners September 4, 2024 13:22
Copy link
Member

@jonnigs jonnigs left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@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: 1

Outside diff range, codebase verification and nitpick comments (1)
libs/application/ui-components/src/components/PaymentPending/PaymentPending.tsx (1)

92-112: Enhance error handling by using localized messages.

The changes to the error handling section are approved. The AlertMessage component provides a structured and visually distinct error notification, enhancing the user experience.

Consider using localized messages for the error message text instead of hardcoding it in Icelandic. This will make it easier to support multiple languages in the future. You can use the useMsg hook and define the error message in the message catalog.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9279407 and 1853c4b.

Files selected for processing (7)
  • apps/application-system/api/src/openApi.ts (1 hunks)
  • libs/api/domains/payment/src/lib/api-domains-payment.types.ts (2 hunks)
  • libs/application/api/core/src/lib/application/application.service.ts (1 hunks)
  • libs/application/api/payment/src/lib/payment-callback.controller.ts (2 hunks)
  • libs/application/core/src/lib/messages.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/example-payment-actions/examplePaymentActions.service.ts (1 hunks)
  • libs/application/ui-components/src/components/PaymentPending/PaymentPending.tsx (2 hunks)
Additional context used
Path-based instructions (7)
apps/application-system/api/src/openApi.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/api/domains/payment/src/lib/api-domains-payment.types.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/api/payment/src/lib/payment-callback.controller.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/template-api-modules/src/lib/modules/templates/example-payment-actions/examplePaymentActions.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-components/src/components/PaymentPending/PaymentPending.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/api/core/src/lib/application/application.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/core/src/lib/messages.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (9)
apps/application-system/api/src/openApi.ts (1)

11-11: LGTM!

The addition of the payment-callback tag to the openApi configuration is a valuable improvement that enhances the organization and clarity of the API documentation. The tag is added in the correct order, maintaining the logical grouping of related tags, and adheres to the existing code style and structure.

libs/api/domains/payment/src/lib/api-domains-payment.types.ts (3)

1-3: LGTM!

The new imports from class-validator and @nestjs/swagger are necessary for adding validation decorators and API documentation annotations to the Callback class.


21-26: LGTM!

The new enum paidStatus improves type safety and readability by defining a set of allowed values for the status property of the Callback class.


28-42: Excellent refactoring!

The changes to the Callback interface, transforming it into a class, provide several benefits:

  1. The validation decorators from class-validator ensure that the properties are not empty and are of the correct type, improving data integrity.

  2. The API documentation annotations from @nestjs/swagger enrich the API documentation, making it easier for consumers to understand the structure and constraints of the Callback entity.

  3. The use of the paidStatus enum for the status property improves type safety by restricting the allowed values to a predefined set.

Overall, these changes enhance the structure, validation capabilities, and documentation of the Callback entity.

libs/application/api/payment/src/lib/payment-callback.controller.ts (2)

10-13: LGTM!

The code changes are approved.


Line range hint 15-42: LGTM!

The code changes are approved.

libs/application/ui-components/src/components/PaymentPending/PaymentPending.tsx (1)

8-14: LGTM!

The changes to the import statements are approved. The imported components are used to enhance the user interface and feedback during payment processing. The import statements follow the correct syntax and adhere to the TypeScript usage for defining props and exporting types.

libs/application/api/core/src/lib/application/application.service.ts (1)

302-302: LGTM!

The code change is approved.

libs/application/core/src/lib/messages.ts (1)

424-429: LGTM!

The new paymentSubmitFailedDescription entry in coreErrorMessages looks good. It follows the existing pattern and provides a clear error message to display when a payment submission fails.

Copy link
Member

@Toti91 Toti91 left a comment

Choose a reason for hiding this comment

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

TWo things

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 82.60870% with 4 lines in your changes missing coverage. Please review.

Project coverage is 36.68%. Comparing base (c5d69fd) to head (aca4e07).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...api/payment/src/lib/payment-callback.controller.ts 80.00% 2 Missing ⚠️
...s/src/components/PaymentPending/PaymentPending.tsx 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15883      +/-   ##
==========================================
+ Coverage   36.65%   36.68%   +0.02%     
==========================================
  Files        6750     6759       +9     
  Lines      138925   138993      +68     
  Branches    39472    39481       +9     
==========================================
+ Hits        50926    50983      +57     
- Misses      87999    88010      +11     
Flag Coverage Δ
api 3.39% <ø> (ø)
application-api-files 57.59% <ø> (ø)
application-core 71.62% <ø> (+0.41%) ⬆️
application-system-api 41.57% <90.47%> (+0.07%) ⬆️
application-template-api-modules 23.61% <71.42%> (+0.14%) ⬆️
application-templates-accident-notification 22.14% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.63% <ø> (ø)
application-templates-driving-license 18.63% <ø> (ø)
application-templates-estate 12.34% <0.00%> (-0.02%) ⬇️
application-templates-example-payment 25.41% <ø> (ø)
application-templates-financial-aid 14.34% <ø> (ø)
application-templates-general-petition 23.68% <ø> (ø)
application-templates-health-insurance 26.62% <ø> (ø)
application-templates-inheritance-report 6.45% <ø> (ø)
application-templates-marriage-conditions 15.23% <ø> (ø)
application-templates-mortgage-certificate 43.96% <ø> (ø)
application-templates-parental-leave 30.15% <ø> (ø)
application-ui-components 1.28% <0.00%> (+<0.01%) ⬆️
application-ui-shell 21.29% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
apps/application-system/api/src/openApi.ts 0.00% <ø> (ø)
...mains/payment/src/lib/api-domains-payment.types.ts 100.00% <100.00%> (ø)
...pi/core/src/lib/application/application.service.ts 61.72% <ø> (ø)
libs/application/core/src/lib/messages.ts 100.00% <ø> (ø)
...api/payment/src/lib/payment-callback.controller.ts 85.00% <80.00%> (-5.00%) ⬇️
...s/src/components/PaymentPending/PaymentPending.tsx 2.50% <0.00%> (+0.06%) ⬆️

... and 9 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5d69fd...aca4e07. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 4, 2024

Datadog Report

All test runs 56286d7 🔗

17 Total Test Services: 0 Failed, 17 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.02%), 3 increased, 80 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.01s 1 no change Link
application-api-files 0 0 0 12 0 6.89s 1 no change Link
application-core 0 0 0 90 0 20.89s 1 increased (+0.31%) Link
application-system-api 0 0 0 111 2 3m 21.5s 1 increased (+0.05%) Link
application-template-api-modules 0 0 0 109 0 1m 56.6s 1 increased (+0.12%) Link
application-templates-accident-notification 0 0 0 98 0 19.71s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 11.74s 1 no change Link
application-templates-driving-license 0 0 0 13 0 17.48s 1 no change Link
application-templates-example-payment 0 0 0 2 0 12.12s 1 no change Link
application-templates-financial-aid 0 0 0 11 0 16.52s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • application-templates-estate - jest 18.97% (-0.02%) - Details

Copy link
Contributor

@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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1853c4b and ab5c173.

Files selected for processing (3)
  • libs/api/domains/payment/src/lib/api-domains-payment.types.ts (2 hunks)
  • libs/application/api/payment/src/lib/payment-callback.controller.ts (2 hunks)
  • libs/application/ui-components/src/components/PaymentPending/PaymentPending.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • libs/application/api/payment/src/lib/payment-callback.controller.ts
  • libs/application/ui-components/src/components/PaymentPending/PaymentPending.tsx
Additional context used
Path-based instructions (1)
libs/api/domains/payment/src/lib/api-domains-payment.types.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (3)
libs/api/domains/payment/src/lib/api-domains-payment.types.ts (3)

1-3: LGTM!

The new imports from class-validator and @nestjs/swagger libraries are necessary for using validation decorators and API documentation annotations in the Callback class.


21-26: LGTM!

The new enum PaidStatus provides a clear and type-safe way to represent the possible payment statuses. It is used to define the type of the status property in the Callback class, which improves type safety and readability.


28-42: Excellent improvements to the Callback entity! 👍

The conversion of the Callback interface to a class with validation decorators and API documentation annotations is a significant enhancement that brings several benefits:

  1. Improved structure: The class structure provides a clearer and more organized representation of the Callback entity.

  2. Enhanced type safety: The use of validation decorators from class-validator ensures that the properties are not empty and are of the correct type. This helps prevent errors and improves the robustness of the code.

  3. Better API documentation: The API documentation annotations from @nestjs/swagger provide clear and informative documentation for the Callback entity in the API. This makes it easier for developers to understand and use the API.

Overall, these changes greatly improve the clarity, type safety, and documentation of the Callback entity. Well done!

@obmagnusson obmagnusson added the automerge Merge this PR as soon as all checks pass label Sep 4, 2024
Copy link
Contributor

@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

Outside diff range and nitpick comments (4)
libs/api/domains/payment/src/lib/api-domains-payment.types.ts (2)

20-25: LGTM: The PaidStatus enum is well-defined and enhances type safety.

The enum provides a clear set of possible payment statuses, which is good for type safety and code clarity. It's also exported, allowing for reuse across different parts of the application, which aligns with our reusability guidelines.

Consider adding JSDoc comments to describe each status, especially for recreated and recreatedAndPaid, to improve documentation:

export enum PaidStatus {
  /** Payment successfully completed */
  paid = 'paid',
  /** Payment was cancelled */
  cancelled = 'cancelled',
  /** Payment was recreated (please add more context) */
  recreated = 'recreated',
  /** Payment was recreated and then paid (please add more context) */
  recreatedAndPaid = 'recreatedAndPaid',
}

27-38: LGTM: The Callback class is well-structured and follows best practices.

The conversion of the Callback interface to a class with decorators enhances type safety, provides runtime validation, and improves API documentation. This aligns well with NestJS best practices and our TypeScript usage guidelines. The use of readonly properties ensures immutability, which is a good practice for data objects.

For consistency, consider adding an @ApiProperty() decorator to the status property that includes a description of the enum:

@IsEnum(PaidStatus)
@ApiProperty({ 
  enum: PaidStatus,
  description: 'The status of the payment callback'
})
readonly status!: PaidStatus

This addition would provide more context in the API documentation, improving clarity for API consumers.

apps/application-system/api/src/app/modules/application/e2e/payment/payment-callback.spec.ts (2)

19-28: LGTM! Consider using a constant for the UUID.

The changes improve the test case by simplifying the payload structure and using a more realistic UUID format. The new expectation syntax is also more idiomatic for Jest.

Consider defining the UUID as a constant at the top of the file or in a separate test utilities file. This would make it easier to reuse and update if needed:

const SAMPLE_UUID = '123e4567-e89b-12d3-a456-426614174000';

Then use it in the test case:

receptionID: SAMPLE_UUID,

38-40: LGTM! Consider updating the expectation syntax for consistency.

The changes in this test case are consistent with the improvements made in the first test case, which is good for maintaining overall test consistency and quality.

For consistency with the first test case, consider updating the expectation syntax:

-      .expect(400)
+    const response = await server
+      .post(
+        '/application-payment/32eee126-6b7f-4fca-b9a0-a3618b3e42bf/missing-id',
+      )
+      .send({
+        receptionID: SAMPLE_UUID, // Use the constant suggested earlier
+        chargeItemSubject: 'nice subject.. not',
+        status: 'paid',
+      });
+    expect(response.status).toBe(400);

This change would make both test cases use the same expectation style, improving overall consistency.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ab5c173 and 2ad6016.

Files selected for processing (2)
  • apps/application-system/api/src/app/modules/application/e2e/payment/payment-callback.spec.ts (2 hunks)
  • libs/api/domains/payment/src/lib/api-domains-payment.types.ts (2 hunks)
Additional context used
Path-based instructions (2)
apps/application-system/api/src/app/modules/application/e2e/payment/payment-callback.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/api/domains/payment/src/lib/api-domains-payment.types.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (2)
libs/api/domains/payment/src/lib/api-domains-payment.types.ts (2)

1-2: LGTM: Import statements are appropriate and align with TypeScript usage guidelines.

The new imports from 'class-validator' and '@nestjs/swagger' are necessary for the class decorators and API documentation, which enhances type safety and API clarity.


Line range hint 1-38: Great job adhering to the coding guidelines for libs directory!

The changes in this file align well with the specified guidelines:

  1. Reusability: Both the PaidStatus enum and Callback class are exported, allowing for reuse across different NextJS apps.
  2. TypeScript usage: The code makes excellent use of TypeScript features, including enums, classes, and decorators for defining props and exporting types.
  3. Tree-shaking: The use of named exports (enum and class) allows for effective tree-shaking and bundling.

These changes contribute to creating a robust, reusable, and maintainable codebase.

@kodiakhq kodiakhq bot merged commit 9c26661 into main Sep 24, 2024
72 checks passed
@kodiakhq kodiakhq bot deleted the as-payment-extend-lifecycle-on-success branch September 24, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants