From 032d58cdbbf388cf25cbf2e43b0117b83f7d076d Mon Sep 17 00:00:00 2001 From: Sagar naik Date: Wed, 28 Feb 2024 19:10:20 +0530 Subject: [PATCH] feat(analytics): add force retrieve call for force retrieve calls (#3565) Co-authored-by: harsh-sharma-juspay <125131007+harsh-sharma-juspay@users.noreply.github.com> --- .../compatibility/stripe/payment_intents.rs | 14 ++++++++++---- .../src/compatibility/stripe/refunds.rs | 15 ++++++++++----- .../src/compatibility/stripe/setup_intents.rs | 4 ++-- crates/router/src/routes/lock_utils.rs | 2 ++ crates/router/src/routes/payments.rs | 16 ++++++++++++---- crates/router/src/routes/refunds.rs | 19 +++++++++++++++---- crates/router_env/src/logger/types.rs | 4 ++++ 7 files changed, 55 insertions(+), 19 deletions(-) diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs index d67166c0d0..87560032ea 100644 --- a/crates/router/src/compatibility/stripe/payment_intents.rs +++ b/crates/router/src/compatibility/stripe/payment_intents.rs @@ -71,7 +71,7 @@ pub async fn payment_intents_create( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] pub async fn payment_intents_retrieve( state: web::Data, req: HttpRequest, @@ -96,7 +96,7 @@ pub async fn payment_intents_retrieve( Err(err) => return api::log_and_return_error_response(report!(err)), }; - let flow = Flow::PaymentsRetrieve; + let flow = Flow::PaymentsRetrieveForceSync; let locking_action = payload.get_locking_input(flow.clone()); Box::pin(wrap::compatibility_api_wrap::< _, @@ -131,7 +131,7 @@ pub async fn payment_intents_retrieve( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieve))] +#[instrument(skip_all, fields(flow))] pub async fn payment_intents_retrieve_with_gateway_creds( state: web::Data, qs_config: web::Data, @@ -160,7 +160,13 @@ pub async fn payment_intents_retrieve_with_gateway_creds( Err(err) => return api::log_and_return_error_response(report!(err)), }; - let flow = Flow::PaymentsRetrieve; + let flow = match json_payload.force_sync { + Some(true) => Flow::PaymentsRetrieveForceSync, + _ => Flow::PaymentsRetrieve, + }; + + tracing::Span::current().record("flow", &flow.to_string()); + let locking_action = payload.get_locking_input(flow.clone()); Box::pin(wrap::compatibility_api_wrap::< _, diff --git a/crates/router/src/compatibility/stripe/refunds.rs b/crates/router/src/compatibility/stripe/refunds.rs index 77c3a61fa7..80ebbc4f84 100644 --- a/crates/router/src/compatibility/stripe/refunds.rs +++ b/crates/router/src/compatibility/stripe/refunds.rs @@ -57,14 +57,14 @@ pub async fn refund_create( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::RefundsRetrieve))] +#[instrument(skip_all, fields(flow))] pub async fn refund_retrieve_with_gateway_creds( state: web::Data, qs_config: web::Data, req: HttpRequest, form_payload: web::Bytes, ) -> HttpResponse { - let refund_request = match qs_config + let refund_request: refund_types::RefundsRetrieveRequest = match qs_config .deserialize_bytes(&form_payload) .map_err(|err| report!(errors::StripeErrorCode::from(err))) { @@ -72,7 +72,12 @@ pub async fn refund_retrieve_with_gateway_creds( Err(err) => return api::log_and_return_error_response(err), }; - let flow = Flow::RefundsRetrieve; + let flow = match refund_request.force_sync { + Some(true) => Flow::RefundsRetrieveForceSync, + _ => Flow::RefundsRetrieve, + }; + + tracing::Span::current().record("flow", &flow.to_string()); Box::pin(wrap::compatibility_api_wrap::< _, @@ -103,7 +108,7 @@ pub async fn refund_retrieve_with_gateway_creds( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::RefundsRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::RefundsRetrieveForceSync))] pub async fn refund_retrieve( state: web::Data, req: HttpRequest, @@ -115,7 +120,7 @@ pub async fn refund_retrieve( merchant_connector_details: None, }; - let flow = Flow::RefundsRetrieve; + let flow = Flow::RefundsRetrieveForceSync; Box::pin(wrap::compatibility_api_wrap::< _, diff --git a/crates/router/src/compatibility/stripe/setup_intents.rs b/crates/router/src/compatibility/stripe/setup_intents.rs index 515e41ec91..6522dc4697 100644 --- a/crates/router/src/compatibility/stripe/setup_intents.rs +++ b/crates/router/src/compatibility/stripe/setup_intents.rs @@ -78,7 +78,7 @@ pub async fn setup_intents_create( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] pub async fn setup_intents_retrieve( state: web::Data, req: HttpRequest, @@ -103,7 +103,7 @@ pub async fn setup_intents_retrieve( Err(err) => return api::log_and_return_error_response(report!(err)), }; - let flow = Flow::PaymentsRetrieve; + let flow = Flow::PaymentsRetrieveForceSync; Box::pin(wrap::compatibility_api_wrap::< _, diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rs index edbdee7bf6..b209fd5716 100644 --- a/crates/router/src/routes/lock_utils.rs +++ b/crates/router/src/routes/lock_utils.rs @@ -103,6 +103,7 @@ impl From for ApiIdentifier { Flow::PaymentsCreate | Flow::PaymentsRetrieve + | Flow::PaymentsRetrieveForceSync | Flow::PaymentsUpdate | Flow::PaymentsConfirm | Flow::PaymentsCapture @@ -124,6 +125,7 @@ impl From for ApiIdentifier { Flow::RefundsCreate | Flow::RefundsRetrieve + | Flow::RefundsRetrieveForceSync | Flow::RefundsUpdate | Flow::RefundsList => Self::Refunds, diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs index b822e6d4e6..24849d828e 100644 --- a/crates/router/src/routes/payments.rs +++ b/crates/router/src/routes/payments.rs @@ -229,7 +229,7 @@ pub async fn payments_start( operation_id = "Retrieve a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -#[instrument(skip(state, req), fields(flow = ?Flow::PaymentsRetrieve, payment_id))] +#[instrument(skip(state, req), fields(flow, payment_id))] // #[get("/{payment_id}")] pub async fn payments_retrieve( state: web::Data, @@ -237,7 +237,10 @@ pub async fn payments_retrieve( path: web::Path, json_payload: web::Query, ) -> impl Responder { - let flow = Flow::PaymentsRetrieve; + let flow = match json_payload.force_sync { + Some(true) => Flow::PaymentsRetrieveForceSync, + _ => Flow::PaymentsRetrieve, + }; let payload = payment_types::PaymentsRetrieveRequest { resource_id: payment_types::PaymentIdType::PaymentIntentId(path.to_string()), merchant_id: json_payload.merchant_id.clone(), @@ -249,6 +252,7 @@ pub async fn payments_retrieve( }; tracing::Span::current().record("payment_id", &path.to_string()); + tracing::Span::current().record("flow", &flow.to_string()); let (auth_type, auth_flow) = match auth::check_client_secret_and_get_auth(req.headers(), &payload) { @@ -300,7 +304,7 @@ pub async fn payments_retrieve( operation_id = "Retrieve a Payment", security(("api_key" = [])) )] -#[instrument(skip(state, req), fields(flow = ?Flow::PaymentsRetrieve, payment_id))] +#[instrument(skip(state, req), fields(flow, payment_id))] // #[post("/sync")] pub async fn payments_retrieve_with_gateway_creds( state: web::Data, @@ -320,9 +324,13 @@ pub async fn payments_retrieve_with_gateway_creds( merchant_connector_details: json_payload.merchant_connector_details.clone(), ..Default::default() }; - let flow = Flow::PaymentsRetrieve; + let flow = match json_payload.force_sync { + Some(true) => Flow::PaymentsRetrieveForceSync, + _ => Flow::PaymentsRetrieve, + }; tracing::Span::current().record("payment_id", &json_payload.payment_id); + tracing::Span::current().record("flow", &flow.to_string()); let locking_action = payload.get_locking_input(flow.clone()); diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs index 47e9f2bf42..ef9ffb4112 100644 --- a/crates/router/src/routes/refunds.rs +++ b/crates/router/src/routes/refunds.rs @@ -63,7 +63,7 @@ pub async fn refunds_create( operation_id = "Retrieve a Refund", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::RefundsRetrieve))] +#[instrument(skip_all, fields(flow))] // #[get("/{id}")] pub async fn refunds_retrieve( state: web::Data, @@ -76,7 +76,12 @@ pub async fn refunds_retrieve( force_sync: query_params.force_sync, merchant_connector_details: None, }; - let flow = Flow::RefundsRetrieve; + let flow = match query_params.force_sync { + Some(true) => Flow::RefundsRetrieveForceSync, + _ => Flow::RefundsRetrieve, + }; + + tracing::Span::current().record("flow", &flow.to_string()); Box::pin(api::server_wrap( flow, @@ -115,14 +120,20 @@ pub async fn refunds_retrieve( operation_id = "Retrieve a Refund", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::RefundsRetrieve))] +#[instrument(skip_all, fields(flow))] // #[post("/sync")] pub async fn refunds_retrieve_with_body( state: web::Data, req: HttpRequest, json_payload: web::Json, ) -> HttpResponse { - let flow = Flow::RefundsRetrieve; + let flow = match json_payload.force_sync { + Some(true) => Flow::RefundsRetrieveForceSync, + _ => Flow::RefundsRetrieve, + }; + + tracing::Span::current().record("flow", &flow.to_string()); + Box::pin(api::server_wrap( flow, state, diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rs index 4790e60acb..0814808434 100644 --- a/crates/router_env/src/logger/types.rs +++ b/crates/router_env/src/logger/types.rs @@ -129,6 +129,8 @@ pub enum Flow { PaymentsCreate, /// Payments Retrieve flow. PaymentsRetrieve, + /// Payments Retrieve force sync flow. + PaymentsRetrieveForceSync, /// Payments update flow. PaymentsUpdate, /// Payments confirm flow. @@ -170,6 +172,8 @@ pub enum Flow { RefundsCreate, /// Refunds retrieve flow. RefundsRetrieve, + /// Refunds retrieve force sync flow. + RefundsRetrieveForceSync, /// Refunds update flow. RefundsUpdate, /// Refunds list flow.