mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	fix(router): add payment_method check in get_mandate_type (#5828)
				
					
				
			This commit is contained in:
		 Sai Harsha Vardhan
					Sai Harsha Vardhan
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							985761cfb3
						
					
				
				
					commit
					1929f56e2a
				
			| @ -51,6 +51,7 @@ pub fn get_mandate_type( | ||||
|     setup_future_usage: Option<enums::FutureUsage>, | ||||
|     customer_acceptance: Option<api_payments::CustomerAcceptance>, | ||||
|     token: Option<String>, | ||||
|     payment_method: Option<enums::PaymentMethod>, | ||||
| ) -> CustomResult<Option<api::MandateTransactionType>, errors::ValidationError> { | ||||
|     match ( | ||||
|         mandate_data.clone(), | ||||
| @ -58,25 +59,28 @@ pub fn get_mandate_type( | ||||
|         setup_future_usage, | ||||
|         customer_acceptance.or(mandate_data.and_then(|m_data| m_data.customer_acceptance)), | ||||
|         token, | ||||
|         payment_method, | ||||
|     ) { | ||||
|         (Some(_), Some(_), Some(enums::FutureUsage::OffSession), Some(_), Some(_)) => { | ||||
|         (Some(_), Some(_), Some(enums::FutureUsage::OffSession), Some(_), Some(_), _) => { | ||||
|             Err(errors::ValidationError::InvalidValue { | ||||
|                 message: "Expected one out of recurring_details and mandate_data but got both" | ||||
|                     .to_string(), | ||||
|             } | ||||
|             .into()) | ||||
|         } | ||||
|         (_, _, Some(enums::FutureUsage::OffSession), Some(_), Some(_)) | ||||
|         | (_, _, Some(enums::FutureUsage::OffSession), Some(_), _) | ||||
|         | (Some(_), _, Some(enums::FutureUsage::OffSession), _, _) => { | ||||
|         (_, _, Some(enums::FutureUsage::OffSession), Some(_), Some(_), _) | ||||
|         | (_, _, Some(enums::FutureUsage::OffSession), Some(_), _, _) | ||||
|         | (Some(_), _, Some(enums::FutureUsage::OffSession), _, _, _) => { | ||||
|             Ok(Some(api::MandateTransactionType::NewMandateTransaction)) | ||||
|         } | ||||
|  | ||||
|         (_, _, Some(enums::FutureUsage::OffSession), _, Some(_)) | ||||
|         | (_, Some(_), _, _, _) | ||||
|         | (_, _, Some(enums::FutureUsage::OffSession), _, _) => Ok(Some( | ||||
|             api::MandateTransactionType::RecurringMandateTransaction, | ||||
|         )), | ||||
|         (_, _, Some(enums::FutureUsage::OffSession), _, Some(_), _) | ||||
|         | (_, Some(_), _, _, _, _) | ||||
|         | (_, _, Some(enums::FutureUsage::OffSession), _, _, Some(enums::PaymentMethod::Wallet)) => { | ||||
|             Ok(Some( | ||||
|                 api::MandateTransactionType::RecurringMandateTransaction, | ||||
|             )) | ||||
|         } | ||||
|  | ||||
|         _ => Ok(None), | ||||
|     } | ||||
|  | ||||
| @ -111,6 +111,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co | ||||
|             payment_intent.setup_future_usage, | ||||
|             request.customer_acceptance.clone(), | ||||
|             request.payment_token.clone(), | ||||
|             payment_attempt.payment_method, | ||||
|         ) | ||||
|         .change_context(errors::ApiErrorResponse::MandateValidationFailed { | ||||
|             reason: "Expected one out of recurring_details and mandate_data but got both".into(), | ||||
|  | ||||
| @ -524,6 +524,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa | ||||
|             payment_intent.setup_future_usage, | ||||
|             request.customer_acceptance.clone(), | ||||
|             request.payment_token.clone(), | ||||
|             payment_attempt.payment_method.or(request.payment_method), | ||||
|         ) | ||||
|         .change_context(errors::ApiErrorResponse::MandateValidationFailed { | ||||
|             reason: "Expected one out of recurring_details and mandate_data but got both".into(), | ||||
|  | ||||
| @ -150,6 +150,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa | ||||
|             request.setup_future_usage, | ||||
|             request.customer_acceptance.clone(), | ||||
|             request.payment_token.clone(), | ||||
|             request.payment_method, | ||||
|         ) | ||||
|         .change_context(errors::ApiErrorResponse::MandateValidationFailed { | ||||
|             reason: "Expected one out of recurring_details and mandate_data but got both".into(), | ||||
|  | ||||
| @ -136,6 +136,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa | ||||
|             payment_intent.setup_future_usage, | ||||
|             request.customer_acceptance.clone(), | ||||
|             request.payment_token.clone(), | ||||
|             payment_attempt.payment_method.or(request.payment_method), | ||||
|         ) | ||||
|         .change_context(errors::ApiErrorResponse::MandateValidationFailed { | ||||
|             reason: "Expected one out of recurring_details and mandate_data but got both".into(), | ||||
|  | ||||
		Reference in New Issue
	
	Block a user