Skip to content

Commit

Permalink
fix(core): fix mandate_details to store some value only if mandate_da…
Browse files Browse the repository at this point in the history
…ta struct is present (#3525)
  • Loading branch information
Aprabhat19 authored Feb 1, 2024
1 parent 13be7e6 commit 78fdad2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
32 changes: 24 additions & 8 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 78fdad2

Please sign in to comment.