mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
Refactor(refunds_v2): Refactor api event metric for refunds v2 apis (#8041)
This commit is contained in:
@ -22,13 +22,6 @@ impl ApiEventMetric for RefundRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v2")]
|
|
||||||
impl ApiEventMetric for refunds::RefundsCreateRequest {
|
|
||||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
impl ApiEventMetric for refunds::RefundResponse {
|
impl ApiEventMetric for refunds::RefundResponse {
|
||||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||||
@ -43,7 +36,7 @@ impl ApiEventMetric for refunds::RefundResponse {
|
|||||||
impl ApiEventMetric for refunds::RefundResponse {
|
impl ApiEventMetric for refunds::RefundResponse {
|
||||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||||
Some(ApiEventsType::Refund {
|
Some(ApiEventsType::Refund {
|
||||||
payment_id: self.payment_id.clone(),
|
payment_id: Some(self.payment_id.clone()),
|
||||||
refund_id: self.id.clone(),
|
refund_id: self.id.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -62,7 +55,10 @@ impl ApiEventMetric for RefundsRetrieveRequest {
|
|||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
impl ApiEventMetric for refunds::RefundsRetrieveRequest {
|
impl ApiEventMetric for refunds::RefundsRetrieveRequest {
|
||||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||||
None
|
Some(ApiEventsType::Refund {
|
||||||
|
payment_id: None,
|
||||||
|
refund_id: self.refund_id.clone(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ pub enum ApiEventsType {
|
|||||||
},
|
},
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
Refund {
|
Refund {
|
||||||
payment_id: id_type::GlobalPaymentId,
|
payment_id: Option<id_type::GlobalPaymentId>,
|
||||||
refund_id: id_type::GlobalRefundId,
|
refund_id: id_type::GlobalRefundId,
|
||||||
},
|
},
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
|
|||||||
@ -811,7 +811,7 @@ impl common_utils::events::ApiEventMetric for Refund {
|
|||||||
impl common_utils::events::ApiEventMetric for Refund {
|
impl common_utils::events::ApiEventMetric for Refund {
|
||||||
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
|
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
|
||||||
Some(common_utils::events::ApiEventsType::Refund {
|
Some(common_utils::events::ApiEventsType::Refund {
|
||||||
payment_id: self.payment_id.clone(),
|
payment_id: Some(self.payment_id.clone()),
|
||||||
refund_id: self.id.clone(),
|
refund_id: self.id.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,7 @@ pub async fn refund_create_core(
|
|||||||
state: SessionState,
|
state: SessionState,
|
||||||
merchant_context: domain::MerchantContext,
|
merchant_context: domain::MerchantContext,
|
||||||
req: refunds::RefundsCreateRequest,
|
req: refunds::RefundsCreateRequest,
|
||||||
|
global_refund_id: id_type::GlobalRefundId,
|
||||||
) -> errors::RouterResponse<refunds::RefundResponse> {
|
) -> errors::RouterResponse<refunds::RefundResponse> {
|
||||||
let db = &*state.store;
|
let db = &*state.store;
|
||||||
let (payment_intent, payment_attempt, amount);
|
let (payment_intent, payment_attempt, amount);
|
||||||
@ -94,8 +95,6 @@ pub async fn refund_create_core(
|
|||||||
.await
|
.await
|
||||||
.to_not_found_response(errors::ApiErrorResponse::SuccessfulPaymentNotFound)?;
|
.to_not_found_response(errors::ApiErrorResponse::SuccessfulPaymentNotFound)?;
|
||||||
|
|
||||||
let global_refund_id = id_type::GlobalRefundId::generate(&state.conf.cell_information.id);
|
|
||||||
|
|
||||||
tracing::Span::current().record("global_refund_id", global_refund_id.get_string_repr());
|
tracing::Span::current().record("global_refund_id", global_refund_id.get_string_repr());
|
||||||
|
|
||||||
Box::pin(validate_and_create_refund(
|
Box::pin(validate_and_create_refund(
|
||||||
|
|||||||
@ -35,12 +35,11 @@ mod internal_payload_types {
|
|||||||
{
|
{
|
||||||
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
|
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
|
||||||
let refund_id = self.global_refund_id.clone();
|
let refund_id = self.global_refund_id.clone();
|
||||||
self.payment_id
|
let payment_id = self.payment_id.clone();
|
||||||
.clone()
|
Some(common_utils::events::ApiEventsType::Refund {
|
||||||
.map(|payment_id| common_utils::events::ApiEventsType::Refund {
|
payment_id,
|
||||||
payment_id,
|
refund_id,
|
||||||
refund_id,
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,16 +104,32 @@ pub async fn refunds_create(
|
|||||||
) -> HttpResponse {
|
) -> HttpResponse {
|
||||||
let flow = Flow::RefundsCreate;
|
let flow = Flow::RefundsCreate;
|
||||||
|
|
||||||
|
let global_refund_id =
|
||||||
|
common_utils::id_type::GlobalRefundId::generate(&state.conf.cell_information.id);
|
||||||
|
let payload = json_payload.into_inner();
|
||||||
|
|
||||||
|
let internal_refund_create_payload =
|
||||||
|
internal_payload_types::RefundsGenericRequestWithResourceId {
|
||||||
|
global_refund_id: global_refund_id.clone(),
|
||||||
|
payment_id: Some(payload.payment_id.clone()),
|
||||||
|
payload,
|
||||||
|
};
|
||||||
|
|
||||||
Box::pin(api::server_wrap(
|
Box::pin(api::server_wrap(
|
||||||
flow,
|
flow,
|
||||||
state,
|
state,
|
||||||
&req,
|
&req,
|
||||||
json_payload.into_inner(),
|
internal_refund_create_payload,
|
||||||
|state, auth: auth::AuthenticationData, req, _| {
|
|state, auth: auth::AuthenticationData, req, _| {
|
||||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||||
domain::Context(auth.merchant_account, auth.key_store),
|
domain::Context(auth.merchant_account, auth.key_store),
|
||||||
));
|
));
|
||||||
refund_create_core(state, merchant_context, req)
|
refund_create_core(
|
||||||
|
state,
|
||||||
|
merchant_context,
|
||||||
|
req.payload,
|
||||||
|
global_refund_id.clone(),
|
||||||
|
)
|
||||||
},
|
},
|
||||||
auth::auth_type(
|
auth::auth_type(
|
||||||
&auth::V2ApiKeyAuth {
|
&auth::V2ApiKeyAuth {
|
||||||
|
|||||||
Reference in New Issue
Block a user