refactor(router): Remove payment_methods_v2 and customer_v2 feature flag (#8236)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Prasunna Soppa
2025-06-12 00:07:24 +05:30
committed by GitHub
parent 6ea2e2a6f4
commit 000aa23c10
106 changed files with 896 additions and 1856 deletions

View File

@ -1,5 +1,5 @@
use std::collections::{HashMap, HashSet};
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
use std::str::FromStr;
use cards::CardNumber;
@ -16,7 +16,7 @@ use masking::PeekInterface;
use serde::de;
use utoipa::{schema, ToSchema};
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
#[cfg(feature = "v1")]
use crate::customers;
#[cfg(feature = "payouts")]
use crate::payouts;
@ -25,10 +25,7 @@ use crate::{
payments::{self, BankCodeResponse},
};
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodCreate {
@ -105,7 +102,7 @@ pub struct PaymentMethodCreate {
pub network_transaction_id: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodCreate {
@ -146,7 +143,7 @@ pub struct PaymentMethodCreate {
pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodIntentCreate {
@ -168,7 +165,7 @@ pub struct PaymentMethodIntentCreate {
pub customer_id: id_type::GlobalCustomerId,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodIntentConfirm {
@ -188,7 +185,7 @@ pub struct PaymentMethodIntentConfirm {
pub payment_method_subtype: api_enums::PaymentMethodType,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl PaymentMethodIntentConfirm {
pub fn validate_payment_method_data_against_payment_method(
payment_method_type: api_enums::PaymentMethod,
@ -204,14 +201,14 @@ impl PaymentMethodIntentConfirm {
}
/// This struct is used internally only
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct PaymentMethodIntentConfirmInternal {
pub id: id_type::GlobalPaymentMethodId,
pub request: PaymentMethodIntentConfirm,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl From<PaymentMethodIntentConfirmInternal> for PaymentMethodIntentConfirm {
fn from(item: PaymentMethodIntentConfirmInternal) -> Self {
item.request
@ -388,10 +385,7 @@ where
}))
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
impl PaymentMethodCreate {
pub fn get_payment_method_create_from_payment_method_migrate(
card_number: CardNumber,
@ -440,7 +434,7 @@ impl PaymentMethodCreate {
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl PaymentMethodCreate {
pub fn validate_payment_method_data_against_payment_method(
payment_method_type: api_enums::PaymentMethod,
@ -464,10 +458,7 @@ impl PaymentMethodCreate {
}
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodUpdate {
@ -484,7 +475,7 @@ pub struct PaymentMethodUpdate {
pub client_secret: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodUpdate {
@ -495,7 +486,7 @@ pub struct PaymentMethodUpdate {
pub connector_token_details: Option<ConnectorTokenDetails>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
@ -504,7 +495,7 @@ pub enum PaymentMethodUpdateData {
Card(CardDetailUpdate),
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
@ -513,10 +504,7 @@ pub enum PaymentMethodCreateData {
Card(CardDetail),
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
@ -525,10 +513,7 @@ pub enum PaymentMethodCreateData {
Card(CardDetail),
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetail {
@ -588,7 +573,7 @@ pub enum CardType {
// but when vaulting the card, we do not need cvc to be collected from the user
// This is because, the vaulted payment method can be used for future transactions in the presence of the customer
// when the customer is on_session again, the cvc can be collected from the customer
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetail {
@ -716,10 +701,7 @@ pub struct MigrateNetworkTokenDetail {
pub network_token_requestor_ref_id: String,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetailUpdate {
@ -740,10 +722,7 @@ pub struct CardDetailUpdate {
pub nick_name: Option<masking::Secret<String>>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
impl CardDetailUpdate {
pub fn apply(&self, card_data_from_locker: Card) -> CardDetail {
CardDetail {
@ -772,7 +751,7 @@ impl CardDetailUpdate {
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetailUpdate {
@ -785,7 +764,7 @@ pub struct CardDetailUpdate {
pub nick_name: Option<masking::Secret<String>>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl CardDetailUpdate {
pub fn apply(&self, card_data_from_locker: Card) -> CardDetail {
CardDetail {
@ -809,7 +788,7 @@ impl CardDetailUpdate {
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
@ -818,10 +797,7 @@ pub enum PaymentMethodResponseData {
Card(CardDetailFromLocker),
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct PaymentMethodResponse {
/// Unique identifier for a merchant
@ -883,7 +859,7 @@ pub struct PaymentMethodResponse {
pub client_secret: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema, Clone)]
pub struct ConnectorTokenDetails {
/// The unique identifier of the connector account through which the token was generated
@ -913,7 +889,8 @@ pub struct ConnectorTokenDetails {
/// The value of the connector token. This token can be used to make merchant initiated payments ( MIT ), directly with the connector.
pub token: masking::Secret<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, serde::Deserialize, ToSchema, Clone)]
pub struct PaymentMethodResponse {
/// The unique identifier of the Payment method
@ -1090,10 +1067,7 @@ pub struct Card {
pub nick_name: Option<String>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct CardDetailFromLocker {
pub scheme: Option<String>,
@ -1130,7 +1104,7 @@ pub struct CardDetailFromLocker {
pub saved_to_locker: bool,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct CardDetailFromLocker {
#[schema(value_type = Option<CountryAlpha2>)]
@ -1164,7 +1138,7 @@ pub struct CardDetailFromLocker {
pub saved_to_locker: bool,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct NetworkTokenResponse {
pub payment_method_data: NetworkTokenDetailsPaymentMethod,
@ -1174,10 +1148,7 @@ fn saved_in_locker_default() -> bool {
true
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
impl From<CardDetailFromLocker> for payments::AdditionalCardInfo {
fn from(item: CardDetailFromLocker) -> Self {
Self {
@ -1200,7 +1171,7 @@ impl From<CardDetailFromLocker> for payments::AdditionalCardInfo {
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl From<CardDetailFromLocker> for payments::AdditionalCardInfo {
fn from(item: CardDetailFromLocker) -> Self {
Self {
@ -1233,10 +1204,7 @@ pub struct PaymentMethodListResponseForSession {
pub customer_payment_methods: Vec<CustomerPaymentMethodResponseItem>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
impl From<CardDetailsPaymentMethod> for CardDetailFromLocker {
fn from(item: CardDetailsPaymentMethod) -> Self {
Self {
@ -1259,7 +1227,7 @@ impl From<CardDetailsPaymentMethod> for CardDetailFromLocker {
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl From<CardDetailsPaymentMethod> for CardDetailFromLocker {
fn from(item: CardDetailsPaymentMethod) -> Self {
Self {
@ -1286,7 +1254,7 @@ impl From<CardDetailsPaymentMethod> for CardDetailFromLocker {
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl From<CardDetail> for CardDetailFromLocker {
fn from(item: CardDetail) -> Self {
Self {
@ -1307,7 +1275,7 @@ impl From<CardDetail> for CardDetailFromLocker {
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl From<CardDetail> for CardDetailsPaymentMethod {
fn from(item: CardDetail) -> Self {
Self {
@ -1327,10 +1295,7 @@ impl From<CardDetail> for CardDetailsPaymentMethod {
}
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
impl From<(CardDetailFromLocker, Option<&CoBadgedCardData>)> for CardDetailsPaymentMethod {
fn from(
(item, co_badged_card_data): (CardDetailFromLocker, Option<&CoBadgedCardData>),
@ -1352,7 +1317,7 @@ impl From<(CardDetailFromLocker, Option<&CoBadgedCardData>)> for CardDetailsPaym
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl From<CardDetailFromLocker> for CardDetailsPaymentMethod {
fn from(item: CardDetailFromLocker) -> Self {
Self {
@ -1402,10 +1367,7 @@ pub struct BankDebitTypes {
pub eligible_connectors: Vec<String>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, Clone, serde::Serialize, ToSchema, PartialEq)]
pub struct ResponsePaymentMethodTypes {
/// The payment method type enabled
@ -1437,7 +1399,7 @@ pub struct ResponsePaymentMethodTypes {
pub pm_auth_connector: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, ToSchema, PartialEq)]
#[serde(untagged)] // Untagged used for serialization only
pub enum PaymentMethodSubtypeSpecificData {
@ -1449,7 +1411,7 @@ pub enum PaymentMethodSubtypeSpecificData {
Bank { bank_names: Vec<BankCodeResponse> },
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, ToSchema, PartialEq)]
pub struct ResponsePaymentMethodTypes {
/// The payment method type enabled
@ -1627,10 +1589,7 @@ impl RequestPaymentMethodTypes {
}
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
//List Payment Method
#[derive(Debug, Clone, serde::Serialize, Default, ToSchema)]
#[serde(deny_unknown_fields)]
@ -1668,10 +1627,7 @@ pub struct PaymentMethodListRequest {
pub limit: Option<i64>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
impl<'de> serde::Deserialize<'de> for PaymentMethodListRequest {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@ -1753,7 +1709,7 @@ impl<'de> serde::Deserialize<'de> for PaymentMethodListRequest {
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
//List Payment Method
#[derive(Debug, Clone, serde::Serialize, Default, ToSchema)]
#[serde(deny_unknown_fields)]
@ -1787,7 +1743,7 @@ pub struct PaymentMethodListRequest {
pub limit: Option<i64>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl<'de> serde::Deserialize<'de> for PaymentMethodListRequest {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@ -1918,10 +1874,7 @@ pub struct PaymentMethodListResponse {
pub is_tax_calculation_enabled: bool,
}
#[cfg(all(
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethodsListResponse {
/// List of payment methods for customer
@ -1931,14 +1884,14 @@ pub struct CustomerPaymentMethodsListResponse {
}
// OLAP PML Response
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethodsListResponse {
/// List of payment methods for customer
pub customer_payment_methods: Vec<PaymentMethodResponseItem>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct GetTokenDataRequest {
@ -1946,10 +1899,10 @@ pub struct GetTokenDataRequest {
pub token_type: api_enums::TokenDataType,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl common_utils::events::ApiEventMetric for GetTokenDataRequest {}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct TokenDataResponse {
/// The unique identifier of the payment method.
@ -1964,17 +1917,17 @@ pub struct TokenDataResponse {
pub token_details: TokenDetailsResponse,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl common_utils::events::ApiEventMetric for TokenDataResponse {}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, ToSchema)]
#[serde(untagged)]
pub enum TokenDetailsResponse {
NetworkTokenDetails(NetworkTokenDetailsResponse),
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct NetworkTokenDetailsResponse {
/// Network token generated against the Card Number
@ -2022,20 +1975,17 @@ pub struct NetworkTokenDetailsResponse {
pub eci: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct TotalPaymentMethodCountResponse {
/// total count of payment methods under the merchant
pub total_count: i64,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
impl common_utils::events::ApiEventMetric for TotalPaymentMethodCountResponse {}
#[cfg(all(
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct PaymentMethodDeleteResponse {
/// The unique identifier of the Payment method
@ -2047,7 +1997,7 @@ pub struct PaymentMethodDeleteResponse {
pub deleted: bool,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct PaymentMethodDeleteResponse {
/// The unique identifier of the Payment method
@ -2072,7 +2022,7 @@ pub struct CustomerDefaultPaymentMethodResponse {
pub payment_method_type: Option<api_enums::PaymentMethodType>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
pub struct PaymentMethodResponseItem {
/// The unique identifier of the payment method.
@ -2137,7 +2087,7 @@ pub struct PaymentMethodResponseItem {
pub psp_tokenization_enabled: bool,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethodResponseItem {
/// The unique identifier of the payment method.
@ -2199,7 +2149,7 @@ pub struct CustomerPaymentMethodResponseItem {
pub billing: Option<payments::Address>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum PaymentMethodListData {
@ -2209,10 +2159,7 @@ pub enum PaymentMethodListData {
Bank(payouts::Bank),
}
#[cfg(all(
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethod {
/// Token for payment method in temporary card locker which gets refreshed often
@ -2590,19 +2537,13 @@ pub enum MigrationStatus {
Failed,
}
#[cfg(all(
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
type PaymentMethodMigrationResponseType = (
Result<PaymentMethodMigrateResponse, String>,
PaymentMethodRecord,
);
#[cfg(all(
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_v2")
))]
#[cfg(feature = "v1")]
impl From<PaymentMethodMigrationResponseType> for PaymentMethodMigrationResponse {
fn from((response, record): PaymentMethodMigrationResponseType) -> Self {
match response {
@ -2736,7 +2677,7 @@ impl
}
}
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
#[cfg(feature = "v1")]
impl From<(PaymentMethodRecord, id_type::MerchantId)> for customers::CustomerRequest {
fn from(value: (PaymentMethodRecord, id_type::MerchantId)) -> Self {
let (record, merchant_id) = value;