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

feat(router): add v2 endpoint retrieve payment filters based on merchant profile #7171

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

aniketburman014
Copy link

@aniketburman014 aniketburman014 commented Feb 3, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Added the v2/payments/v2/filter API to retrieve available payment filters (connectors, statuses, payment methods, authentication types, etc.) for merchant profile.

This pr closes the issue #7193.

Key Changes

1. `get_payment_filters` -> `crates/router/src/routes/payments.rs`
   - Integrates the new API with authentication via API keys & JWT (`ProfilePaymentRead` permission).
   - Supports profile-based filtering for merchants.
   
2. `get_payment_filters` -> `crates/router/src/core/payments.rs`
   - Retrieves available payment filters, including:
     - Connectors
     - Currencies
     - Statuses
     - Payment methods
     - Authentication types
     - Card networks
   - Calls list_payment_connectors to fetch merchant-specific connectors (using both profile_id and merchant_id), applying profile-based filtering to return only the relevant connectors and payment methods available for the given profile and merchant combination.
   - Constructs and returns a structured response (`PaymentListFiltersV2`).

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Links to the files with corresponding changes.

  1. crates/router/src/core/payments.rs
  2. crates/router/src/routes/app.rs
  3. crates/router/src/routes/payments.rs

Motivation and Context

How did you test it?

  • Using Postman
Screenshot 2025-02-03 at 5 49 09 PM
  • Curl Request Example
curl --location 'http://localhost:8080/v2/payments/v2/filter' \
--header 'X-Profile-Id: pro_68rBAUSCoq91kQ870GFR' \
--header 'X-Merchant-Id: cloth_seller_cnwkRpdOSnP0vLY1lhGb' \
--header 'api-key: dev_elV1dBHRfYgbT09Q3R914ZOZzKCsJFjMJRot4TUcByFCYDseSZHTrZbCJuBX6ZHO'

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@aniketburman014 aniketburman014 added the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 3, 2025
@aniketburman014 aniketburman014 self-assigned this Feb 3, 2025
@aniketburman014 aniketburman014 requested review from a team as code owners February 3, 2025 13:04
Copy link

semanticdiff-com bot commented Feb 3, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/routes/app.rs  57% smaller
  crates/router/src/routes/payments.rs  12% smaller
  crates/router/src/core/payments.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 3, 2025
return Err(errors::ApiErrorResponse::InternalServerError.into());
};

let mut connector_map: HashMap<String, Vec<MerchantConnectorInfo>> = HashMap::new();
Copy link
Member

Choose a reason for hiding this comment

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

can you use this function

pub fn from_payment_connectors_list(payment_connectors: Vec<MerchantConnectorAccount>) -> Self {

Copy link
Member

Choose a reason for hiding this comment

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

And once you receive the flattened list, you can construct a hashmap from that

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.

2 participants