Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ShankarSinghC committed Dec 22, 2024
1 parent 047c75f commit 3e8b3e5
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 218 deletions.
3 changes: 0 additions & 3 deletions api-reference/api-reference/relay/relay--retrieve.mdx

This file was deleted.

3 changes: 1 addition & 2 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3422,10 +3422,9 @@ impl From<ConnectorType> for TransactionType {
impl From<RefundStatus> for RelayStatus {
fn from(refund_status: RefundStatus) -> Self {
match refund_status {
RefundStatus::Failure => Self::Failure,
RefundStatus::Failure | RefundStatus::TransactionFailure => Self::Failure,
RefundStatus::ManualReview | RefundStatus::Pending => Self::Pending,
RefundStatus::Success => Self::Success,
RefundStatus::TransactionFailure => Self::Failure,
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions crates/common_utils/src/id_type/relay.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

crate::id_type!(
RelayId,
"A type for relay_id that can be used for relay ids"
Expand All @@ -13,12 +11,3 @@ crate::impl_queryable_id_type!(RelayId);
crate::impl_to_sql_from_sql_id_type!(RelayId);

crate::impl_debug_id_type!(RelayId);

impl FromStr for RelayId {
type Err = error_stack::Report<crate::errors::ValidationError>;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let cow_string = std::borrow::Cow::Owned(s.to_string());
Self::try_from(cow_string)
}
}
10 changes: 2 additions & 8 deletions crates/diesel_models/src/query/relay.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods};
use diesel::{associations::HasTable, ExpressionMethods};

use super::generics;
use crate::{
Expand All @@ -25,13 +25,7 @@ impl Relay {
_,
_,
_,
>(
conn,
dsl::id
.eq(self.id.to_owned())
.and(dsl::merchant_id.eq(self.merchant_id.to_owned())),
relay,
)
>(conn, dsl::id.eq(self.id.to_owned()), relay)
.await
{
Err(error) => match error.current_context() {
Expand Down
77 changes: 38 additions & 39 deletions crates/diesel_models/src/relay.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{enums as storage_enums, schema::relay};
use common_utils::pii;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use time::PrimitiveDateTime;

use crate::{enums as storage_enums, schema::relay};

#[derive(
Clone,
Debug,
Expand Down Expand Up @@ -66,17 +65,17 @@ pub struct RelayNew {
pub response_data: Option<pii::SecretSerdeValue>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum RelayUpdate {
ErrorUpdate {
error_code: String,
error_reason: String,
},
StatusUpdate {
connector_reference_id: Option<String>,
status: storage_enums::RelayStatus,
},
}
// #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
// pub enum RelayUpdate {
// ErrorUpdate {
// error_code: String,
// error_reason: String,
// },
// StatusUpdate {
// connector_reference_id: Option<String>,
// status: storage_enums::RelayStatus,
// },
// }

#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[table_name = "relay"]
Expand All @@ -88,29 +87,29 @@ pub struct RelayUpdateInternal {
pub modified_at: PrimitiveDateTime,
}

impl From<RelayUpdate> for RelayUpdateInternal {
fn from(value: RelayUpdate) -> Self {
match value {
RelayUpdate::ErrorUpdate {
error_code,
error_reason,
} => Self {
error_code: Some(error_code),
error_reason: Some(error_reason),
connector_reference_id: None,
status: None,
modified_at: common_utils::date_time::now(),
},
RelayUpdate::StatusUpdate {
connector_reference_id,
status,
} => Self {
connector_reference_id,
status: Some(status),
error_code: None,
error_reason: None,
modified_at: common_utils::date_time::now(),
},
}
}
}
// impl From<RelayUpdate> for RelayUpdateInternal {
// fn from(value: RelayUpdate) -> Self {
// match value {
// RelayUpdate::ErrorUpdate {
// error_code,
// error_reason,
// } => Self {
// error_code: Some(error_code),
// error_reason: Some(error_reason),
// connector_reference_id: None,
// status: None,
// modified_at: common_utils::date_time::now(),
// },
// RelayUpdate::StatusUpdate {
// connector_reference_id,
// status,
// } => Self {
// connector_reference_id,
// status: Some(status),
// error_code: None,
// error_reason: None,
// modified_at: common_utils::date_time::now(),
// },
// }
// }
// }
35 changes: 27 additions & 8 deletions crates/hyperswitch_domain_models/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ impl From<Relay> for api_models::relay::RelayResponse {
);

let data = value.request_data.map(|relay_data| match relay_data {
RelayData::Refund(relay_refund_request) => api_models::relay::RelayRefundRequest {
amount: relay_refund_request.amount,
currency: relay_refund_request.currency,
reason: relay_refund_request.reason,
},
RelayData::Refund(relay_refund_request) => {
api_models::relay::RelayData::Refund(api_models::relay::RelayRefundRequest {
amount: relay_refund_request.amount,
currency: relay_refund_request.currency,
reason: relay_refund_request.reason,
})
}
});
Self {
id: value.id,
Expand All @@ -58,7 +60,7 @@ impl From<Relay> for api_models::relay::RelayResponse {
connector_id: value.connector_id,
profile_id: value.profile_id,
relay_type: value.relay_type,
data: data.map(api_models::relay::RelayData::Refund),
data: data,
connector_reference_id: value.connector_reference_id,
}
}
Expand All @@ -67,11 +69,11 @@ impl From<Relay> for api_models::relay::RelayResponse {
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case", untagged)]
pub enum RelayData {
Refund(RelayRefundRequest),
Refund(RelayRefundData),
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RelayRefundRequest {
pub struct RelayRefundData {
pub amount: MinorUnit,
pub currency: enums::Currency,
pub reason: Option<String>,
Expand All @@ -90,6 +92,23 @@ pub enum RelayUpdate {
},
}

// impl From<Result<Response, ErrorResponse>> for RelayUpdate {
// fn from(value: Result<Response, ErrorResponse>) -> Self {
// match value.response {
// Err(error) => hyperswitch_domain_models::relay::RelayUpdate::ErrorUpdate {
// error_code: error.code,
// error_reason: error.message,
// status: common_enums::RelayStatus::Failure,
// },
// Ok(response) => hyperswitch_domain_models::relay::RelayUpdate::StatusUpdate {
// connector_reference_id: Some(response.connector_refund_id),
// status: common_enums::RelayStatus::from(response.refund_status),
// },
// }
// }
// }


impl From<RelayUpdate> for RelayUpdateInternal {
fn from(value: RelayUpdate) -> Self {
match value {
Expand Down
2 changes: 0 additions & 2 deletions crates/router/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ pub const FINGERPRINT_SECRET_LENGTH: usize = 64;

pub const DEFAULT_LIST_API_LIMIT: u16 = 10;

pub const X_PROFILE_ID: &str = "X-Profile-Id";

// String literals
pub(crate) const UNSUPPORTED_ERROR_MESSAGE: &str = "Unsupported response type";
pub(crate) const LOW_BALANCE_ERROR_MESSAGE: &str = "Insufficient balance in the payment method";
Expand Down
Loading

0 comments on commit 3e8b3e5

Please sign in to comment.