mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-29 00:49:42 +08:00 
			
		
		
		
	fix(router): remove attempt_count in payments list response and add it in payments response (#2008)
				
					
				
			This commit is contained in:
		 Sai Harsha Vardhan
					Sai Harsha Vardhan
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							aeebc5b525
						
					
				
				
					commit
					23b8d3412c
				
			| @ -1905,6 +1905,9 @@ pub struct PaymentsResponse { | ||||
|  | ||||
|     /// The business profile that is associated with this payment | ||||
|     pub profile_id: Option<String>, | ||||
|  | ||||
|     /// total number of attempts associated with this payment | ||||
|     pub attempt_count: i16, | ||||
| } | ||||
|  | ||||
| #[derive(Clone, Debug, serde::Deserialize, ToSchema)] | ||||
| @ -1970,8 +1973,6 @@ pub struct PaymentListConstraints { | ||||
| pub struct PaymentListResponse { | ||||
|     /// The number of payments included in the list | ||||
|     pub size: usize, | ||||
|     /// The total number of payment_attempts for intents included in the list | ||||
|     pub attempt_count: i16, | ||||
|     // The list of payments response objects | ||||
|     pub data: Vec<PaymentsResponse>, | ||||
| } | ||||
|  | ||||
| @ -1262,11 +1262,6 @@ pub async fn list_payments( | ||||
|             .await | ||||
|             .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; | ||||
|  | ||||
|     let attempt_count = payment_intents | ||||
|         .iter() | ||||
|         .map(|intent| intent.attempt_count) | ||||
|         .sum(); | ||||
|  | ||||
|     let collected_futures = payment_intents.into_iter().map(|pi| { | ||||
|         async { | ||||
|             match db | ||||
| @ -1314,7 +1309,6 @@ pub async fn list_payments( | ||||
|     Ok(services::ApplicationResponse::Json( | ||||
|         api::PaymentListResponse { | ||||
|             size: data.len(), | ||||
|             attempt_count, | ||||
|             data, | ||||
|         }, | ||||
|     )) | ||||
| @ -1341,15 +1335,12 @@ pub async fn apply_filters_on_payments( | ||||
|         .map(|(pi, pa)| (pi, pa.to_storage_model())) | ||||
|         .collect(); | ||||
|  | ||||
|     let attempt_count = list.iter().map(|item| item.0.attempt_count).sum(); | ||||
|  | ||||
|     let data: Vec<api::PaymentsResponse> = | ||||
|         list.into_iter().map(ForeignFrom::foreign_from).collect(); | ||||
|  | ||||
|     Ok(services::ApplicationResponse::Json( | ||||
|         api::PaymentListResponse { | ||||
|             size: data.len(), | ||||
|             attempt_count, | ||||
|             data, | ||||
|         }, | ||||
|     )) | ||||
|  | ||||
| @ -601,6 +601,7 @@ where | ||||
|                         .set_connector_metadata(payment_intent.connector_metadata) | ||||
|                         .set_reference_id(payment_attempt.connector_response_reference_id) | ||||
|                         .set_profile_id(payment_intent.profile_id) | ||||
|                         .set_attempt_count(payment_intent.attempt_count) | ||||
|                         .to_owned(), | ||||
|                     headers, | ||||
|                 )) | ||||
| @ -658,6 +659,7 @@ where | ||||
|                 connector_metadata: payment_intent.connector_metadata, | ||||
|                 allowed_payment_method_types: payment_intent.allowed_payment_method_types, | ||||
|                 reference_id: payment_attempt.connector_response_reference_id, | ||||
|                 attempt_count: payment_intent.attempt_count, | ||||
|                 ..Default::default() | ||||
|             }, | ||||
|             headers, | ||||
| @ -761,6 +763,7 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay | ||||
|             capture_method: pa.capture_method, | ||||
|             authentication_type: pa.authentication_type, | ||||
|             connector_transaction_id: pa.connector_transaction_id, | ||||
|             attempt_count: pi.attempt_count, | ||||
|             ..Default::default() | ||||
|         } | ||||
|     } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user