feat(core): Make installment_payment_enabled,recurring_enabled Optional (#8201)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
awasthi21
2025-06-10 16:01:50 +05:30
committed by GitHub
parent e0ea1b4832
commit 171ca3b564
17 changed files with 149 additions and 120 deletions

View File

@ -131,6 +131,12 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
}
.into()
}
errors::ConnectorError::CaptureMethodNotSupported => {
errors::ApiErrorResponse::NotSupported {
message: "Capture Method Not Supported".to_owned(),
}
.into()
}
errors::ConnectorError::FailedToObtainIntegrationUrl
| errors::ConnectorError::RequestEncodingFailed
| errors::ConnectorError::RequestEncodingFailedWithReason(_)
@ -151,7 +157,6 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
| errors::ConnectorError::NoConnectorWalletDetails
| errors::ConnectorError::FailedToObtainCertificateKey
| errors::ConnectorError::FlowNotSupported { .. }
| errors::ConnectorError::CaptureMethodNotSupported
| errors::ConnectorError::MissingConnectorMandateID
| errors::ConnectorError::MissingConnectorMandateMetadata
| errors::ConnectorError::MissingConnectorTransactionID
@ -234,6 +239,11 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
errors::ConnectorError::InvalidDataFormat { field_name } => {
errors::ApiErrorResponse::InvalidDataValue { field_name }
},
errors::ConnectorError::CaptureMethodNotSupported => {
errors::ApiErrorResponse::NotSupported {
message: "Capture Method Not Supported".to_owned(),
}
}
errors::ConnectorError::InvalidWalletToken {wallet_name} => errors::ApiErrorResponse::InvalidWalletToken {wallet_name: wallet_name.to_string()},
errors::ConnectorError::CurrencyNotSupported { message, connector} => errors::ApiErrorResponse::CurrencyNotSupported { message: format!("Credentials for the currency {message} are not configured with the connector {connector}/hyperswitch") },
errors::ConnectorError::FailedToObtainAuthType => errors::ApiErrorResponse::InvalidConnectorConfiguration {config: "connector_account_details".to_string()},
@ -252,7 +262,6 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
errors::ConnectorError::FailedToObtainCertificate |
errors::ConnectorError::NoConnectorMetaData | errors::ConnectorError::NoConnectorWalletDetails |
errors::ConnectorError::FailedToObtainCertificateKey |
errors::ConnectorError::CaptureMethodNotSupported |
errors::ConnectorError::MissingConnectorMandateID |
errors::ConnectorError::MissingConnectorMandateMetadata |
errors::ConnectorError::MissingConnectorTransactionID |
@ -324,6 +333,11 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
wallet_name: wallet_name.to_string(),
}
}
errors::ConnectorError::CaptureMethodNotSupported => {
errors::ApiErrorResponse::NotSupported {
message: "Capture Method Not Supported".to_owned(),
}
}
errors::ConnectorError::RequestEncodingFailed
| errors::ConnectorError::RequestEncodingFailedWithReason(_)
| errors::ConnectorError::ParsingFailed
@ -343,7 +357,6 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
| errors::ConnectorError::NotImplemented(_)
| errors::ConnectorError::NotSupported { .. }
| errors::ConnectorError::FlowNotSupported { .. }
| errors::ConnectorError::CaptureMethodNotSupported
| errors::ConnectorError::MissingConnectorMandateID
| errors::ConnectorError::MissingConnectorMandateMetadata
| errors::ConnectorError::MissingConnectorTransactionID

View File

