mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(compatibility): added compatibility layer request logs (#3774)
This commit is contained in:
		| @ -2,17 +2,17 @@ pub mod types; | ||||
| use actix_web::{web, HttpRequest, HttpResponse}; | ||||
| use api_models::payments as payment_types; | ||||
| use error_stack::report; | ||||
| use router_env::{instrument, tracing, Flow}; | ||||
| use router_env::{instrument, tracing, Flow, Tag}; | ||||
|  | ||||
| use crate::{ | ||||
|     compatibility::{stripe::errors, wrap}, | ||||
|     core::{api_locking::GetLockingInput, payment_methods::Oss, payments}, | ||||
|     routes, | ||||
|     logger, routes, | ||||
|     services::{api, authentication as auth}, | ||||
|     types::api as api_types, | ||||
| }; | ||||
|  | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] | ||||
| pub async fn payment_intents_create( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
| @ -26,6 +26,9 @@ pub async fn payment_intents_create( | ||||
|         Ok(p) => p, | ||||
|         Err(err) => return api::log_and_return_error_response(err), | ||||
|     }; | ||||
|     tracing::Span::current().record("payment_id", &payload.id.clone().unwrap_or_default()); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?payload); | ||||
|  | ||||
|     let create_payment_req: payment_types::PaymentsRequest = match payload.try_into() { | ||||
|         Ok(req) => req, | ||||
| @ -258,7 +261,7 @@ pub async fn payment_intents_update( | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsConfirm))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] | ||||
| pub async fn payment_intents_confirm( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
| @ -276,6 +279,10 @@ pub async fn payment_intents_confirm( | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     tracing::Span::current().record("payment_id", stripe_payload.id.as_ref()); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?stripe_payload); | ||||
|  | ||||
|     let mut payload: payment_types::PaymentsRequest = match stripe_payload.try_into() { | ||||
|         Ok(req) => req, | ||||
|         Err(err) => return api::log_and_return_error_response(err), | ||||
| @ -326,7 +333,7 @@ pub async fn payment_intents_confirm( | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsCapture))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] | ||||
| pub async fn payment_intents_capture( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
| @ -343,6 +350,10 @@ pub async fn payment_intents_capture( | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     tracing::Span::current().record("payment_id", &stripe_payload.payment_id.clone()); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?stripe_payload); | ||||
|  | ||||
|     let payload = payment_types::PaymentsCaptureRequest { | ||||
|         payment_id: path.into_inner(), | ||||
|         ..stripe_payload | ||||
| @ -383,7 +394,7 @@ pub async fn payment_intents_capture( | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsCancel))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] | ||||
| pub async fn payment_intents_cancel( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
| @ -401,6 +412,10 @@ pub async fn payment_intents_cancel( | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     tracing::Span::current().record("payment_id", &payment_id.clone()); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?stripe_payload); | ||||
|  | ||||
|     let mut payload: payment_types::PaymentsCancelRequest = stripe_payload.into(); | ||||
|     payload.payment_id = payment_id; | ||||
|  | ||||
|  | ||||
| @ -22,7 +22,7 @@ use crate::{ | ||||
|     }, | ||||
| }; | ||||
|  | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone, Debug)] | ||||
| pub struct StripeBillingDetails { | ||||
|     pub address: Option<AddressDetails>, | ||||
|     pub email: Option<Email>, | ||||
| @ -65,7 +65,7 @@ pub struct StripeCard { | ||||
| } | ||||
|  | ||||
| // ApplePay wallet param is not available in stripe Docs | ||||
| #[derive(Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||
| #[derive(Serialize, PartialEq, Eq, Deserialize, Clone, Debug)] | ||||
| #[serde(rename_all = "snake_case")] | ||||
| pub enum StripeWallet { | ||||
|     ApplePay(payments::ApplePayWalletData), | ||||
| @ -95,7 +95,7 @@ impl From<StripePaymentMethodType> for api_enums::PaymentMethod { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | ||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone, Debug)] | ||||
| pub struct StripePaymentMethodData { | ||||
|     #[serde(rename = "type")] | ||||
|     pub stype: StripePaymentMethodType, | ||||
| @ -105,7 +105,7 @@ pub struct StripePaymentMethodData { | ||||
|     pub metadata: Option<SecretSerdeValue>, | ||||
| } | ||||
|  | ||||
| #[derive(PartialEq, Eq, Deserialize, Clone)] | ||||
| #[derive(PartialEq, Eq, Deserialize, Clone, Debug)] | ||||
| #[serde(rename_all = "snake_case")] | ||||
| pub enum StripePaymentMethodDetails { | ||||
|     Card(StripeCard), | ||||
| @ -159,7 +159,7 @@ impl From<StripePaymentMethodDetails> for payments::PaymentMethodData { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone, Debug)] | ||||
| pub struct Shipping { | ||||
|     pub address: AddressDetails, | ||||
|     pub name: Option<masking::Secret<String>>, | ||||
| @ -168,7 +168,7 @@ pub struct Shipping { | ||||
|     pub tracking_number: Option<masking::Secret<String>>, | ||||
| } | ||||
|  | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone, Debug)] | ||||
| pub struct AddressDetails { | ||||
|     pub city: Option<String>, | ||||
|     pub country: Option<api_enums::CountryAlpha2>, | ||||
| @ -201,7 +201,7 @@ impl From<Shipping> for payments::Address { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone, Debug)] | ||||
| pub struct MandateData { | ||||
|     pub customer_acceptance: CustomerAcceptance, | ||||
|     pub mandate_type: Option<StripeMandateType>, | ||||
| @ -212,7 +212,7 @@ pub struct MandateData { | ||||
|     pub end_date: Option<PrimitiveDateTime>, | ||||
| } | ||||
|  | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone, Debug)] | ||||
| pub struct CustomerAcceptance { | ||||
|     #[serde(rename = "type")] | ||||
|     pub acceptance_type: Option<AcceptanceType>, | ||||
| @ -235,7 +235,7 @@ pub struct OnlineMandate { | ||||
|     pub user_agent: String, | ||||
| } | ||||
|  | ||||
| #[derive(Deserialize, Clone)] | ||||
| #[derive(Deserialize, Clone, Debug)] | ||||
| pub struct StripePaymentIntentRequest { | ||||
|     pub id: Option<String>, | ||||
|     pub amount: Option<i64>, // amount in cents, hence passed as integer | ||||
|  | ||||
| @ -1,17 +1,17 @@ | ||||
| pub mod types; | ||||
| use actix_web::{web, HttpRequest, HttpResponse}; | ||||
| use error_stack::report; | ||||
| use router_env::{instrument, tracing, Flow}; | ||||
| use router_env::{instrument, tracing, Flow, Tag}; | ||||
|  | ||||
| use crate::{ | ||||
|     compatibility::{stripe::errors, wrap}, | ||||
|     core::{api_locking, refunds}, | ||||
|     routes, | ||||
|     logger, routes, | ||||
|     services::{api, authentication as auth}, | ||||
|     types::api::refunds as refund_types, | ||||
| }; | ||||
|  | ||||
| #[instrument(skip_all, fields(flow = ?Flow::RefundsCreate))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::RefundsCreate, payment_id))] | ||||
| pub async fn refund_create( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
| @ -26,6 +26,10 @@ pub async fn refund_create( | ||||
|         Err(err) => return api::log_and_return_error_response(err), | ||||
|     }; | ||||
|  | ||||
|     tracing::Span::current().record("payment_id", &payload.payment_intent.clone()); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?payload); | ||||
|  | ||||
|     let create_refund_req: refund_types::RefundRequest = payload.into(); | ||||
|  | ||||
|     let flow = Flow::RefundsCreate; | ||||
|  | ||||
| @ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| use crate::types::api::{admin, refunds}; | ||||
|  | ||||
| #[derive(Clone, Serialize, Deserialize, PartialEq, Eq)] | ||||
| #[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)] | ||||
| pub struct StripeCreateRefundRequest { | ||||
|     pub refund_id: Option<String>, | ||||
|     pub amount: Option<i64>, | ||||
|  | ||||
| @ -49,6 +49,9 @@ pub enum Tag { | ||||
|  | ||||
|     /// Event: general. | ||||
|     Event, | ||||
|  | ||||
|     /// Compatibility Layer Request | ||||
|     CompatibilityLayerRequest, | ||||
| } | ||||
|  | ||||
| /// API Flow | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sahkal Poddar
					Sahkal Poddar