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

Code before:
    //pm client construction
    let client = pm_client::PaymentMethodClient::new(
        &state.conf.micro_services.payment_methods_base_url,
        &parent_headers,
        &trace,
    );

    //Modular service call
    let pm_response =
        pm_client::RetrievePaymentMethod::call(state, &client, payment_method_fetch_req)
            .await
            .map_err(|err| {
                logger::debug!("Error in retrieving payment method: {:?}", err);
                errors::ApiErrorResponse::InternalServerError
            })
            .attach_printable("Failed to retrieve payment method from modular service")?;

    Ok(pm_response)
}

//Create Payment Method from Modular Service
#[cfg(feature = "v1")]
#[allow(clippy::too_many_arguments)]
pub async fn create_payment_method_in_modular_service(
    state: &routes::SessionState,
    merchant_id: &id_type::MerchantId,
    processor_merchant_id: &id_type::MerchantId,
    profile_id: &id_type::ProfileId,
    payment_method: common_enums::PaymentMethod,
    payment_method_type: common_enums::PaymentMethodType,
    payment_method_data: domain::PaymentMethodData,
    billing_address: Option<hyperswitch_domain_models::address::Address>,
    customer_id: id_type::CustomerId,
) -> CustomResult<domain::PaymentMethod, errors::ApiErrorResponse> {
    let payment_method_request = CreatePaymentMethodV1Request {
        merchant_id: merchant_id.clone(),
        payment_method,
        payment_method_type,
        metadata: None,
        customer_id,
        payment_method_data,
        billing: billing_address,
        network_tokenization: None,
        storage_type: Some(common_enums::StorageType::Persistent),
        modular_service_prefix: state.conf.micro_services.payment_methods_prefix.0.clone(),
    };

    //Create modular service call
    let pm_response = create_pm_modular_service_call(
        state,
        processor_merchant_id,

Review comment (suggestion):
```suggestion
    provider_merchant_id: &id_type::MerchantId,
```

Code after:
        headers::X_INTERNAL_API_KEY.to_string(),
        internal_api_key.clone().expose().to_string().into_masked(),
    ));
    parent_headers.insert((
        headers::X_MERCHANT_ID.to_string(),
        processor_merchant_id
            .get_string_repr()
            .to_string()
            .into_masked(),
    ));

    let trace = RequestIdentifier::new(&state.conf.trace_header.header_name)
        .use_incoming_id(state.conf.trace_header.id_reuse_strategy);

    //pm client construction
    let client = pm_client::PaymentMethodClient::new(
        &state.conf.micro_services.payment_methods_base_url,
        &parent_headers,
        &trace,
    );

    //Modular service call
    let pm_response =
        pm_client::RetrievePaymentMethod::call(state, &client, payment_method_fetch_req)
            .await
            .map_err(|err| {
                logger::debug!("Error in retrieving payment method: {:?}", err);
                errors::ApiErrorResponse::InternalServerError
            })
            .attach_printable("Failed to retrieve payment method from modular service")?;

    Ok(pm_response)
}

//Create Payment Method from Modular Service
#[cfg(feature = "v1")]
#[allow(clippy::too_many_arguments)]
pub async fn create_payment_method_in_modular_service(
    state: &routes::SessionState,
    provider_merchant_id: &id_type::MerchantId,
    processor_merchant_id: &id_type::MerchantId,
    profile_id: &id_type::ProfileId,
    payment_method: common_enums::PaymentMethod,
    payment_method_type: common_enums::PaymentMethodType,
    payment_method_data: domain::PaymentMethodData,
    billing_address: Option<hyperswitch_domain_models::address::Address>,
    customer_id: id_type::CustomerId,
) -> CustomResult<domain::PaymentMethod, errors::ApiErrorResponse> {
    let payment_method_request = CreatePaymentMethodV1Request {
        merchant_id: provider_merchant_id.clone(),
        payment_method,