mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	fix(core): fix amount capturable in payments response (#1437)
This commit is contained in:
		| @ -284,7 +284,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData | ||||
|     } | ||||
| } | ||||
|  | ||||
| async fn payment_response_update_tracker<F: Clone, T>( | ||||
| async fn payment_response_update_tracker<F: Clone, T: types::Capturable>( | ||||
|     db: &dyn StorageInterface, | ||||
|     _payment_id: &api::PaymentIdType, | ||||
|     mut payment_data: PaymentData<F>, | ||||
| @ -428,10 +428,11 @@ async fn payment_response_update_tracker<F: Clone, T>( | ||||
|             .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?, | ||||
|         None => payment_data.connector_response, | ||||
|     }; | ||||
|     let amount = router_data.request.get_capture_amount(); | ||||
|  | ||||
|     let amount_captured = router_data.amount_captured.or_else(|| { | ||||
|         if router_data.status == enums::AttemptStatus::Charged { | ||||
|             Some(payment_data.payment_intent.amount) | ||||
|             amount | ||||
|         } else { | ||||
|             None | ||||
|         } | ||||
|  | ||||
| @ -361,13 +361,15 @@ where | ||||
|                     }) | ||||
|                     .transpose() | ||||
|                     .unwrap_or_default(); | ||||
|                 let amount_captured = payment_intent.amount_captured.unwrap_or_default(); | ||||
|                 let amount_capturable = Some(payment_attempt.amount - amount_captured); | ||||
|                 services::ApplicationResponse::Json( | ||||
|                     response | ||||
|                         .set_payment_id(Some(payment_attempt.payment_id)) | ||||
|                         .set_merchant_id(Some(payment_attempt.merchant_id)) | ||||
|                         .set_status(payment_intent.status.foreign_into()) | ||||
|                         .set_amount(payment_attempt.amount) | ||||
|                         .set_amount_capturable(None) | ||||
|                         .set_amount_capturable(amount_capturable) | ||||
|                         .set_amount_received(payment_intent.amount_captured) | ||||
|                         .set_connector(routed_through) | ||||
|                         .set_client_secret(payment_intent.client_secret.map(masking::Secret::new)) | ||||
|  | ||||
| @ -347,6 +347,34 @@ pub struct AccessTokenRequestData { | ||||
|     // Add more keys if required | ||||
| } | ||||
|  | ||||
| pub trait Capturable { | ||||
|     fn get_capture_amount(&self) -> Option<i64> { | ||||
|         Some(0) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Capturable for PaymentsAuthorizeData { | ||||
|     fn get_capture_amount(&self) -> Option<i64> { | ||||
|         Some(self.amount) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Capturable for PaymentsCaptureData { | ||||
|     fn get_capture_amount(&self) -> Option<i64> { | ||||
|         Some(self.amount_to_capture) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Capturable for CompleteAuthorizeData { | ||||
|     fn get_capture_amount(&self) -> Option<i64> { | ||||
|         Some(self.amount) | ||||
|     } | ||||
| } | ||||
| impl Capturable for VerifyRequestData {} | ||||
| impl Capturable for PaymentsCancelData {} | ||||
| impl Capturable for PaymentsSessionData {} | ||||
| impl Capturable for PaymentsSyncData {} | ||||
|  | ||||
| pub struct AddAccessTokenResult { | ||||
|     pub access_token_result: Result<Option<AccessToken>, ErrorResponse>, | ||||
|     pub connector_supports_access_token: bool, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Prasunna Soppa
					Prasunna Soppa