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

Code before:
    subscription.generate_and_set_client_secret();
    let subscription_response = db
        .insert_subscription_entry(subscription)
        .await
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("subscriptions: unable to insert subscription entry to database")?;

    let response = CreateSubscriptionResponse::new(
        subscription_response.id.clone(),
        subscription_response.merchant_reference_id,
        SubscriptionStatus::from_str(&subscription_response.status)
            .unwrap_or(SubscriptionStatus::Created),
        None,
        subscription_response.profile_id,
        subscription_response.merchant_id,
        subscription_response.client_secret.map(Secret::new),
        request.customer_id,
    );

    Ok(ApplicationResponse::Json(response))
}

pub async fn get_subscription_plans(
    state: SessionState,
    merchant_context: MerchantContext,
    profile_id: String,
    query: subscription_types::GetPlansQuery,
) -> RouterResponse<Vec<subscription_types::GetPlansResponse>> {
    let profile_id = common_utils::id_type::ProfileId::from_str(&profile_id).change_context(
        errors::ApiErrorResponse::InvalidDataValue {
            field_name: "X-Profile-Id",
        },
    )?;

    let key_manager_state = &(&state).into();
    let merchant_key_store = merchant_context.get_merchant_key_store();

    let profile = state
        .store
        .find_business_profile_by_profile_id(key_manager_state, merchant_key_store, &profile_id)
        .await
        .change_context(errors::ApiErrorResponse::ProfileNotFound {
            id: profile_id.get_string_repr().to_string(),
        })?;

    let subscription_handler = subscription_utils::SubscriptionHandler::new(
        state.clone(),
        merchant_context.clone(),
        profile,
    );


Review comment (suggestion):
```suggestion
    profile_id: ProfileId,
```
pass domain type from caller itself as suggested below

Code after:
        .await
        .attach_printable("subscriptions: failed to create subscription entry")?;
    let invoice_handler = subscription.get_invoice_handler(profile.clone());
    let payment = invoice_handler
        .create_payment_with_confirm_false(subscription.handler.state, &request)
        .await
        .attach_printable("subscriptions: failed to create payment")?;
    let invoice_entry = invoice_handler
        .create_invoice_entry(
            &state,
            billing_handler.merchant_connector_id,
            Some(payment.payment_id.clone()),
            request.amount,
            request.currency,
            connector_enums::InvoiceStatus::InvoiceCreated,
            billing_handler.connector_data.connector_name,
            None,
        )
        .await
        .attach_printable("subscriptions: failed to create invoice")?;

    subscription
        .update_subscription(diesel_models::subscription::SubscriptionUpdate::new(
            payment.payment_method_id.clone(),
            None,
            None,
        ))
        .await
        .attach_printable("subscriptions: failed to update subscription")?;

    let response = subscription.generate_response(
        &invoice_entry,
        &payment,
        subscription_response_types::SubscriptionStatus::Created,
    )?;

    Ok(ApplicationResponse::Json(response))
}

pub async fn get_subscription_plans(
    state: SessionState,
    merchant_context: MerchantContext,
    profile_id: common_utils::id_type::ProfileId,
    query: subscription_types::GetPlansQuery,
) -> RouterResponse<Vec<subscription_types::GetPlansResponse>> {
    let profile =
        SubscriptionHandler::find_business_profile(&state, &merchant_context, &profile_id)
            .await
            .attach_printable("subscriptions: failed to find business profile")?;

    let subscription_handler = SubscriptionHandler::new(&state, &merchant_context);