Skip to content

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

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

Merged
merged 10 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 75 additions & 79 deletions api-reference/v2/openapi_spec_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -12587,6 +12587,78 @@
}
}
},
"ListMethodsForPaymentMethodsRequest": {
"type": "object",
"properties": {
"client_secret": {
"type": "string",
"description": "This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK",
"example": "secret_k2uj3he2893eiu2d",
"nullable": true,
"maxLength": 30,
"minLength": 30
},
"accepted_countries": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CountryAlpha2"
},
"description": "The two-letter ISO currency code",
"example": [
"US",
"UK",
"IN"
],
"nullable": true
},
"amount": {
"allOf": [
{
"$ref": "#/components/schemas/MinorUnit"
}
],
"nullable": true
},
"accepted_currencies": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Currency"
},
"description": "The three-letter ISO currency code",
"example": [
"USD",
"EUR"
],
"nullable": true
},
"recurring_enabled": {
"type": "boolean",
"description": "Indicates whether the payment method supports recurring payments. Optional.",
"example": true,
"nullable": true
},
"card_networks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CardNetwork"
},
"description": "Indicates whether the payment method is eligible for card netwotks",
"example": [
"visa",
"mastercard"
],
"nullable": true
},
"limit": {
"type": "integer",
"format": "int64",
"description": "Indicates the limit of last used payment methods",
"example": 1,
"nullable": true
}
},
"additionalProperties": false
},
"LocalBankTransferAdditionalData": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -17085,78 +17157,6 @@
}
]
},
"PaymentMethodListRequest": {
"type": "object",
"properties": {
"client_secret": {
"type": "string",
"description": "This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK",
"example": "secret_k2uj3he2893eiu2d",
"nullable": true,
"maxLength": 30,
"minLength": 30
},
"accepted_countries": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CountryAlpha2"
},
"description": "The two-letter ISO currency code",
"example": [
"US",
"UK",
"IN"
],
"nullable": true
},
"amount": {
"allOf": [
{
"$ref": "#/components/schemas/MinorUnit"
}
],
"nullable": true
},
"accepted_currencies": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Currency"
},
"description": "The three-letter ISO currency code",
"example": [
"USD",
"EUR"
],
"nullable": true
},
"recurring_enabled": {
"type": "boolean",
"description": "Indicates whether the payment method supports recurring payments. Optional.",
"example": true,
"nullable": true
},
"card_networks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CardNetwork"
},
"description": "Indicates whether the payment method is eligible for card netwotks",
"example": [
"visa",
"mastercard"
],
"nullable": true
},
"limit": {
"type": "integer",
"format": "int64",
"description": "Indicates the limit of last used payment methods",
"example": 1,
"nullable": true
}
},
"additionalProperties": false
},
"PaymentMethodListResponseForPayments": {
"type": "object",
"required": [
Expand Down Expand Up @@ -22358,7 +22358,8 @@
"type": "object",
"required": [
"payment_method_type",
"payment_method_subtype"
"payment_method_subtype",
"required_fields"
],
"properties": {
"payment_method_type": {
Expand All @@ -22376,12 +22377,7 @@
"nullable": true
},
"required_fields": {
"allOf": [
{
"$ref": "#/components/schemas/RequiredFieldInfo"
}
],
"nullable": true
"$ref": "#/components/schemas/RequiredFieldInfo"
},
"surcharge_details": {
"allOf": [
Expand Down
22 changes: 11 additions & 11 deletions config/payment_required_fields_v2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2139,19 +2139,19 @@ non_mandate = []
# Payment method type: Sepa
[required_fields.bank_debit.sepa.fields.Stripe]
common = [
{ required_field = "payment_method_data.billing.address.first_name", display_name = "billing_address_first_name", field_type = "text" },
{ required_field = "payment_method_data.billing.address.last_name", display_name = "billing_address_last_name", field_type = "text" },
{ required_field = "payment_method_data.bank_debit.sepa.iban", display_name = "iban", field_type = "text" },
{ required_field = "email", display_name = "email", field_type = "text" }
{ required_field = "payment_method_data.billing.address.first_name", display_name = "owner_name", field_type = "user_billing_name" },
{ required_field = "payment_method_data.billing.address.last_name", display_name = "owner_name", field_type = "user_billing_name" },
{ required_field = "payment_method_data.bank_debit.sepa_bank_debit.iban", display_name = "iban", field_type = "user_iban" },
{ required_field = "email", display_name = "email", field_type = "user_iban" }
]
mandate = []
non_mandate = []

[required_fields.bank_debit.sepa.fields.Adyen]
common = [
{ required_field = "payment_method_data.billing.address.first_name", display_name = "billing_address_first_name", field_type = "text" },
{ required_field = "payment_method_data.billing.address.last_name", display_name = "billing_address_last_name", field_type = "text" },
{ required_field = "payment_method_data.bank_debit.sepa.iban", display_name = "iban", field_type = "text" }
{ required_field = "payment_method_data.billing.address.first_name", display_name = "owner_name", field_type = "user_billing_name" },
{ required_field = "payment_method_data.billing.address.last_name", display_name = "owner_name", field_type = "user_billing_name" },
{ required_field = "payment_method_data.bank_debit.sepa_bank_debit.iban", display_name = "iban", field_type = "user_iban" }
]
mandate = []
non_mandate = []
Expand Down Expand Up @@ -2210,10 +2210,10 @@ non_mandate = []

[required_fields.bank_debit.becs.fields.Adyen]
common = [
{ required_field = "payment_method_data.billing.address.first_name", display_name = "billing_address_first_name", field_type = "text" },
{ required_field = "payment_method_data.billing.address.last_name", display_name = "billing_address_last_name", field_type = "text" },
{ required_field = "payment_method_data.bank_debit.becs.account_number", display_name = "account_number", field_type = "text" },
{ required_field = "payment_method_data.bank_debit.bacs.sort_code", display_name = "sort_code", field_type = "text" } # Corrected from becs.sort_code as per V1
{ required_field = "payment_method_data.billing.address.first_name", display_name = "owner_name", field_type = "user_billing_name" },
{ required_field = "payment_method_data.billing.address.last_name", display_name = "owner_name", field_type = "user_billing_name" },
{ required_field = "ppayment_method_data.bank_debit.becs_bank_debit.account_number", display_name = "bank_account_number", field_type = "user_bank_account_number" },
{ required_field = "payment_method_data.bank_debit.becs_bank_debit.sort_code", display_name = "bank_sort_code", field_type = "user_bank_sort_code" } # Corrected from becs.sort_code as per V1
]
mandate = []
non_mandate = []
Expand Down
1 change: 1 addition & 0 deletions crates/api_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ time = { version = "0.3.41", features = ["serde", "serde-well-known", "std"] }
url = { version = "2.5.4", features = ["serde"] }
utoipa = { version = "4.2.3", features = ["preserve_order", "preserve_path_order"] }
nutype = { version = "0.4.3", features = ["serde"] }
deserialize_form_style_query_parameter = "0.2.2"

# First party crates
cards = { version = "0.1.0", path = "../cards" }
Expand Down
46 changes: 31 additions & 15 deletions crates/api_models/src/events/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {}
Expand Down
8 changes: 4 additions & 4 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -1809,15 +1809,15 @@ 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>,
{
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")
Expand All @@ -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 {
Expand Down
Loading
Loading