feat(payment-methods): add filtering logic for payment method list v2 (#8606)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sakil Mostak
2025-08-05 12:38:37 +05:30
committed by GitHub
parent b91e6d954b
commit 2e137716b9
16 changed files with 616 additions and 187 deletions

View File

@ -6,10 +6,25 @@ use super::{
PaymentsCreateIntentRequest, PaymentsGetIntentRequest, PaymentsIntentResponse, PaymentsRequest,
};
#[cfg(feature = "v2")]
use crate::payment_methods::PaymentMethodListResponseForSession;
use crate::payment_methods::{
ListMethodsForPaymentMethodsRequest, PaymentMethodListResponseForSession,
};
use crate::{
payment_methods::{
self, ListCountriesCurrenciesRequest, ListCountriesCurrenciesResponse,
PaymentMethodCollectLinkRenderRequest, PaymentMethodCollectLinkRequest,
PaymentMethodCollectLinkResponse, PaymentMethodMigrateResponse, PaymentMethodResponse,
PaymentMethodUpdate,
},
payments::{
self, PaymentListConstraints, PaymentListFilters, PaymentListFiltersV2,
PaymentListResponse, PaymentsAggregateResponse, PaymentsSessionResponse,
RedirectionResponse,
},
};
#[cfg(feature = "v1")]
use crate::{
payment_methods::PaymentMethodListResponse,
payment_methods::{PaymentMethodListRequest, PaymentMethodListResponse},
payments::{
ExtendedCardInfoResponse, PaymentIdType, PaymentListFilterConstraints,
PaymentListResponseV2, PaymentsApproveRequest, PaymentsCancelRequest,
@ -22,19 +37,6 @@ use crate::{
PaymentsStartRequest, PaymentsUpdateMetadataRequest, PaymentsUpdateMetadataResponse,
},
};
use crate::{
payment_methods::{
self, ListCountriesCurrenciesRequest, ListCountriesCurrenciesResponse,
PaymentMethodCollectLinkRenderRequest, PaymentMethodCollectLinkRequest,
PaymentMethodCollectLinkResponse, PaymentMethodListRequest, PaymentMethodMigrateResponse,
PaymentMethodResponse, PaymentMethodUpdate,
},
payments::{
self, PaymentListConstraints, PaymentListFilters, PaymentListFiltersV2,
PaymentListResponse, PaymentsAggregateResponse, PaymentsSessionResponse,
RedirectionResponse,
},
};
#[cfg(feature = "v1")]
impl ApiEventMetric for PaymentsRetrieveRequest {
@ -305,6 +307,7 @@ impl ApiEventMetric for payment_methods::PaymentMethodDeleteResponse {
impl ApiEventMetric for payment_methods::CustomerPaymentMethodsListResponse {}
#[cfg(feature = "v1")]
impl ApiEventMetric for PaymentMethodListRequest {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::PaymentMethodList {
@ -317,6 +320,19 @@ impl ApiEventMetric for PaymentMethodListRequest {
}
}
#[cfg(feature = "v2")]
impl ApiEventMetric for ListMethodsForPaymentMethodsRequest {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::PaymentMethodList {
payment_id: self
.client_secret
.as_ref()
.and_then(|cs| cs.rsplit_once("_secret_"))
.map(|(pid, _)| pid.to_string()),
})
}
}
impl ApiEventMetric for ListCountriesCurrenciesRequest {}
impl ApiEventMetric for ListCountriesCurrenciesResponse {}

View File

@ -1778,7 +1778,7 @@ impl<'de> serde::Deserialize<'de> for PaymentMethodListRequest {
//List Payment Method
#[derive(Debug, Clone, serde::Serialize, Default, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodListRequest {
pub struct ListMethodsForPaymentMethodsRequest {
/// This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK
#[schema(max_length = 30, min_length = 30, example = "secret_k2uj3he2893eiu2d")]
pub client_secret: Option<String>,
@ -1809,7 +1809,7 @@ pub struct PaymentMethodListRequest {
}
#[cfg(feature = "v2")]
impl<'de> serde::Deserialize<'de> for PaymentMethodListRequest {
impl<'de> serde::Deserialize<'de> for ListMethodsForPaymentMethodsRequest {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
@ -1817,7 +1817,7 @@ impl<'de> serde::Deserialize<'de> for PaymentMethodListRequest {
struct FieldVisitor;
impl<'de> de::Visitor<'de> for FieldVisitor {
type Value = PaymentMethodListRequest;
type Value = ListMethodsForPaymentMethodsRequest;
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("Failed while deserializing as map")
@ -1827,7 +1827,7 @@ impl<'de> serde::Deserialize<'de> for PaymentMethodListRequest {
where
A: de::MapAccess<'de>,
{
let mut output = PaymentMethodListRequest::default();
let mut output = ListMethodsForPaymentMethodsRequest::default();
while let Some(key) = map.next_key()? {
match key {

View File

@ -26,6 +26,8 @@ use common_utils::{
pii::{self, Email},
types::{MinorUnit, StringMajorUnit},
};
#[cfg(feature = "v2")]
use deserialize_form_style_query_parameter::option_form_vec_deserialize;
use error_stack::ResultExt;
use masking::{PeekInterface, Secret, WithType};
use router_derive::Setter;
@ -7769,7 +7771,38 @@ pub enum SdkType {
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct PaymentMethodsListRequest {}
pub struct ListMethodsForPaymentsRequest {
/// This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK
#[schema(max_length = 30, min_length = 30, example = "secret_k2uj3he2893eiu2d")]
pub client_secret: Option<String>,
/// The two-letter ISO currency code
#[serde(deserialize_with = "option_form_vec_deserialize", default)]
#[schema(value_type = Option<Vec<CountryAlpha2>>, example = json!(["US", "UK", "IN"]))]
pub accepted_countries: Option<Vec<api_enums::CountryAlpha2>>,
/// Filter by amount
#[schema(example = 60)]
pub amount: Option<MinorUnit>,
/// The three-letter ISO currency code
#[serde(deserialize_with = "option_form_vec_deserialize", default)]
#[schema(value_type = Option<Vec<Currency>>,example = json!(["USD", "EUR"]))]
pub accepted_currencies: Option<Vec<api_enums::Currency>>,
/// Indicates whether the payment method supports recurring payments. Optional.
#[schema(example = true)]
pub recurring_enabled: Option<bool>,
/// Indicates whether the payment method is eligible for card networks
#[serde(deserialize_with = "option_form_vec_deserialize", default)]
#[schema(value_type = Option<Vec<CardNetwork>>, example = json!(["visa", "mastercard"]))]
pub card_networks: Option<Vec<api_enums::CardNetwork>>,
/// Indicates the limit of last used payment methods
#[schema(example = 1)]
pub limit: Option<i64>,
}
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, ToSchema)]
@ -7805,8 +7838,8 @@ pub struct ResponsePaymentMethodTypesForPayments {
/// Required fields for the payment_method_type.
/// This is the union of all the required fields for the payment method type enabled in all the connectors.
#[schema(value_type = Option<RequiredFieldInfo>)]
pub required_fields: Option<Vec<payment_methods::RequiredFieldInfo>>,
#[schema(value_type = RequiredFieldInfo)]
pub required_fields: Vec<payment_methods::RequiredFieldInfo>,
/// surcharge details for this payment method type if exists
#[schema(value_type = Option<SurchargeDetailsResponse>)]