mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 01:57:45 +08:00 
			
		
		
		
	refactor(payment_id): add payment id domain type (#5738)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		| @ -206,7 +206,9 @@ pub enum StripeErrorCode { | ||||
|     PaymentIntentMandateInvalid { message: String }, | ||||
|  | ||||
|     #[error(error_type = StripeErrorType::InvalidRequestError, code = "", message = "The payment with the specified payment_id already exists in our records.")] | ||||
|     DuplicatePayment { payment_id: String }, | ||||
|     DuplicatePayment { | ||||
|         payment_id: common_utils::id_type::PaymentId, | ||||
|     }, | ||||
|  | ||||
|     #[error(error_type = StripeErrorType::ConnectorError, code = "", message = "{code}: {message}")] | ||||
|     ExternalConnectorError { | ||||
|  | ||||
| @ -36,7 +36,14 @@ pub async fn payment_intents_create( | ||||
|         Err(err) => return api::log_and_return_error_response(err), | ||||
|     }; | ||||
|  | ||||
|     tracing::Span::current().record("payment_id", payload.id.clone().unwrap_or_default()); | ||||
|     tracing::Span::current().record( | ||||
|         "payment_id", | ||||
|         payload | ||||
|             .id | ||||
|             .as_ref() | ||||
|             .map(|payment_id| payment_id.get_string_repr()) | ||||
|             .unwrap_or_default(), | ||||
|     ); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?payload); | ||||
|  | ||||
| @ -91,11 +98,11 @@ pub async fn payment_intents_create( | ||||
| pub async fn payment_intents_retrieve( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     req: HttpRequest, | ||||
|     path: web::Path<String>, | ||||
|     path: web::Path<common_utils::id_type::PaymentId>, | ||||
|     query_payload: web::Query<types::StripePaymentRetrieveBody>, | ||||
| ) -> HttpResponse { | ||||
|     let payload = payment_types::PaymentsRetrieveRequest { | ||||
|         resource_id: api_types::PaymentIdType::PaymentIntentId(path.to_string()), | ||||
|         resource_id: api_types::PaymentIdType::PaymentIntentId(path.into_inner()), | ||||
|         merchant_id: None, | ||||
|         force_sync: true, | ||||
|         connector: None, | ||||
| @ -166,9 +173,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds( | ||||
|     }; | ||||
|  | ||||
|     let payload = payment_types::PaymentsRetrieveRequest { | ||||
|         resource_id: payment_types::PaymentIdType::PaymentIntentId( | ||||
|             json_payload.payment_id.to_string(), | ||||
|         ), | ||||
|         resource_id: payment_types::PaymentIdType::PaymentIntentId(json_payload.payment_id), | ||||
|         merchant_id: json_payload.merchant_id.clone(), | ||||
|         force_sync: json_payload.force_sync.unwrap_or(false), | ||||
|         merchant_connector_details: json_payload.merchant_connector_details.clone(), | ||||
| @ -229,7 +234,7 @@ pub async fn payment_intents_update( | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
|     req: HttpRequest, | ||||
|     form_payload: web::Bytes, | ||||
|     path: web::Path<String>, | ||||
|     path: web::Path<common_utils::id_type::PaymentId>, | ||||
| ) -> HttpResponse { | ||||
|     let payment_id = path.into_inner(); | ||||
|     let stripe_payload: types::StripePaymentIntentRequest = match qs_config | ||||
| @ -298,7 +303,7 @@ pub async fn payment_intents_confirm( | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
|     req: HttpRequest, | ||||
|     form_payload: web::Bytes, | ||||
|     path: web::Path<String>, | ||||
|     path: web::Path<common_utils::id_type::PaymentId>, | ||||
| ) -> HttpResponse { | ||||
|     let payment_id = path.into_inner(); | ||||
|     let stripe_payload: types::StripePaymentIntentRequest = match qs_config | ||||
| @ -310,7 +315,10 @@ pub async fn payment_intents_confirm( | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     tracing::Span::current().record("payment_id", stripe_payload.id.as_ref()); | ||||
|     tracing::Span::current().record( | ||||
|         "payment_id", | ||||
|         stripe_payload.id.as_ref().map(|id| id.get_string_repr()), | ||||
|     ); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?stripe_payload); | ||||
|  | ||||
| @ -373,7 +381,7 @@ pub async fn payment_intents_capture( | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
|     req: HttpRequest, | ||||
|     form_payload: web::Bytes, | ||||
|     path: web::Path<String>, | ||||
|     path: web::Path<common_utils::id_type::PaymentId>, | ||||
| ) -> HttpResponse { | ||||
|     let stripe_payload: payment_types::PaymentsCaptureRequest = match qs_config | ||||
|         .deserialize_bytes(&form_payload) | ||||
| @ -384,7 +392,7 @@ pub async fn payment_intents_capture( | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     tracing::Span::current().record("payment_id", stripe_payload.payment_id.clone()); | ||||
|     tracing::Span::current().record("payment_id", stripe_payload.payment_id.get_string_repr()); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?stripe_payload); | ||||
|  | ||||
| @ -437,7 +445,7 @@ pub async fn payment_intents_cancel( | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
|     req: HttpRequest, | ||||
|     form_payload: web::Bytes, | ||||
|     path: web::Path<String>, | ||||
|     path: web::Path<common_utils::id_type::PaymentId>, | ||||
| ) -> HttpResponse { | ||||
|     let payment_id = path.into_inner(); | ||||
|     let stripe_payload: types::StripePaymentCancelRequest = match qs_config | ||||
| @ -449,7 +457,7 @@ pub async fn payment_intents_cancel( | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     tracing::Span::current().record("payment_id", payment_id.clone()); | ||||
|     tracing::Span::current().record("payment_id", payment_id.get_string_repr()); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?stripe_payload); | ||||
|  | ||||
|  | ||||
| @ -244,7 +244,7 @@ pub struct OnlineMandate { | ||||
|  | ||||
| #[derive(Deserialize, Clone, Debug)] | ||||
| pub struct StripePaymentIntentRequest { | ||||
|     pub id: Option<String>, | ||||
|     pub id: Option<id_type::PaymentId>, | ||||
|     pub amount: Option<i64>, // amount in cents, hence passed as integer | ||||
|     pub connector: Option<Vec<api_enums::RoutableConnectors>>, | ||||
|     pub currency: Option<String>, | ||||
| @ -462,7 +462,7 @@ impl From<StripePaymentCancelRequest> for payments::PaymentsCancelRequest { | ||||
|  | ||||
| #[derive(Default, Eq, PartialEq, Serialize, Debug)] | ||||
| pub struct StripePaymentIntentResponse { | ||||
|     pub id: String, | ||||
|     pub id: id_type::PaymentId, | ||||
|     pub object: &'static str, | ||||
|     pub amount: i64, | ||||
|     pub amount_received: Option<i64>, | ||||
| @ -615,8 +615,8 @@ impl Charges { | ||||
| #[serde(deny_unknown_fields)] | ||||
| pub struct StripePaymentListConstraints { | ||||
|     pub customer: Option<id_type::CustomerId>, | ||||
|     pub starting_after: Option<String>, | ||||
|     pub ending_before: Option<String>, | ||||
|     pub starting_after: Option<id_type::PaymentId>, | ||||
|     pub ending_before: Option<id_type::PaymentId>, | ||||
|     #[serde(default = "default_limit")] | ||||
|     pub limit: u32, | ||||
|     pub created: Option<i64>, | ||||
|  | ||||
| @ -27,7 +27,7 @@ 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()); | ||||
|     tracing::Span::current().record("payment_id", payload.payment_intent.get_string_repr()); | ||||
|  | ||||
|     logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?payload); | ||||
|  | ||||
|  | ||||
| @ -9,7 +9,7 @@ use crate::types::api::{admin, refunds}; | ||||
| pub struct StripeCreateRefundRequest { | ||||
|     pub refund_id: Option<String>, | ||||
|     pub amount: Option<i64>, | ||||
|     pub payment_intent: String, | ||||
|     pub payment_intent: common_utils::id_type::PaymentId, | ||||
|     pub reason: Option<String>, | ||||
|     pub metadata: Option<pii::SecretSerdeValue>, | ||||
|     pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>, | ||||
| @ -27,7 +27,7 @@ pub struct StripeRefundResponse { | ||||
|     pub id: String, | ||||
|     pub amount: i64, | ||||
|     pub currency: String, | ||||
|     pub payment_intent: String, | ||||
|     pub payment_intent: common_utils::id_type::PaymentId, | ||||
|     pub status: StripeRefundStatus, | ||||
|     pub created: Option<i64>, | ||||
|     pub metadata: pii::SecretSerdeValue, | ||||
|  | ||||
| @ -90,11 +90,11 @@ pub async fn setup_intents_create( | ||||
| pub async fn setup_intents_retrieve( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     req: HttpRequest, | ||||
|     path: web::Path<String>, | ||||
|     path: web::Path<common_utils::id_type::PaymentId>, | ||||
|     query_payload: web::Query<stripe_payment_types::StripePaymentRetrieveBody>, | ||||
| ) -> HttpResponse { | ||||
|     let payload = payment_types::PaymentsRetrieveRequest { | ||||
|         resource_id: api_types::PaymentIdType::PaymentIntentId(path.to_string()), | ||||
|         resource_id: api_types::PaymentIdType::PaymentIntentId(path.into_inner()), | ||||
|         merchant_id: None, | ||||
|         force_sync: true, | ||||
|         connector: None, | ||||
| @ -155,7 +155,7 @@ pub async fn setup_intents_update( | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
|     req: HttpRequest, | ||||
|     form_payload: web::Bytes, | ||||
|     path: web::Path<String>, | ||||
|     path: web::Path<common_utils::id_type::PaymentId>, | ||||
| ) -> HttpResponse { | ||||
|     let setup_id = path.into_inner(); | ||||
|     let stripe_payload: types::StripeSetupIntentRequest = match qs_config | ||||
| @ -230,7 +230,7 @@ pub async fn setup_intents_confirm( | ||||
|     qs_config: web::Data<serde_qs::Config>, | ||||
|     req: HttpRequest, | ||||
|     form_payload: web::Bytes, | ||||
|     path: web::Path<String>, | ||||
|     path: web::Path<common_utils::id_type::PaymentId>, | ||||
| ) -> HttpResponse { | ||||
|     let setup_id = path.into_inner(); | ||||
|     let stripe_payload: types::StripeSetupIntentRequest = match qs_config | ||||
|  | ||||
| @ -451,7 +451,7 @@ pub(crate) fn into_stripe_next_action( | ||||
|  | ||||
| #[derive(Default, Eq, PartialEq, Serialize)] | ||||
| pub struct StripeSetupIntentResponse { | ||||
|     pub id: String, | ||||
|     pub id: id_type::PaymentId, | ||||
|     pub object: String, | ||||
|     pub status: StripeSetupStatus, | ||||
|     pub client_secret: Option<masking::Secret<String>>, | ||||
| @ -536,8 +536,8 @@ impl From<payments::PaymentsResponse> for StripeSetupIntentResponse { | ||||
| #[serde(deny_unknown_fields)] | ||||
| pub struct StripePaymentListConstraints { | ||||
|     pub customer: Option<id_type::CustomerId>, | ||||
|     pub starting_after: Option<String>, | ||||
|     pub ending_before: Option<String>, | ||||
|     pub starting_after: Option<id_type::PaymentId>, | ||||
|     pub ending_before: Option<id_type::PaymentId>, | ||||
|     #[serde(default = "default_limit")] | ||||
|     pub limit: u32, | ||||
|     pub created: Option<i64>, | ||||
|  | ||||
| @ -94,7 +94,7 @@ pub struct StripeDisputeResponse { | ||||
|     pub id: String, | ||||
|     pub amount: String, | ||||
|     pub currency: String, | ||||
|     pub payment_intent: String, | ||||
|     pub payment_intent: common_utils::id_type::PaymentId, | ||||
|     pub reason: Option<String>, | ||||
|     pub status: StripeDisputeStatus, | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Narayan Bhat
					Narayan Bhat