Skip to content

Return 400 error for specific auth.net error code #903

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

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

landonshumway-ia
Copy link
Collaborator

@landonshumway-ia landonshumway-ia commented Jul 2, 2025

During user testing with practitioners, because we were using test card numbers with repeated names and privilege prices, the Authorize.net suspicious activity filter denied several requests, and this caused the API to fail with a 5xx error. The system should gracefully handle this scenario.

This adds a check for that specific error code so the backend will return a 400 with a message informing the user to try again.

Closes #889

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messaging for declined transactions due to suspicious activity filters, providing users with clearer guidance to wait and retry later.
  • Tests

    • Added tests to verify proper handling and user messaging when transactions are declined by security filters.

Copy link
Contributor

coderabbitai bot commented Jul 2, 2025

"""

Walkthrough

The code update extends error handling for Authorize.net payment processing by adding explicit handling for the 'E00114' error code, which relates to suspicious activity filter rejections. The change ensures that such errors raise a user-friendly exception with retry guidance, and corresponding unit tests are added to verify this behavior.

Changes

File(s) Change Summary
backend/compact-connect/lambdas/python/purchases/purchase_client.py Added handling for Authorize.net error code 'E00114' in _handle_api_error with new exception and message.
backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py Introduced helper for mocking error responses and added a test for 'E00114' suspicious activity filter error.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PurchaseClient
    participant AuthorizeNetAPI

    User->>PurchaseClient: process_charge_for_licensee_privileges()
    PurchaseClient->>AuthorizeNetAPI: create_transaction()
    AuthorizeNetAPI-->>PurchaseClient: API error with code 'E00114'
    PurchaseClient-->>User: Raise CCInvalidRequestException with retry message
Loading

Assessment against linked issues

Objective Addressed Explanation
Gracefully handle Authorize.net suspicious activity filter rejections (E00114) (#889)
Add automated tests for suspicious activity filter handling (#889)

Poem

A filter caught the bunny’s hop,
Suspicious code made payments stop.
Now with care, the client replies—
“Wait a bit, then retry!”
With tests in tow, the bugs take flight,
The burrow’s safe, the code is right.
🐇💳✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Pylint (3.3.7)
backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py

📜 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 4ef2a44 and 870c937.

📒 Files selected for processing (1)
  • backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: TestPython
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 121f381 and 4ef2a44.

📒 Files selected for processing (2)
  • backend/compact-connect/lambdas/python/purchases/purchase_client.py (2 hunks)
  • backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#769
File: backend/compact-connect/lambdas/python/provider-data-v1/handlers/encumbrance.py:39-41
Timestamp: 2025-04-29T02:09:36.291Z
Learning: In the CompactConnect project, authentication/authorization failures like misconfigured authorizers should be allowed to propagate as 500 errors rather than being caught and converted to 4xx errors, as this is intentional to trigger alerts for critical system issues.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#848
File: backend/compact-connect/lambdas/python/provider-data-v1/handlers/registration.py:111-117
Timestamp: 2025-06-17T19:05:36.255Z
Learning: In CompactConnect PR #848, the user landonshumway-ia decided to leave timezone handling code in _should_allow_reregistration function as-is after testing in sandbox environment confirmed it works correctly. The user's reasoning was that reregistration is an edge case, the code has been tested and verified, and AWS is unlikely to change behavior that would break many clients. This represents a pragmatic engineering decision based on testing and risk assessment.
backend/compact-connect/lambdas/python/purchases/purchase_client.py (1)
Learnt from: jusdino
PR: csg-org/CompactConnect#864
File: backend/compact-connect/lambdas/python/common/cc_common/license_util.py:18-37
Timestamp: 2025-06-18T05:57:18.225Z
Learning: In the `get_license_type_by_abbreviation` method in `license_util.py`, KeyError exceptions from invalid compact codes are intentionally caught and re-raised as CCInvalidRequestException with `from e` to provide a consistent interface between invalid compact and invalid abbreviation scenarios, while preserving the original exception information in the chain.
backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py (1)
Learnt from: jusdino
PR: csg-org/CompactConnect#864
File: backend/compact-connect/lambdas/python/common/cc_common/license_util.py:18-37
Timestamp: 2025-06-18T05:57:18.225Z
Learning: In the `get_license_type_by_abbreviation` method in `license_util.py`, KeyError exceptions from invalid compact codes are intentionally caught and re-raised as CCInvalidRequestException with `from e` to provide a consistent interface between invalid compact and invalid abbreviation scenarios, while preserving the original exception information in the chain.
🧬 Code Graph Analysis (2)
backend/compact-connect/lambdas/python/purchases/purchase_client.py (1)
backend/compact-connect/lambdas/python/common/cc_common/exceptions.py (1)
  • CCInvalidRequestException (7-8)
backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py (2)
backend/compact-connect/lambdas/python/purchases/purchase_client.py (2)
  • PurchaseClient (888-1080)
  • process_charge_for_licensee_privileges (931-963)
backend/compact-connect/lambdas/python/common/cc_common/exceptions.py (1)
  • CCInvalidRequestException (7-8)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: TestPython
🔇 Additional comments (3)
backend/compact-connect/lambdas/python/purchases/purchase_client.py (2)

33-36: LGTM! Good documentation of the E00114 error code addition.

The updated comment clearly explains the purpose of adding E00114 for suspicious activity filter rejections and provides a helpful reference link.


259-267: Excellent implementation of specific E00114 error handling.

The implementation correctly:

  • Checks for the specific E00114 error code
  • Raises CCInvalidRequestException for appropriate 400 response
  • Provides user-friendly message with retry guidance as recommended by Authorize.net
  • Includes helpful context linking to the related GitHub issue

This aligns perfectly with the PR objectives to handle suspicious activity filter rejections gracefully.

backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py (1)

681-711: Excellent test coverage for E00114 error handling.

The test properly verifies:

  • CCInvalidRequestException is raised for E00114 errors
  • The specific user-friendly message is returned
  • Integration with the PurchaseClient.process_charge_for_licensee_privileges method

The test structure follows existing patterns and provides good coverage for the new error handling logic.

@landonshumway-ia landonshumway-ia requested a review from jusdino July 2, 2025 21:38
Copy link
Collaborator

@jusdino jusdino left a comment

Choose a reason for hiding this comment

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

Great!

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.

Investigate 5xx error when suspicious activity filter denies requests
2 participants