mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
refactor(subscription): make invoice as an id type (#9488)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Jagan <jaganelavarasan@gmail.com>
This commit is contained in:
@ -86,6 +86,7 @@ pub enum ApiEventsType {
|
|||||||
},
|
},
|
||||||
Routing,
|
Routing,
|
||||||
Subscription,
|
Subscription,
|
||||||
|
Invoice,
|
||||||
ResourceListAPI,
|
ResourceListAPI,
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
PaymentRedirectionResponse {
|
PaymentRedirectionResponse {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ mod client_secret;
|
|||||||
mod customer;
|
mod customer;
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
mod global_id;
|
mod global_id;
|
||||||
|
mod invoice;
|
||||||
mod merchant;
|
mod merchant;
|
||||||
mod merchant_connector_account;
|
mod merchant_connector_account;
|
||||||
mod organization;
|
mod organization;
|
||||||
@ -47,6 +48,7 @@ pub use self::{
|
|||||||
authentication::AuthenticationId,
|
authentication::AuthenticationId,
|
||||||
client_secret::ClientSecretId,
|
client_secret::ClientSecretId,
|
||||||
customer::CustomerId,
|
customer::CustomerId,
|
||||||
|
invoice::InvoiceId,
|
||||||
merchant::MerchantId,
|
merchant::MerchantId,
|
||||||
merchant_connector_account::MerchantConnectorAccountId,
|
merchant_connector_account::MerchantConnectorAccountId,
|
||||||
organization::OrganizationId,
|
organization::OrganizationId,
|
||||||
|
|||||||
21
crates/common_utils/src/id_type/invoice.rs
Normal file
21
crates/common_utils/src/id_type/invoice.rs
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
use common_enums::connector_enums::{Connector, InvoiceStatus};
|
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 diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -8,8 +8,8 @@ use crate::schema::invoice;
|
|||||||
#[derive(Clone, Debug, Eq, Insertable, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Eq, Insertable, PartialEq, Serialize, Deserialize)]
|
||||||
#[diesel(table_name = invoice, check_for_backend(diesel::pg::Pg))]
|
#[diesel(table_name = invoice, check_for_backend(diesel::pg::Pg))]
|
||||||
pub struct InvoiceNew {
|
pub struct InvoiceNew {
|
||||||
pub id: String,
|
pub id: common_utils::id_type::InvoiceId,
|
||||||
pub subscription_id: String,
|
pub subscription_id: common_utils::id_type::SubscriptionId,
|
||||||
pub merchant_id: common_utils::id_type::MerchantId,
|
pub merchant_id: common_utils::id_type::MerchantId,
|
||||||
pub profile_id: common_utils::id_type::ProfileId,
|
pub profile_id: common_utils::id_type::ProfileId,
|
||||||
pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
||||||
@ -34,8 +34,8 @@ pub struct InvoiceNew {
|
|||||||
check_for_backend(diesel::pg::Pg)
|
check_for_backend(diesel::pg::Pg)
|
||||||
)]
|
)]
|
||||||
pub struct Invoice {
|
pub struct Invoice {
|
||||||
id: String,
|
id: common_utils::id_type::InvoiceId,
|
||||||
subscription_id: String,
|
subscription_id: common_utils::id_type::SubscriptionId,
|
||||||
merchant_id: common_utils::id_type::MerchantId,
|
merchant_id: common_utils::id_type::MerchantId,
|
||||||
profile_id: common_utils::id_type::ProfileId,
|
profile_id: common_utils::id_type::ProfileId,
|
||||||
merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
||||||
@ -62,8 +62,7 @@ pub struct InvoiceUpdate {
|
|||||||
impl InvoiceNew {
|
impl InvoiceNew {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: String,
|
subscription_id: common_utils::id_type::SubscriptionId,
|
||||||
subscription_id: String,
|
|
||||||
merchant_id: common_utils::id_type::MerchantId,
|
merchant_id: common_utils::id_type::MerchantId,
|
||||||
profile_id: common_utils::id_type::ProfileId,
|
profile_id: common_utils::id_type::ProfileId,
|
||||||
merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
||||||
@ -76,6 +75,7 @@ impl InvoiceNew {
|
|||||||
provider_name: Connector,
|
provider_name: Connector,
|
||||||
metadata: Option<SecretSerdeValue>,
|
metadata: Option<SecretSerdeValue>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let id = common_utils::id_type::InvoiceId::generate();
|
||||||
let now = common_utils::date_time::now();
|
let now = common_utils::date_time::now();
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
|
|||||||
Reference in New Issue
Block a user