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

Code before:
                    // Handle PaymentsMandateReference
                    let mut existing_payments_mandate = mandate_details
                        .payments
                        .unwrap_or_else(|| PaymentsMandateReference(HashMap::new()));

                    // Check if record exists for this merchant_connector_id
                    if let Some(existing_record) =
                        existing_payments_mandate.0.get_mut(merchant_connector_id)
                    {
                        existing_record.connector_mandate_id =
                            payment_instrument_id.peek().to_string();
                    } else {
                        // Insert new record in connector_mandate_details
                        existing_payments_mandate.0.insert(
                            merchant_connector_id.clone(),
                            PaymentsMandateReferenceRecord {
                                connector_mandate_id: payment_instrument_id.peek().to_string(),
                                payment_method_type: None,
                                original_payment_authorized_amount: None,
                                original_payment_authorized_currency: None,
                                mandate_metadata: None,
                                connector_mandate_status: None,
                                connector_mandate_request_reference_id: None,
                            },
                        );
                    }

                    // 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,

Review comment (security):
Writing it this way would be more clear -

```suggestion
match mca.connector_type {
    enums::ConnectorType::PayoutProcessor => {
        let mut existing_payouts_mandate = mandate_details
            .payouts
            .unwrap_or_else(|| PayoutsMandateReference(HashMap::new()));

        if let Some(existing_record) = existing_payouts_mandate.0.get_mut(merchant_connector_id) {
            existing_record.transfer_method_id =
                Some(payment_instrument_id.peek().to_string());
        } else {
            existing_payouts_mandate.0.insert(
                merchant_connector_id.clone(),
                PayoutsMandateReferenceRecord {
                    transfer_method_id: Some(payment_instrument_id.peek().to_string()),
                },
            );
        }
        mandate_details.payouts = Some(existing_payouts_mandate);
    }

    _ => {
        let mut existing_payments_mandate = mandate_details
            .payments
            .unwrap_or_else(|| PaymentsMandateReference(HashMap::new()));

        if let Some(existing_record) = existing_payments_mandate.0.get_mut(merchant_connector_id) {
            existing_record.connector_mandate_id =
                payment_instrument_id.peek().to_string();
        } else {
            existing_payments_mandate.0.insert(
                merchant_connector_id.clone(),
                PaymentsMandateReferenceRecord {
                    connector_mandate_id: payment_instrument_id.peek().to_string(),
                    payment_method_type: None,
                    original_payment_authorized_amount: None,
                    original_payment_authorized_currency: None,
                    mandate_metadata: None,
                    connector_mandate_status: None,
                    connector_mandate_request_reference_id: None,
                },
            );
        }
        mandate_details.payments = Some(existing_payments_mandate);
    }
}
```

Code after:
                    }
                }
                _ => {
                    // Handle PaymentsMandateReference
                    let mut existing_payments_mandate = mandate_details
                        .payments
                        .unwrap_or_else(|| PaymentsMandateReference(HashMap::new()));

                    // Check if record exists for this merchant_connector_id
                    if let Some(existing_record) =
                        existing_payments_mandate.0.get_mut(merchant_connector_id)
                    {
                        existing_record.connector_mandate_id =
                            payment_instrument_id.peek().to_string();
                    } else {
                        // Insert new record in connector_mandate_details
                        existing_payments_mandate.0.insert(
                            merchant_connector_id.clone(),
                            PaymentsMandateReferenceRecord {
                                connector_mandate_id: payment_instrument_id.peek().to_string(),
                                payment_method_type: None,
                                original_payment_authorized_amount: None,
                                original_payment_authorized_currency: None,
                                mandate_metadata: None,
                                connector_mandate_status: None,
                                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,