Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(core): fix mandate_details to store some value only if mandate_data struct is present (#3525)

Amisha Prabhat78fdad218ca3
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index e08dbc61f5..5797fd60da 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -1823,7 +1823,6 @@ pub async fn list_payment_methods(
} else {
api_surcharge_decision_configs::MerchantSurchargeConfigs::default()
};
- print!("PAMT{:?}", payment_attempt);
Ok(services::ApplicationResponse::Json(
api::PaymentMethodListResponse {
redirect_url: merchant_account.return_url,
@@ -2070,13 +2069,30 @@ pub async fn filter_payment_methods(
})?;
let filter7 = payment_attempt
.and_then(|attempt| attempt.mandate_details.as_ref())
- .map(|_mandate_details| {
- filter_pm_based_on_supported_payments_for_mandate(
- supported_payment_methods_for_mandate,
- &payment_method,
- &payment_method_object.payment_method_type,
- connector_variant,
- )
+ .map(|mandate_details| {
+ let (mandate_type_present, update_mandate_id_present) =
+ match mandate_details {
+ data_models::mandates::MandateTypeDetails::MandateType(_) => {
+ (true, false)
+ }
+ data_models::mandates::MandateTypeDetails::MandateDetails(
+ mand_details,
+ ) => (
+ mand_details.mandate_type.is_some(),
+ mand_details.update_mandate_id.is_some(),
+ ),
+ };
+
+ if mandate_type_present || update_mandate_id_present {
+ filter_pm_based_on_supported_payments_for_mandate(
+ supported_payment_methods_for_mandate,
+ &payment_method,
+ &payment_method_object.payment_method_type,
+ connector_variant,
+ )
+ } else {
+ true
+ }
})
.unwrap_or(true);
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 381f026597..378cbb2546 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -712,7 +712,9 @@ impl PaymentCreate {
Err(errors::ApiErrorResponse::InvalidRequestData {message:"Only one field out of 'mandate_type' and 'update_mandate_id' was expected, found both".to_string()})?
}
- let mandate_dets = if let Some(update_id) = request
+ let mandate_details = if request.mandate_data.is_none() {
+ None
+ } else if let Some(update_id) = request
.mandate_data
.as_ref()
.and_then(|inner| inner.update_mandate_id.clone())
@@ -723,8 +725,6 @@ impl PaymentCreate {
};
Some(MandateTypeDetails::MandateDetails(mandate_data))
} else {
- // let mandate_type: data_models::mandates::MandateDataType =
-
let mandate_data = MandateDetails {
update_mandate_id: None,
mandate_type: request
@@ -761,7 +761,7 @@ impl PaymentCreate {
business_sub_label: request.business_sub_label.clone(),
surcharge_amount,
tax_amount,
- mandate_details: mandate_dets,
+ mandate_details,
..storage::PaymentAttemptNew::default()
},
additional_pm_data,