Skip to content

Commit

Permalink
feat(analytics): add force retrieve call for force retrieve calls (#3565
Browse files Browse the repository at this point in the history
)

Co-authored-by: harsh-sharma-juspay <[email protected]>
  • Loading branch information
sagarnaikjuspay and harsh-sharma-juspay authored Feb 28, 2024
1 parent ffbe042 commit 032d58c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 19 deletions.
14 changes: 10 additions & 4 deletions crates/router/src/compatibility/stripe/payment_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<routes::AppState>,
req: HttpRequest,
Expand All @@ -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::<
_,
Expand Down Expand Up @@ -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<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
Expand Down Expand Up @@ -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::<
_,
Expand Down
15 changes: 10 additions & 5 deletions crates/router/src/compatibility/stripe/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,27 @@ 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<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
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)))
{
Ok(payload) => payload,
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::<
_,
Expand Down Expand Up @@ -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<routes::AppState>,
req: HttpRequest,
Expand All @@ -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::<
_,
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/compatibility/stripe/setup_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<routes::AppState>,
req: HttpRequest,
Expand All @@ -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::<
_,
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/routes/lock_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl From<Flow> for ApiIdentifier {

Flow::PaymentsCreate
| Flow::PaymentsRetrieve
| Flow::PaymentsRetrieveForceSync
| Flow::PaymentsUpdate
| Flow::PaymentsConfirm
| Flow::PaymentsCapture
Expand All @@ -124,6 +125,7 @@ impl From<Flow> for ApiIdentifier {

Flow::RefundsCreate
| Flow::RefundsRetrieve
| Flow::RefundsRetrieveForceSync
| Flow::RefundsUpdate
| Flow::RefundsList => Self::Refunds,

Expand Down
16 changes: 12 additions & 4 deletions crates/router/src/routes/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,18 @@ 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<app::AppState>,
req: actix_web::HttpRequest,
path: web::Path<String>,
json_payload: web::Query<payment_types::PaymentRetrieveBody>,
) -> 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(),
Expand All @@ -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) {
Expand Down Expand Up @@ -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<app::AppState>,
Expand All @@ -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());

Expand Down
19 changes: 15 additions & 4 deletions crates/router/src/routes/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppState>,
Expand All @@ -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,
Expand Down Expand Up @@ -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<AppState>,
req: HttpRequest,
json_payload: web::Json<refunds::RefundsRetrieveRequest>,
) -> 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,
Expand Down
4 changes: 4 additions & 0 deletions crates/router_env/src/logger/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 032d58c

Please sign in to comment.