Repository: juspay/hyperswitch
File: crates/router/src/core/payments/operations/payment_response.rs (Rust)

Code before:
    key_store: &domain::MerchantKeyStore,
    storage_scheme: enums::MerchantStorageScheme,
    locale: &Option<String>,
    #[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connectors: Vec<
        RoutableConnectorChoice,
    >,
    #[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
) -> RouterResult<PaymentData<F>> {
    // Update additional payment data with the payment method response that we received from connector
    // This is for details like whether 3ds was upgraded and which version of 3ds was used
    // also some connectors might send card network details in the response, which is captured and stored

    let additional_payment_data = payment_data.payment_attempt.get_payment_method_data();

    // Helper closure for updating the additional_payment_data with connector response
    let update_pm_data = || {
        update_additional_payment_data_with_connector_response_pm_data(
            payment_data.payment_attempt.payment_method_data.clone(),
            router_data
                .connector_response
                .as_ref()
                .and_then(|connector_response| {
                    connector_response.additional_payment_method_data.clone()
                }),
        )
        .ok()
        .flatten()
    };

    let additional_payment_method_data = match payment_data.payment_method_data.clone() {
        Some(hyperswitch_domain_models::payment_method_data::PaymentMethodData::NetworkToken(_))
        | Some(hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardDetailsForNetworkTransactionId(_)) => {
            payment_data.payment_attempt.payment_method_data.clone()
        }
        _ => additional_payment_data.and_then(|_| update_pm_data()),
    };

    router_data.payment_method_status.and_then(|status| {
        payment_data
            .payment_method_info
            .as_mut()
            .map(|info| info.status = status)
    });
    payment_data.whole_connector_response = router_data.raw_connector_response.clone();

    // TODO: refactor of gsm_error_category with respective feature flag
    #[allow(unused_variables)]
    let (capture_update, mut payment_attempt_update, gsm_error_category) = match router_data
        .response
        .clone()
    {

Review comment (bug):
Why are we ignoring the failure here? Shouldn't we propogate this? If this needs to be supressed it would be good if you log the error without ignoring it completely

Code after:
    key_store: &domain::MerchantKeyStore,
    storage_scheme: enums::MerchantStorageScheme,
    locale: &Option<String>,
    #[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connectors: Vec<
        RoutableConnectorChoice,
    >,
    #[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
) -> RouterResult<PaymentData<F>> {
    // Update additional payment data with the payment method response that we received from connector
    // This is for details like whether 3ds was upgraded and which version of 3ds was used
    // also some connectors might send card network details in the response, which is captured and stored

    let additional_payment_data = payment_data.payment_attempt.get_payment_method_data();

    let additional_payment_method_data = match payment_data.payment_method_data.clone() {
        Some(hyperswitch_domain_models::payment_method_data::PaymentMethodData::NetworkToken(_))
        | Some(hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardDetailsForNetworkTransactionId(_)) => {
            payment_data.payment_attempt.payment_method_data.clone()
        }
        _ => {
            additional_payment_data
                .map(|_| {
                    update_additional_payment_data_with_connector_response_pm_data(
                        payment_data.payment_attempt.payment_method_data.clone(),
                        router_data
                            .connector_response
                            .as_ref()
                            .and_then(|connector_response| {
                                connector_response.additional_payment_method_data.clone()
                            }),
                    )
                })
                .transpose()?
                .flatten()
        }
    };

    router_data.payment_method_status.and_then(|status| {
        payment_data
            .payment_method_info
            .as_mut()
            .map(|info| info.status = status)
    });
    payment_data.whole_connector_response = router_data.raw_connector_response.clone();

    // TODO: refactor of gsm_error_category with respective feature flag
    #[allow(unused_variables)]
    let (capture_update, mut payment_attempt_update, gsm_error_category) = match router_data
        .response
        .clone()
    {