Skip to content

Commit 3507ad6

Browse files
fix(core): return surcharge in payment method list response if passed in create request (#3363)
Co-authored-by: Narayan Bhat <[email protected]>
1 parent 7777710 commit 3507ad6

File tree

4 files changed

+249
-197
lines changed

4 files changed

+249
-197
lines changed

crates/router/src/connector/cybersource/transformers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,9 +2015,9 @@ impl<F>
20152015
resource_id: types::ResponseId::NoResponseId,
20162016
redirection_data,
20172017
mandate_reference: None,
2018-
connector_metadata: Some(
2019-
serde_json::json!({"three_ds_data":three_ds_data}),
2020-
),
2018+
connector_metadata: Some(serde_json::json!({
2019+
"three_ds_data": three_ds_data
2020+
})),
20212021
network_txn_id: None,
20222022
connector_response_reference_id,
20232023
incremental_authorization_allowed: None,

crates/router/src/core/payment_methods/cards.rs

Lines changed: 71 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,49 +1864,45 @@ pub async fn call_surcharge_decision_management(
18641864
billing_address: Option<domain::Address>,
18651865
response_payment_method_types: &mut [ResponsePaymentMethodsEnabled],
18661866
) -> errors::RouterResult<api_surcharge_decision_configs::MerchantSurchargeConfigs> {
1867-
if payment_attempt.surcharge_amount.is_some() {
1868-
Ok(api_surcharge_decision_configs::MerchantSurchargeConfigs::default())
1869-
} else {
1870-
let algorithm_ref: routing_types::RoutingAlgorithmRef = merchant_account
1871-
.routing_algorithm
1872-
.clone()
1873-
.map(|val| val.parse_value("routing algorithm"))
1874-
.transpose()
1875-
.change_context(errors::ApiErrorResponse::InternalServerError)
1876-
.attach_printable("Could not decode the routing algorithm")?
1877-
.unwrap_or_default();
1878-
let (surcharge_results, merchant_sucharge_configs) =
1879-
perform_surcharge_decision_management_for_payment_method_list(
1880-
&state,
1881-
algorithm_ref,
1882-
payment_attempt,
1883-
&payment_intent,
1884-
billing_address.as_ref().map(Into::into),
1885-
response_payment_method_types,
1867+
let algorithm_ref: routing_types::RoutingAlgorithmRef = merchant_account
1868+
.routing_algorithm
1869+
.clone()
1870+
.map(|val| val.parse_value("routing algorithm"))
1871+
.transpose()
1872+
.change_context(errors::ApiErrorResponse::InternalServerError)
1873+
.attach_printable("Could not decode the routing algorithm")?
1874+
.unwrap_or_default();
1875+
let (surcharge_results, merchant_sucharge_configs) =
1876+
perform_surcharge_decision_management_for_payment_method_list(
1877+
&state,
1878+
algorithm_ref,
1879+
payment_attempt,
1880+
&payment_intent,
1881+
billing_address.as_ref().map(Into::into),
1882+
response_payment_method_types,
1883+
)
1884+
.await
1885+
.change_context(errors::ApiErrorResponse::InternalServerError)
1886+
.attach_printable("error performing surcharge decision operation")?;
1887+
if !surcharge_results.is_empty_result() {
1888+
surcharge_results
1889+
.persist_individual_surcharge_details_in_redis(&state, business_profile)
1890+
.await?;
1891+
let _ = state
1892+
.store
1893+
.update_payment_intent(
1894+
payment_intent,
1895+
storage::PaymentIntentUpdate::SurchargeApplicableUpdate {
1896+
surcharge_applicable: true,
1897+
updated_by: merchant_account.storage_scheme.to_string(),
1898+
},
1899+
merchant_account.storage_scheme,
18861900
)
18871901
.await
1888-
.change_context(errors::ApiErrorResponse::InternalServerError)
1889-
.attach_printable("error performing surcharge decision operation")?;
1890-
if !surcharge_results.is_empty_result() {
1891-
surcharge_results
1892-
.persist_individual_surcharge_details_in_redis(&state, business_profile)
1893-
.await?;
1894-
let _ = state
1895-
.store
1896-
.update_payment_intent(
1897-
payment_intent,
1898-
storage::PaymentIntentUpdate::SurchargeApplicableUpdate {
1899-
surcharge_applicable: true,
1900-
updated_by: merchant_account.storage_scheme.to_string(),
1901-
},
1902-
merchant_account.storage_scheme,
1903-
)
1904-
.await
1905-
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
1906-
.attach_printable("Failed to update surcharge_applicable in Payment Intent");
1907-
}
1908-
Ok(merchant_sucharge_configs)
1902+
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
1903+
.attach_printable("Failed to update surcharge_applicable in Payment Intent");
19091904
}
1905+
Ok(merchant_sucharge_configs)
19101906
}
19111907

19121908
pub async fn call_surcharge_decision_management_for_saved_card(
@@ -1917,47 +1913,43 @@ pub async fn call_surcharge_decision_management_for_saved_card(
19171913
payment_intent: storage::PaymentIntent,
19181914
customer_payment_method_response: &mut api::CustomerPaymentMethodsListResponse,
19191915
) -> errors::RouterResult<()> {
1920-
if payment_attempt.surcharge_amount.is_some() {
1921-
Ok(())
1922-
} else {
1923-
let algorithm_ref: routing_types::RoutingAlgorithmRef = merchant_account
1924-
.routing_algorithm
1925-
.clone()
1926-
.map(|val| val.parse_value("routing algorithm"))
1927-
.transpose()
1928-
.change_context(errors::ApiErrorResponse::InternalServerError)
1929-
.attach_printable("Could not decode the routing algorithm")?
1930-
.unwrap_or_default();
1931-
let surcharge_results = perform_surcharge_decision_management_for_saved_cards(
1932-
state,
1933-
algorithm_ref,
1934-
payment_attempt,
1935-
&payment_intent,
1936-
&mut customer_payment_method_response.customer_payment_methods,
1937-
)
1938-
.await
1916+
let algorithm_ref: routing_types::RoutingAlgorithmRef = merchant_account
1917+
.routing_algorithm
1918+
.clone()
1919+
.map(|val| val.parse_value("routing algorithm"))
1920+
.transpose()
19391921
.change_context(errors::ApiErrorResponse::InternalServerError)
1940-
.attach_printable("error performing surcharge decision operation")?;
1941-
if !surcharge_results.is_empty_result() {
1942-
surcharge_results
1943-
.persist_individual_surcharge_details_in_redis(state, business_profile)
1944-
.await?;
1945-
let _ = state
1946-
.store
1947-
.update_payment_intent(
1948-
payment_intent,
1949-
storage::PaymentIntentUpdate::SurchargeApplicableUpdate {
1950-
surcharge_applicable: true,
1951-
updated_by: merchant_account.storage_scheme.to_string(),
1952-
},
1953-
merchant_account.storage_scheme,
1954-
)
1955-
.await
1956-
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
1957-
.attach_printable("Failed to update surcharge_applicable in Payment Intent");
1958-
}
1959-
Ok(())
1922+
.attach_printable("Could not decode the routing algorithm")?
1923+
.unwrap_or_default();
1924+
let surcharge_results = perform_surcharge_decision_management_for_saved_cards(
1925+
state,
1926+
algorithm_ref,
1927+
payment_attempt,
1928+
&payment_intent,
1929+
&mut customer_payment_method_response.customer_payment_methods,
1930+
)
1931+
.await
1932+
.change_context(errors::ApiErrorResponse::InternalServerError)
1933+
.attach_printable("error performing surcharge decision operation")?;
1934+
if !surcharge_results.is_empty_result() {
1935+
surcharge_results
1936+
.persist_individual_surcharge_details_in_redis(state, business_profile)
1937+
.await?;
1938+
let _ = state
1939+
.store
1940+
.update_payment_intent(
1941+
payment_intent,
1942+
storage::PaymentIntentUpdate::SurchargeApplicableUpdate {
1943+
surcharge_applicable: true,
1944+
updated_by: merchant_account.storage_scheme.to_string(),
1945+
},
1946+
merchant_account.storage_scheme,
1947+
)
1948+
.await
1949+
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
1950+
.attach_printable("Failed to update surcharge_applicable in Payment Intent");
19601951
}
1952+
Ok(())
19611953
}
19621954

19631955
#[allow(clippy::too_many_arguments)]

0 commit comments

Comments
 (0)