Skip to content

Commit

Permalink
chore: Resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Dec 18, 2024
1 parent a809655 commit 7aa4143
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
22 changes: 22 additions & 0 deletions crates/api_models/src/ephemeral_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,34 @@ pub struct EphemeralKeyCreateRequest {
pub customer_id: id_type::GlobalCustomerId,
}

#[cfg(feature = "v2")]
/// ephemeral_key for the customer_id mentioned
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Eq, PartialEq, ToSchema)]
pub struct EphemeralKeyResponse {
/// customer_id to which this ephemeral key belongs to
#[schema(value_type = String, max_length = 64, min_length = 32, example = "12345_cus_01926c58bc6e77c09e809964e72af8c8")]
pub customer_id: id_type::GlobalCustomerId,
/// time at which this ephemeral key was created
pub created_at: time::PrimitiveDateTime,
/// time at which this ephemeral key would expire
pub expires: time::PrimitiveDateTime,
/// ephemeral key
pub secret: String,
}

impl common_utils::events::ApiEventMetric for EphemeralKeyCreateRequest {
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
Some(common_utils::events::ApiEventsType::Miscellaneous)
}
}

#[cfg(feature = "v2")]
impl common_utils::events::ApiEventMetric for EphemeralKeyResponse {
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
Some(common_utils::events::ApiEventsType::Miscellaneous)
}
}

/// ephemeral_key for the customer_id mentioned
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Eq, PartialEq, ToSchema)]
pub struct EphemeralKeyCreateResponse {
Expand Down
7 changes: 0 additions & 7 deletions crates/diesel_models/src/ephemeral_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ impl common_utils::events::ApiEventMetric for EphemeralKey {
}
}

#[cfg(feature = "v2")]
impl common_utils::events::ApiEventMetric for EphemeralKeyType {
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
Some(common_utils::events::ApiEventsType::Miscellaneous)
}
}

#[derive(
Clone,
Copy,
Expand Down
12 changes: 8 additions & 4 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{borrow::Cow, str::FromStr};

#[cfg(feature = "v2")]
use api_models::ephemeral_key::EphemeralKeyResponse;
use api_models::{
mandates::RecurringDetails,
payments::{additional_info as payment_additional_types, RequestSurchargeDetails},
Expand Down Expand Up @@ -3050,7 +3052,7 @@ pub async fn make_ephemeral_key(
customer_id: id_type::GlobalCustomerId,
merchant_id: id_type::MerchantId,
headers: &actix_web::http::header::HeaderMap,
) -> errors::RouterResponse<ephemeral_key::EphemeralKeyType> {
) -> errors::RouterResponse<EphemeralKeyResponse> {
let store = &state.store;
let id = id_type::EphemeralKeyId::generate_key_id("eki");
let secret = format!("epk_{}", &Uuid::new_v4().simple().to_string());
Expand All @@ -3077,7 +3079,8 @@ pub async fn make_ephemeral_key(
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to create ephemeral key")?;
Ok(services::ApplicationResponse::Json(ek))
let response = EphemeralKeyResponse::foreign_from(ek);
Ok(services::ApplicationResponse::Json(response))
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -3123,14 +3126,15 @@ pub async fn delete_ephemeral_key(
pub async fn delete_ephemeral_key(
state: SessionState,
ek_id: String,
) -> errors::RouterResponse<ephemeral_key::EphemeralKeyType> {
) -> errors::RouterResponse<EphemeralKeyResponse> {
let db = state.store.as_ref();
let ek = db
.delete_ephemeral_key(&ek_id)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to delete ephemeral key")?;
Ok(services::ApplicationResponse::Json(ek))
let response = EphemeralKeyResponse::foreign_from(ek);
Ok(services::ApplicationResponse::Json(response))
}

pub fn make_pg_redirect_response(
Expand Down
14 changes: 14 additions & 0 deletions crates/router/src/types/storage/ephemeral_key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
pub use diesel_models::ephemeral_key::{EphemeralKey, EphemeralKeyNew};
#[cfg(feature = "v2")]
pub use diesel_models::ephemeral_key::{EphemeralKeyType, EphemeralKeyTypeNew, ResourceType};

#[cfg(feature = "v2")]
use crate::types::transformers::ForeignFrom;
#[cfg(feature = "v2")]
impl ForeignFrom<EphemeralKeyType> for api_models::ephemeral_key::EphemeralKeyResponse {
fn foreign_from(from: EphemeralKeyType) -> Self {
Self {
customer_id: from.customer_id,
created_at: from.created_at,
expires: from.expires,
secret: from.secret,
}
}
}

0 comments on commit 7aa4143

Please sign in to comment.