Bug: Add invoice_id type and autogeneration util




diff --git a/crates/common_utils/src/events.rs b/crates/common_utils/src/events.rs
index dc8f6e333a4..b1f1883257d 100644
--- a/crates/common_utils/src/events.rs
+++ b/crates/common_utils/src/events.rs
@@ -86,6 +86,7 @@ pub enum ApiEventsType {
     },
     Routing,
     Subscription,
+    Invoice,
     ResourceListAPI,
     #[cfg(feature = "v1")]
     PaymentRedirectionResponse {
diff --git a/crates/common_utils/src/id_type.rs b/crates/common_utils/src/id_type.rs
index 237ca661c10..d1ab0106688 100644
--- a/crates/common_utils/src/id_type.rs
+++ b/crates/common_utils/src/id_type.rs
@@ -7,6 +7,7 @@ mod client_secret;
 mod customer;
 #[cfg(feature = "v2")]
 mod global_id;
+mod invoice;
 mod merchant;
 mod merchant_connector_account;
 mod organization;
@@ -47,6 +48,7 @@ pub use self::{
     authentication::AuthenticationId,
     client_secret::ClientSecretId,
     customer::CustomerId,
+    invoice::InvoiceId,
     merchant::MerchantId,
     merchant_connector_account::MerchantConnectorAccountId,
     organization::OrganizationId,
diff --git a/crates/common_utils/src/id_type/invoice.rs b/crates/common_utils/src/id_type/invoice.rs
new file mode 100644
index 00000000000..9cf0289e2ee
--- /dev/null
+++ b/crates/common_utils/src/id_type/invoice.rs
@@ -0,0 +1,21 @@
+crate::id_type!(
+    InvoiceId,
+    " A type for invoice_id that can be used for invoice ids"
+);
+
+crate::impl_id_type_methods!(InvoiceId, "invoice_id");
+
+// This is to display the `InvoiceId` as InvoiceId(subs)
+crate::impl_debug_id_type!(InvoiceId);
+crate::impl_try_from_cow_str_id_type!(InvoiceId, "invoice_id");
+
+crate::impl_generate_id_id_type!(InvoiceId, "invoice");
+crate::impl_serializable_secret_id_type!(InvoiceId);
+crate::impl_queryable_id_type!(InvoiceId);
+crate::impl_to_sql_from_sql_id_type!(InvoiceId);
+
+impl crate::events::ApiEventMetric for InvoiceId {
+    fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
+        Some(crate::events::ApiEventsType::Invoice)
+    }
+}
diff --git a/crates/diesel_models/src/invoice.rs b/crates/diesel_models/src/invoice.rs
index 24534629307..57024d0730a 100644
--- a/crates/diesel_models/src/invoice.rs
+++ b/crates/diesel_models/src/invoice.rs
@@ -1,5 +1,5 @@
 use common_enums::connector_enums::{Connector, InvoiceStatus};
-use common_utils::{pii::SecretSerdeValue, types::MinorUnit};
+use common_utils::{id_type::GenerateId, pii::SecretSerdeValue, types::MinorUnit};
 use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
 use serde::{Deserialize, Serialize};
 
@@ -8,8 +8,8 @@ use crate::schema::invoice;
 #[derive(Clone, Debug, Eq, Insertable, PartialEq, Serialize, Deserialize)]
 #[diesel(table_name = invoice, check_for_backend(diesel::pg::Pg))]
 pub struct InvoiceNew {
-    pub id: String,
-    pub subscription_id: String,
+    pub id: common_utils::id_type::InvoiceId,
+    pub subscription_id: common_utils::id_type::SubscriptionId,
     pub merchant_id: common_utils::id_type::MerchantId,
     pub profile_id: common_utils::id_type::ProfileId,
     pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
@@ -34,8 +34,8 @@ pub struct InvoiceNew {
     check_for_backend(diesel::pg::Pg)
 )]
 pub struct Invoice {
-    id: String,
-    subscription_id: String,
+    id: common_utils::id_type::InvoiceId,
+    subscription_id: common_utils::id_type::SubscriptionId,
     merchant_id: common_utils::id_type::MerchantId,
     profile_id: common_utils::id_type::ProfileId,
     merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
@@ -62,8 +62,7 @@ pub struct InvoiceUpdate {
 impl InvoiceNew {
     #[allow(clippy::too_many_arguments)]
     pub fn new(
-        id: String,
-        subscription_id: String,
+        subscription_id: common_utils::id_type::SubscriptionId,
         merchant_id: common_utils::id_type::MerchantId,
         profile_id: common_utils::id_type::ProfileId,
         merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
@@ -76,6 +75,7 @@ impl InvoiceNew {
         provider_name: Connector,
         metadata: Option<SecretSerdeValue>,
     ) -> Self {
+        let id = common_utils::id_type::InvoiceId::generate();
         let now = common_utils::date_time::now();
         Self {
             id,

This pull request introduces a new strongly-typed `InvoiceId` identifier and integrates it throughout the codebase to improve type safety and consistency for invoice-related operations. The changes affect both the common utilities and the invoice models, updating struct fields and constructors to use the new type instead of raw strings.

**Invoice ID type integration:**

* Added a new `InvoiceId` type in `common_utils::id_type` and made it available for use throughout the codebase. [[1]](diffhunk://#diff-d949a6c528436f8ab1a851147e7467d525cba63b395b253d1dec17101a971fa1R10) [[2]](diffhunk://#diff-d949a6c528436f8ab1a851147e7467d525cba63b395b253d1dec17101a971fa1R51)
* Updated the `InvoiceNew` and `Invoice` structs in `crates/diesel_models/src/invoice.rs` to use `InvoiceId` and `SubscriptionId` types for their respective fields, replacing previous usage of `String`. [[1]](diffhunk://#diff-cc8ce5ad039d65f1b8644286fe6abb6e8fae401fdb8e5f43f3984efdf2803696L11-R12) [[2]](diffhunk://#diff-cc8ce5ad039d65f1b8644286fe6abb6e8fae401fdb8e5f43f3984efdf2803696L37-R38)
* Modified the `InvoiceNew::new` constructor to automatically generate an `InvoiceId` using the new type, removing the need to pass an ID as a string argument. [[1]](diffhunk://#diff-cc8ce5ad039d65f1b8644286fe6abb6e8fae401fdb8e5f43f3984efdf2803696L65-R65) [[2]](diffhunk://#diff-cc8ce5ad039d65f1b8644286fe6abb6e8fae401fdb8e5f43f3984efdf2803696R78)

**Event type extension:**

* Added a new `Invoice` variant to the `ApiEventsType` enum to support invoice-related events.
## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
This can't be tested as it adds id type for invoice for which there is no external facing api.

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
