Repository: juspay/hyperswitch
File: crates/router/src/core/payment_methods/migration.rs (Rust)

Code before:
                    }

                    // Create updated CommonMandateReference preserving payouts section
                    CommonMandateReference {
                        payments: Some(existing_payments_mandate),
                        payouts: mandate_details.payouts,
                    }
                }
            }
            _ => {
                // If payment_instrument_id or merchant_connector_id is missing, keep existing details
                mandate_details
            }
        };
    let connector_mandate_details_value = updated_connector_mandate_details
        .get_mandate_details_value()
        .map_err(|err| {
            logger::error!("Failed to get get_mandate_details_value : {:?}", err);
            errors::ApiErrorResponse::MandateUpdateFailed
        })?;
    let pm_update =
        PaymentMethodUpdate::ConnectorNetworkTransactionIdStatusAndMandateDetailsUpdate {
            connector_mandate_details: Some(pii::SecretSerdeValue::new(
                connector_mandate_details_value,
            )),
            network_transaction_id,
            status,
        };

    let response = db
        .update_payment_method(
            &state.into(),
            merchant_context.get_merchant_key_store(),
            payment_method,
            pm_update,
            merchant_context.get_merchant_account().storage_scheme,
        )
        .await
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable(format!(
            "Failed to update payment method for existing pm_id: {payment_method_id:?} in db",
        ))?;

    logger::debug!("Payment method updated in db");

    Ok(ApplicationResponse::Json(
        pm_api::PaymentMethodRecordUpdateResponse {
            payment_method_id: response.payment_method_id,
            status: response.status,
            network_transaction_id: response.network_transaction_id,
            connector_mandate_details: response

Review comment (security):
We don't have to update `connector_mandate_details` if it was not requested in the API.

We can create `Some(SecretSerdeValue)` and pass in the above match statement [here](https://github.com/juspay/hyperswitch/pull/9075/files#diff-5bbefb65b030550078d21b981e1f91a1211fc48067dd1ba00a09bdb5ad2d1156R87)

Code after:
                                connector_mandate_request_reference_id: None,
                            },
                        );
                    }

                    // Create updated CommonMandateReference preserving payouts section
                    CommonMandateReference {
                        payments: Some(existing_payments_mandate),
                        payouts: mandate_details.payouts,
                    }
                }
            };

            let connector_mandate_details_value = updated_connector_mandate_details
                .get_mandate_details_value()
                .map_err(|err| {
                    logger::error!("Failed to get get_mandate_details_value : {:?}", err);
                    errors::ApiErrorResponse::MandateUpdateFailed
                })?;

            PaymentMethodUpdate::ConnectorNetworkTransactionIdStatusAndMandateDetailsUpdate {
                connector_mandate_details: Some(pii::SecretSerdeValue::new(
                    connector_mandate_details_value,
                )),
                network_transaction_id,
                status,
            }
        }
        _ => {
            // Update only network_transaction_id and status
            PaymentMethodUpdate::NetworkTransactionIdAndStatusUpdate {
                network_transaction_id,
                status,
            }
        }
    };

    let response = db
        .update_payment_method(
            &state.into(),
            merchant_context.get_merchant_key_store(),
            payment_method,
            pm_update,
            merchant_context.get_merchant_account().storage_scheme,
        )
        .await
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable(format!(
            "Failed to update payment method for existing pm_id: {payment_method_id:?} in db",
        ))?;