Repository: juspay/hyperswitch
File: crates/router/src/routes/subscription.rs (Rust)

Code before:
        ),
        api_locking::LockAction::NotApplicable,
    ))
    .await
}

#[cfg(all(feature = "olap", feature = "v1"))]
#[instrument(skip_all)]
pub async fn get_subscription_plans(
    state: web::Data<AppState>,
    req: HttpRequest,
    query: web::Query<subscription_types::GetPlansQuery>,
) -> impl Responder {
    let flow = Flow::GetPlansForSubscription;
    let api_auth = auth::ApiKeyAuth::default();

    let profile_id = match req.headers().get(X_PROFILE_ID) {
        Some(val) => val.to_str().unwrap_or_default().to_string(),
        None => {
            return HttpResponse::BadRequest().json(
                errors::api_error_response::ApiErrorResponse::MissingRequiredField {
                    field_name: "x-profile-id",
                },
            );
        }
    };

    let auth_data = match auth::is_ephemeral_auth(req.headers(), api_auth) {
        Ok(auth) => auth,
        Err(err) => return crate::services::api::log_and_return_error_response(err),
    };

    Box::pin(oss_api::server_wrap(
        flow,
        state,
        &req,
        query.into_inner(),
        |state, auth: auth::AuthenticationData, query, _| {
            let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
                domain::Context(auth.merchant_account, auth.key_store),
            ));
            subscription::get_subscription_plans(state, merchant_context, profile_id.clone(), query)
        },
        &*auth_data,
        api_locking::LockAction::NotApplicable,
    ))
    .await
}


Review comment (refactor):
```suggestion
fn extract_profile_id(req: &HttpRequest) -> Result<common_utils::id_type::ProfileId, HttpResponse> {
    let header_value = req.headers().get(X_PROFILE_ID).ok_or_else(|| {
        HttpResponse::BadRequest().json(
            errors::api_error_response::ApiErrorResponse::MissingRequiredField {
                field_name: X_PROFILE_ID,
            },
        )
    })?;

    let profile_str = header_value.to_str().unwrap_or_default();

    if profile_str.is_empty() {
        return Err(HttpResponse::BadRequest().json(
            errors::api_error_response::ApiErrorResponse::MissingRequiredField {
                field_name: X_PROFILE_ID,
            },
        ));
    }

    common_utils::id_type::ProfileId::from_str(profile_str).map_err(|_| {
        HttpResponse::BadRequest().json(
            errors::api_error_response::ApiErrorResponse::InvalidDataValue {
                field_name: X_PROFILE_ID,
            },
        )
    })
}
```
don't pass string from here use above method to get ProfileID domain type and pass it to underlying methods

Code after:
            ));
            subscription::confirm_subscription(
                state,
                merchant_context,
                profile_id.clone(),
                payload.clone(),
                subscription_id.clone(),
            )
        },
        auth::auth_type(
            &auth::HeaderAuth(auth::ApiKeyAuth {
                is_connected_allowed: false,
                is_platform_allowed: false,
            }),
            &auth::JWTAuth {
                permission: Permission::ProfileSubscriptionWrite,
            },
            req.headers(),
        ),
        api_locking::LockAction::NotApplicable,
    ))
    .await
}

#[instrument(skip_all)]
pub async fn get_subscription_plans(
    state: web::Data<AppState>,
    req: HttpRequest,
    query: web::Query<subscription_types::GetPlansQuery>,
) -> impl Responder {
    let flow = Flow::GetPlansForSubscription;
    let api_auth = auth::ApiKeyAuth::default();

    let profile_id = match extract_profile_id(&req) {
        Ok(profile_id) => profile_id,
        Err(response) => return response,
    };

    let auth_data = match auth::is_ephemeral_auth(req.headers(), api_auth) {
        Ok(auth) => auth,
        Err(err) => return crate::services::api::log_and_return_error_response(err),
    };
    Box::pin(oss_api::server_wrap(
        flow,
        state,
        &req,
        query.into_inner(),
        |state, auth: auth::AuthenticationData, query, _| {
            let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
                domain::Context(auth.merchant_account, auth.key_store),
            ));