mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(router): add disputes block in payments retrieve response (#1038)
This commit is contained in:
		 Sai Harsha Vardhan
					Sai Harsha Vardhan
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							7c7185bc1a
						
					
				
				
					commit
					1304d912e5
				
			| @ -860,6 +860,7 @@ where | ||||
|     pub force_sync: Option<bool>, | ||||
|     pub payment_method_data: Option<api::PaymentMethodData>, | ||||
|     pub refunds: Vec<storage::Refund>, | ||||
|     pub disputes: Vec<storage::Dispute>, | ||||
|     pub sessions_token: Vec<api::SessionToken>, | ||||
|     pub card_cvc: Option<Secret<String>>, | ||||
|     pub email: Option<Email>, | ||||
|  | ||||
| @ -144,6 +144,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCancelRequest> | ||||
|                 payment_method_data: None, | ||||
|                 force_sync: None, | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 connector_response, | ||||
|                 sessions_token: vec![], | ||||
|                 card_cvc: None, | ||||
|  | ||||
| @ -150,6 +150,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu | ||||
|                 confirm: None, | ||||
|                 payment_method_data: None, | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 connector_response, | ||||
|                 sessions_token: vec![], | ||||
|                 card_cvc: None, | ||||
|  | ||||
| @ -188,6 +188,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co | ||||
|                 payment_method_data: request.payment_method_data.clone(), | ||||
|                 force_sync: None, | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 sessions_token: vec![], | ||||
|                 card_cvc: request.card_cvc.clone(), | ||||
|                 creds_identifier: None, | ||||
|  | ||||
| @ -207,6 +207,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa | ||||
|                 payment_method_data: request.payment_method_data.clone(), | ||||
|                 force_sync: None, | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 sessions_token: vec![], | ||||
|                 card_cvc: request.card_cvc.clone(), | ||||
|                 creds_identifier, | ||||
|  | ||||
| @ -230,6 +230,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa | ||||
|                 confirm: request.confirm, | ||||
|                 payment_method_data: request.payment_method_data.clone(), | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 force_sync: None, | ||||
|                 connector_response, | ||||
|                 sessions_token: vec![], | ||||
|  | ||||
| @ -172,6 +172,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::VerifyRequest> for Paym | ||||
|                 address: types::PaymentAddress::default(), | ||||
|                 force_sync: None, | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 sessions_token: vec![], | ||||
|                 card_cvc: None, | ||||
|                 creds_identifier, | ||||
|  | ||||
| @ -164,6 +164,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest> | ||||
|                 payment_method_data: None, | ||||
|                 force_sync: None, | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 sessions_token: vec![], | ||||
|                 connector_response, | ||||
|                 card_cvc: None, | ||||
|  | ||||
| @ -136,6 +136,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> f | ||||
|                 payment_method_data: None, | ||||
|                 force_sync: None, | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 sessions_token: vec![], | ||||
|                 card_cvc: None, | ||||
|                 creds_identifier: None, | ||||
|  | ||||
| @ -229,6 +229,14 @@ async fn get_tracker_for_sync< | ||||
|             ) | ||||
|         })?; | ||||
|  | ||||
|     let disputes = db | ||||
|         .find_disputes_by_merchant_id_payment_id(merchant_id, &payment_id_str) | ||||
|         .await | ||||
|         .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|         .attach_printable_lazy(|| { | ||||
|             format!("Error while retrieving dispute list for, merchant_id: {merchant_id}, payment_id: {payment_id_str}") | ||||
|         })?; | ||||
|  | ||||
|     let contains_encoded_data = connector_response.encoded_data.is_some(); | ||||
|  | ||||
|     let creds_identifier = request | ||||
| @ -275,6 +283,7 @@ async fn get_tracker_for_sync< | ||||
|             ), | ||||
|             payment_attempt, | ||||
|             refunds, | ||||
|             disputes, | ||||
|             sessions_token: vec![], | ||||
|             card_cvc: None, | ||||
|             creds_identifier, | ||||
|  | ||||
| @ -287,6 +287,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa | ||||
|                 payment_method_data: request.payment_method_data.clone(), | ||||
|                 force_sync: None, | ||||
|                 refunds: vec![], | ||||
|                 disputes: vec![], | ||||
|                 connector_response, | ||||
|                 sessions_token: vec![], | ||||
|                 card_cvc: request.card_cvc.clone(), | ||||
|  | ||||
| @ -151,6 +151,7 @@ where | ||||
|             payment_data.payment_attempt, | ||||
|             payment_data.payment_intent, | ||||
|             payment_data.refunds, | ||||
|             payment_data.disputes, | ||||
|             payment_data.payment_method_data, | ||||
|             customer, | ||||
|             auth_flow, | ||||
| @ -240,6 +241,7 @@ pub fn payments_to_payments_response<R, Op>( | ||||
|     payment_attempt: storage::PaymentAttempt, | ||||
|     payment_intent: storage::PaymentIntent, | ||||
|     refunds: Vec<storage::Refund>, | ||||
|     disputes: Vec<storage::Dispute>, | ||||
|     payment_method_data: Option<api::PaymentMethodData>, | ||||
|     customer: Option<storage::Customer>, | ||||
|     auth_flow: services::AuthFlow, | ||||
| @ -266,6 +268,16 @@ where | ||||
|     } else { | ||||
|         Some(refunds.into_iter().map(ForeignInto::foreign_into).collect()) | ||||
|     }; | ||||
|     let disputes_response = if disputes.is_empty() { | ||||
|         None | ||||
|     } else { | ||||
|         Some( | ||||
|             disputes | ||||
|                 .into_iter() | ||||
|                 .map(ForeignInto::foreign_into) | ||||
|                 .collect(), | ||||
|         ) | ||||
|     }; | ||||
|  | ||||
|     Ok(match payment_request { | ||||
|         Some(_request) => { | ||||
| @ -346,6 +358,7 @@ where | ||||
|                         .set_mandate_id(mandate_id) | ||||
|                         .set_description(payment_intent.description) | ||||
|                         .set_refunds(refunds_response) // refunds.iter().map(refund_to_refund_response), | ||||
|                         .set_disputes(disputes_response) | ||||
|                         .set_payment_method( | ||||
|                             payment_attempt | ||||
|                                 .payment_method | ||||
| @ -417,6 +430,7 @@ where | ||||
|             customer_id: payment_intent.customer_id, | ||||
|             description: payment_intent.description, | ||||
|             refunds: refunds_response, | ||||
|             disputes: disputes_response, | ||||
|             payment_method: payment_attempt | ||||
|                 .payment_method | ||||
|                 .map(ForeignInto::foreign_into), | ||||
|  | ||||
| @ -256,8 +256,8 @@ async fn get_or_update_dispute_object( | ||||
|                 connector_reason: dispute_details.connector_reason, | ||||
|                 connector_reason_code: dispute_details.connector_reason_code, | ||||
|                 challenge_required_by: dispute_details.challenge_required_by, | ||||
|                 dispute_created_at: dispute_details.created_at, | ||||
|                 updated_at: dispute_details.updated_at, | ||||
|                 connector_created_at: dispute_details.created_at, | ||||
|                 connector_updated_at: dispute_details.updated_at, | ||||
|             }; | ||||
|             state | ||||
|                 .store | ||||
| @ -285,7 +285,7 @@ async fn get_or_update_dispute_object( | ||||
|                 connector_reason: dispute_details.connector_reason, | ||||
|                 connector_reason_code: dispute_details.connector_reason_code, | ||||
|                 challenge_required_by: dispute_details.challenge_required_by, | ||||
|                 updated_at: dispute_details.updated_at, | ||||
|                 connector_updated_at: dispute_details.updated_at, | ||||
|             }; | ||||
|             db.update_dispute(dispute, update_dispute) | ||||
|                 .await | ||||
|  | ||||
| @ -33,6 +33,12 @@ pub trait DisputeInterface { | ||||
|         dispute_constraints: api_models::disputes::DisputeListConstraints, | ||||
|     ) -> CustomResult<Vec<storage::Dispute>, errors::StorageError>; | ||||
|  | ||||
|     async fn find_disputes_by_merchant_id_payment_id( | ||||
|         &self, | ||||
|         merchant_id: &str, | ||||
|         payment_id: &str, | ||||
|     ) -> CustomResult<Vec<storage::Dispute>, errors::StorageError>; | ||||
|  | ||||
|     async fn update_dispute( | ||||
|         &self, | ||||
|         this: storage::Dispute, | ||||
| @ -96,6 +102,18 @@ impl DisputeInterface for Store { | ||||
|             .into_report() | ||||
|     } | ||||
|  | ||||
|     async fn find_disputes_by_merchant_id_payment_id( | ||||
|         &self, | ||||
|         merchant_id: &str, | ||||
|         payment_id: &str, | ||||
|     ) -> CustomResult<Vec<storage::Dispute>, errors::StorageError> { | ||||
|         let conn = connection::pg_connection_read(self).await?; | ||||
|         storage::Dispute::find_by_merchant_id_payment_id(&conn, merchant_id, payment_id) | ||||
|             .await | ||||
|             .map_err(Into::into) | ||||
|             .into_report() | ||||
|     } | ||||
|  | ||||
|     async fn update_dispute( | ||||
|         &self, | ||||
|         this: storage::Dispute, | ||||
| @ -146,6 +164,15 @@ impl DisputeInterface for MockDb { | ||||
|         Err(errors::StorageError::MockDbError)? | ||||
|     } | ||||
|  | ||||
|     async fn find_disputes_by_merchant_id_payment_id( | ||||
|         &self, | ||||
|         _merchant_id: &str, | ||||
|         _payment_id: &str, | ||||
|     ) -> CustomResult<Vec<storage::Dispute>, errors::StorageError> { | ||||
|         // TODO: Implement function for `MockDb` | ||||
|         Err(errors::StorageError::MockDbError)? | ||||
|     } | ||||
|  | ||||
|     async fn update_dispute( | ||||
|         &self, | ||||
|         _this: storage::Dispute, | ||||
|  | ||||
| @ -500,9 +500,27 @@ impl ForeignFrom<storage::Dispute> for api_models::disputes::DisputeResponse { | ||||
|             connector_reason: dispute.connector_reason, | ||||
|             connector_reason_code: dispute.connector_reason_code, | ||||
|             challenge_required_by: dispute.challenge_required_by, | ||||
|             created_at: dispute.dispute_created_at, | ||||
|             updated_at: dispute.updated_at, | ||||
|             received_at: dispute.created_at.to_string(), | ||||
|             connector_created_at: dispute.connector_created_at, | ||||
|             connector_updated_at: dispute.connector_updated_at, | ||||
|             created_at: dispute.created_at, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ForeignFrom<storage::Dispute> for api_models::disputes::DisputeResponsePaymentsRetrieve { | ||||
|     fn foreign_from(dispute: storage::Dispute) -> Self { | ||||
|         Self { | ||||
|             dispute_id: dispute.dispute_id, | ||||
|             dispute_stage: dispute.dispute_stage.foreign_into(), | ||||
|             dispute_status: dispute.dispute_status.foreign_into(), | ||||
|             connector_status: dispute.connector_status, | ||||
|             connector_dispute_id: dispute.connector_dispute_id, | ||||
|             connector_reason: dispute.connector_reason, | ||||
|             connector_reason_code: dispute.connector_reason_code, | ||||
|             challenge_required_by: dispute.challenge_required_by, | ||||
|             connector_created_at: dispute.connector_created_at, | ||||
|             connector_updated_at: dispute.connector_updated_at, | ||||
|             created_at: dispute.created_at, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user