Skip to content

Commit

Permalink
refactor(payment_id): add payment id domain type (#5738)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
Narayanbhat166 and hyperswitch-bot[bot] committed Sep 2, 2024
1 parent 4b0564e commit 7296cce
Show file tree
Hide file tree
Showing 150 changed files with 880 additions and 803 deletions.
77 changes: 2 additions & 75 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -10603,58 +10603,6 @@
"display_wait_screen"
]
},
"PaymentIdType": {
"oneOf": [
{
"type": "object",
"required": [
"PaymentIntentId"
],
"properties": {
"PaymentIntentId": {
"type": "string",
"description": "The identifier for payment intent"
}
}
},
{
"type": "object",
"required": [
"ConnectorTransactionId"
],
"properties": {
"ConnectorTransactionId": {
"type": "string",
"description": "The identifier for connector transaction"
}
}
},
{
"type": "object",
"required": [
"PaymentAttemptId"
],
"properties": {
"PaymentAttemptId": {
"type": "string",
"description": "The identifier for payment attempt"
}
}
},
{
"type": "object",
"required": [
"PreprocessingId"
],
"properties": {
"PreprocessingId": {
"type": "string",
"description": "The identifier for preprocessing step"
}
}
}
]
},
"PaymentLinkConfig": {
"type": "object",
"required": [
Expand Down Expand Up @@ -14422,7 +14370,8 @@
],
"properties": {
"resource_id": {
"$ref": "#/components/schemas/PaymentIdType"
"type": "string",
"description": "The type of ID (ex: payment intent id, payment attempt id or connector txn id)"
},
"merchant_id": {
"type": "string",
Expand Down Expand Up @@ -14526,28 +14475,6 @@
}
}
},
"PaymentsStartRequest": {
"type": "object",
"required": [
"payment_id",
"merchant_id",
"attempt_id"
],
"properties": {
"payment_id": {
"type": "string",
"description": "Unique identifier for the payment. This ensures idempotency for multiple payments\nthat have been done by a single merchant. This field is auto generated and is returned in the API response."
},
"merchant_id": {
"type": "string",
"description": "The identifier for the Merchant Account."
},
"attempt_id": {
"type": "string",
"description": "The identifier for the payment transaction"
}
}
},
"PaymentsUpdateRequest": {
"type": "object",
"properties": {
Expand Down
77 changes: 2 additions & 75 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -14616,58 +14616,6 @@
"display_wait_screen"
]
},
"PaymentIdType": {
"oneOf": [
{
"type": "object",
"required": [
"PaymentIntentId"
],
"properties": {
"PaymentIntentId": {
"type": "string",
"description": "The identifier for payment intent"
}
}
},
{
"type": "object",
"required": [
"ConnectorTransactionId"
],
"properties": {
"ConnectorTransactionId": {
"type": "string",
"description": "The identifier for connector transaction"
}
}
},
{
"type": "object",
"required": [
"PaymentAttemptId"
],
"properties": {
"PaymentAttemptId": {
"type": "string",
"description": "The identifier for payment attempt"
}
}
},
{
"type": "object",
"required": [
"PreprocessingId"
],
"properties": {
"PreprocessingId": {
"type": "string",
"description": "The identifier for preprocessing step"
}
}
}
]
},
"PaymentLinkConfig": {
"type": "object",
"required": [
Expand Down Expand Up @@ -18435,7 +18383,8 @@
],
"properties": {
"resource_id": {
"$ref": "#/components/schemas/PaymentIdType"
"type": "string",
"description": "The type of ID (ex: payment intent id, payment attempt id or connector txn id)"
},
"merchant_id": {
"type": "string",
Expand Down Expand Up @@ -18539,28 +18488,6 @@
}
}
},
"PaymentsStartRequest": {
"type": "object",
"required": [
"payment_id",
"merchant_id",
"attempt_id"
],
"properties": {
"payment_id": {
"type": "string",
"description": "Unique identifier for the payment. This ensures idempotency for multiple payments\nthat have been done by a single merchant. This field is auto generated and is returned in the API response."
},
"merchant_id": {
"type": "string",
"description": "The identifier for the Merchant Account."
},
"attempt_id": {
"type": "string",
"description": "The identifier for the payment transaction"
}
}
},
"PaymentsUpdateRequest": {
"type": "object",
"properties": {
Expand Down
8 changes: 4 additions & 4 deletions crates/analytics/src/api_event/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
match query_param.query_param {
QueryType::Payment { payment_id } => {
query_builder
.add_filter_clause("payment_id", payment_id)
.add_filter_clause("payment_id", &payment_id)
.switch()?;
query_builder
.add_filter_in_range_clause(
Expand All @@ -62,7 +62,7 @@ where
refund_id,
} => {
query_builder
.add_filter_clause("payment_id", payment_id)
.add_filter_clause("payment_id", &payment_id)
.switch()?;
query_builder
.add_filter_clause("refund_id", refund_id)
Expand All @@ -76,7 +76,7 @@ where
dispute_id,
} => {
query_builder
.add_filter_clause("payment_id", payment_id)
.add_filter_clause("payment_id", &payment_id)
.switch()?;
query_builder
.add_filter_clause("dispute_id", dispute_id)
Expand All @@ -103,7 +103,7 @@ where
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct ApiLogsResult {
pub merchant_id: common_utils::id_type::MerchantId,
pub payment_id: Option<String>,
pub payment_id: Option<common_utils::id_type::PaymentId>,
pub refund_id: Option<String>,
pub payment_method_id: Option<String>,
pub payment_method: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion crates/analytics/src/connector_events/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ where
.switch()?;

query_builder
.add_filter_clause("payment_id", query_param.payment_id)
.add_filter_clause("payment_id", &query_param.payment_id)
.switch()?;

if let Some(refund_id) = query_param.refund_id {
Expand Down
4 changes: 2 additions & 2 deletions crates/analytics/src/outgoing_webhook_event/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
.add_filter_clause("merchant_id", merchant_id)
.switch()?;
query_builder
.add_filter_clause("payment_id", query_param.payment_id)
.add_filter_clause("payment_id", &query_param.payment_id)
.switch()?;

if let Some(event_id) = query_param.event_id {
Expand Down Expand Up @@ -76,7 +76,7 @@ pub struct OutgoingWebhookLogsResult {
pub event_id: String,
pub event_type: String,
pub outgoing_webhook_event_type: String,
pub payment_id: String,
pub payment_id: common_utils::id_type::PaymentId,
pub refund_id: Option<String>,
pub attempt_id: Option<String>,
pub dispute_id: Option<String>,
Expand Down
6 changes: 6 additions & 0 deletions crates/analytics/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ impl<T: AnalyticsDataSource> ToSql<T> for &common_utils::id_type::MerchantId {
}
}

impl<T: AnalyticsDataSource> ToSql<T> for &common_utils::id_type::PaymentId {
fn to_sql(&self, _table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> {
Ok(self.get_string_repr().to_owned())
}
}

/// Implement `ToSql` on arrays of types that impl `ToString`.
macro_rules! impl_to_sql_for_to_string {
($($type:ty),+) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/analytics/src/sdk_events/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where
.add_filter_clause("merchant_id", publishable_key)
.switch()?;
query_builder
.add_filter_clause("payment_id", request.payment_id)
.add_filter_clause("payment_id", &request.payment_id)
.switch()?;
query_builder
.add_custom_filter_clause("event_name", static_event_list, FilterTypes::In)
Expand All @@ -58,7 +58,7 @@ where
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct SdkEventsResult {
pub merchant_id: common_utils::id_type::MerchantId,
pub payment_id: String,
pub payment_id: common_utils::id_type::PaymentId,
pub event_name: Option<String>,
pub log_type: Option<String>,
pub first_event: bool,
Expand Down
6 changes: 3 additions & 3 deletions crates/api_models/src/analytics/api_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ pub enum FilterType {
#[serde(tag = "type")]
pub enum QueryType {
Payment {
payment_id: String,
payment_id: common_utils::id_type::PaymentId,
},
Refund {
payment_id: String,
payment_id: common_utils::id_type::PaymentId,
refund_id: String,
},
Dispute {
payment_id: String,
payment_id: common_utils::id_type::PaymentId,
dispute_id: String,
},
}
Expand Down
2 changes: 1 addition & 1 deletion crates/api_models/src/analytics/outgoing_webhook_event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct OutgoingWebhookLogsRequest {
pub payment_id: String,
pub payment_id: common_utils::id_type::PaymentId,
pub event_id: Option<String>,
pub refund_id: Option<String>,
pub dispute_id: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion crates/api_models/src/analytics/sdk_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{NameDescription, TimeRange};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SdkEventsRequest {
pub payment_id: String,
pub payment_id: common_utils::id_type::PaymentId,
pub time_range: TimeRange,
}

Expand Down
3 changes: 2 additions & 1 deletion crates/api_models/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub struct DisputeResponse {
/// The identifier for dispute
pub dispute_id: String,
/// The identifier for payment_intent
pub payment_id: String,
#[schema(value_type = String)]
pub payment_id: common_utils::id_type::PaymentId,
/// The identifier for payment_attempt
pub attempt_id: String,
/// The dispute amount
Expand Down
2 changes: 1 addition & 1 deletion crates/api_models/src/errors/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a> From<&'a ApiErrorResponse> for ErrorResponse<'a> {
#[derive(Debug, serde::Serialize, Default, Clone)]
pub struct Extra {
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_id: Option<String>,
pub payment_id: Option<common_utils::id_type::PaymentId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
Loading

0 comments on commit 7296cce

Please sign in to comment.