@ -254,8 +254,8 @@ impl PaymentMethodsController for PmCards<'_> {
card: None,
metadata: req.metadata.clone(),
created: Some(common_utils::date_time::now()),
recurring_enabled: false, //[#219]
installment_payment_enabled: false, //[#219]
recurring_enabled: Some(false), //[#219]
installment_payment_enabled: Some(false), //[#219]
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
last_used_at: Some(common_utils::date_time::now()),
client_secret: None,
@ -990,8 +990,8 @@ impl PaymentMethodsController for PmCards<'_> {
card,
metadata: pm.metadata,
created: Some(pm.created_at),
recurring_enabled: false,
installment_payment_enabled: false,
recurring_enabled: Some(false),
installment_payment_enabled: Some(false),
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
last_used_at: Some(pm.last_used_at),
client_secret: pm.client_secret,
@ -1889,8 +1889,8 @@ pub async fn update_customer_payment_method(
card: Some(existing_card_data),
metadata: pm.metadata,
created: Some(pm.created_at),
recurring_enabled: false,
installment_payment_enabled: false,
recurring_enabled: Some(false),
installment_payment_enabled: Some(false),
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
last_used_at: Some(common_utils::date_time::now()),
client_secret: pm.client_secret.clone(),
@ -4084,7 +4084,7 @@ fn filter_installment_based(
installment_payment_enabled: Option<bool>,
) -> bool {
installment_payment_enabled.map_or(true, |enabled| {
payment_method.installment_payment_enabled == enabled
payment_method.installment_payment_enabled == Some(enabled)
})
}
@ -4118,7 +4118,9 @@ fn filter_recurring_based(
payment_method: &RequestPaymentMethodTypes,
recurring_enabled: Option<bool>,
) -> bool {
recurring_enabled.map_or(true, |enabled| payment_method.recurring_enabled == enabled)
recurring_enabled.map_or(true, |enabled| {
payment_method.recurring_enabled == Some(enabled)
})
}
#[cfg(all(
@ -4359,7 +4361,7 @@ pub async fn list_customer_payment_method(
metadata: pm.metadata,
payment_method_issuer_code: pm.payment_method_issuer_code,
recurring_enabled: mca_enabled,
installment_payment_enabled: false,
installment_payment_enabled: Some(false),
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
created: Some(pm.created_at),
#[cfg(feature = "payouts")]
@ -4372,7 +4374,7 @@ pub async fn list_customer_payment_method(
&& customer.default_payment_method_id == Some(pm.payment_method_id),
billing: payment_method_billing,
};
if requires_cvv || mca_enabled {
if requires_cvv || mca_enabled.unwrap_or(false) {
customer_pms.push(pma.to_owned());
}
@ -4603,9 +4605,9 @@ pub async fn get_mca_status(
is_connector_agnostic_mit_enabled: bool,
connector_mandate_details: Option<CommonMandateReference>,
network_transaction_id: Option<&String>,
) -> errors::RouterResult<bool> {
) -> errors::RouterResult<Option<bool>> {
if is_connector_agnostic_mit_enabled && network_transaction_id.is_some() {
return Ok(true);
return Ok(Some(true));
}
if let Some(connector_mandate_details) = connector_mandate_details {
let mcas = state
@ -4621,14 +4623,14 @@ pub async fn get_mca_status(
id: merchant_id.get_string_repr().to_owned(),
})?;
return Ok(
return Ok(Some(
mcas.is_merchant_connector_account_id_in_connector_mandate_details(
profile_id.as_ref(),
&connector_mandate_details,
),
);
));
}
Ok(false)
Ok(Some(false))
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]

View File

@ -268,8 +268,8 @@ impl<'a> NetworkTokenizationBuilder<'a, CardTokenStored> {
payment_method: payment_method.payment_method,
payment_method_type: payment_method.payment_method_type,
card: card_detail_from_locker,
recurring_enabled: true,
installment_payment_enabled: false,
recurring_enabled: Some(true),
installment_payment_enabled: Some(false),
metadata: payment_method.metadata.clone(),
created: Some(payment_method.created_at),
last_used_at: Some(payment_method.last_used_at),

View File

@ -73,8 +73,8 @@ impl<'a> NetworkTokenizationBuilder<'a, TokenizeWithPmId> {
payment_method_id: payment_method.payment_method_id.clone(),
payment_method: payment_method.payment_method,
payment_method_type: payment_method.payment_method_type,
recurring_enabled: true,
installment_payment_enabled: false,
recurring_enabled: Some(true),
installment_payment_enabled: Some(false),
metadata: payment_method.metadata.clone(),
created: Some(payment_method.created_at),
last_used_at: Some(payment_method.last_used_at),
@ -227,8 +227,8 @@ impl<'a> NetworkTokenizationBuilder<'a, PmTokenStored> {
payment_method_id: payment_method.payment_method_id.clone(),
payment_method: payment_method.payment_method,
payment_method_type: payment_method.payment_method_type,
recurring_enabled: true,
installment_payment_enabled: false,
recurring_enabled: Some(true),
installment_payment_enabled: Some(false),
metadata: payment_method.metadata.clone(),
created: Some(payment_method.created_at),
last_used_at: Some(payment_method.last_used_at),

View File

@ -430,8 +430,8 @@ pub fn mk_add_bank_response_hs(
card: None,
metadata: req.metadata,
created: Some(common_utils::date_time::now()),
recurring_enabled: false, // [#256]
installment_payment_enabled: false, // #[#256]
recurring_enabled: Some(false), // [#256]
installment_payment_enabled: Some(false), // #[#256]
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
last_used_at: Some(common_utils::date_time::now()),
client_secret: None,
@ -493,8 +493,8 @@ pub fn mk_add_card_response_hs(
card: Some(card),
metadata: req.metadata,
created: Some(common_utils::date_time::now()),
recurring_enabled: false, // [#256]
installment_payment_enabled: false, // #[#256]
recurring_enabled: Some(false), // [#256]
installment_payment_enabled: Some(false), // #[#256]
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
last_used_at: Some(common_utils::date_time::now()), // [#256]
client_secret: req.client_secret,
@ -598,7 +598,7 @@ pub fn generate_payment_method_response(
payment_method_type: payment_method.get_payment_method_type(),
payment_method_subtype: payment_method.get_payment_method_subtype(),
created: Some(payment_method.created_at),
recurring_enabled: false,
recurring_enabled: Some(false),
last_used_at: Some(payment_method.last_used_at),
payment_method_data: pmd,
connector_tokens,
@ -1054,7 +1054,7 @@ impl transformers::ForeignTryFrom<domain::PaymentMethod> for PaymentMethodRespon
});
// TODO: check how we can get this field
let recurring_enabled = true;
let recurring_enabled = Some(true);
let psp_tokenization_enabled = item.connector_mandate_details.and_then(|details| {
details.payments.map(|payments| {

View File

@ -962,8 +962,8 @@ async fn skip_saving_card_in_locker(
payment_method: payment_method_request.payment_method,
payment_method_type: payment_method_request.payment_method_type,
card: Some(card_detail),
recurring_enabled: false,
installment_payment_enabled: false,
recurring_enabled: Some(false),
installment_payment_enabled: Some(false),
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
metadata: None,
created: Some(common_utils::date_time::now()),
@ -986,8 +986,8 @@ async fn skip_saving_card_in_locker(
card: None,
metadata: None,
created: Some(common_utils::date_time::now()),
recurring_enabled: false,
installment_payment_enabled: false,
recurring_enabled: Some(false),
installment_payment_enabled: Some(false),
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
#[cfg(feature = "payouts")]
bank_transfer: None,
@ -1053,8 +1053,8 @@ pub async fn save_in_locker(
card: None,
metadata: None,
created: Some(common_utils::date_time::now()),
recurring_enabled: false, //[#219]
installment_payment_enabled: false, //[#219]
recurring_enabled: Some(false),
installment_payment_enabled: Some(false),
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]), //[#219]
last_used_at: Some(common_utils::date_time::now()),
client_secret: None,

View File

@ -197,6 +197,7 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {
is_debit_routing_enabled: Some(item.is_debit_routing_enabled),
merchant_business_country: item.merchant_business_country,
is_pre_network_tokenization_enabled: item.is_pre_network_tokenization_enabled,
is_iframe_redirection_enabled: item.is_iframe_redirection_enabled,
})
}
}

View File

@ -103,8 +103,8 @@ impl
payment_method: item.get_payment_method_type(),
payment_method_type: item.get_payment_method_subtype(),
card: card_details,
recurring_enabled: false,
installment_payment_enabled: false,
recurring_enabled: Some(false),
installment_payment_enabled: Some(false),
payment_experience: None,
metadata: item.metadata,
created: Some(item.created_at),