mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(router): Add v2 endpoint to retrieve payment filters at merchant and profile level (#7171)
Co-authored-by: Aniket Burman <aniket.burman@Aniket-Burman-JDXHW2PH34.local> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		| @ -5459,7 +5459,7 @@ pub async fn get_filters_for_payments( | ||||
|     )) | ||||
| } | ||||
|  | ||||
| #[cfg(all(feature = "olap", feature = "v1"))] | ||||
| #[cfg(feature = "olap")] | ||||
| pub async fn get_payment_filters( | ||||
|     state: SessionState, | ||||
|     merchant: domain::MerchantAccount, | ||||
| @ -5489,12 +5489,12 @@ pub async fn get_payment_filters( | ||||
|                 .as_ref() | ||||
|                 .map(|label| { | ||||
|                     let info = merchant_connector_account.to_merchant_connector_info(label); | ||||
|                     (merchant_connector_account.connector_name.clone(), info) | ||||
|                     (merchant_connector_account.get_connector_name(), info) | ||||
|                 }) | ||||
|         }) | ||||
|         .for_each(|(connector_name, info)| { | ||||
|             connector_map | ||||
|                 .entry(connector_name.clone()) | ||||
|                 .entry(connector_name.to_string()) | ||||
|                 .or_default() | ||||
|                 .push(info); | ||||
|         }); | ||||
| @ -5510,22 +5510,30 @@ pub async fn get_payment_filters( | ||||
|                 .iter() | ||||
|                 .filter_map(|payment_method_enabled| { | ||||
|                     payment_method_enabled | ||||
|                         .payment_method_types | ||||
|                         .as_ref() | ||||
|                         .map(|types_vec| (payment_method_enabled.payment_method, types_vec.clone())) | ||||
|                         .get_payment_method_type() | ||||
|                         .map(|types_vec| { | ||||
|                             ( | ||||
|                                 payment_method_enabled.get_payment_method(), | ||||
|                                 types_vec.clone(), | ||||
|                             ) | ||||
|                         }) | ||||
|                 }) | ||||
|         }) | ||||
|         .for_each(|payment_methods_enabled| { | ||||
|             payment_methods_enabled.for_each(|(payment_method, payment_method_types_vec)| { | ||||
|                 payment_method_types_map | ||||
|                     .entry(payment_method) | ||||
|                     .or_default() | ||||
|                     .extend( | ||||
|                         payment_method_types_vec | ||||
|                             .iter() | ||||
|                             .map(|p| p.payment_method_type), | ||||
|                     ); | ||||
|             }); | ||||
|             payment_methods_enabled.for_each( | ||||
|                 |(payment_method_option, payment_method_types_vec)| { | ||||
|                     if let Some(payment_method) = payment_method_option { | ||||
|                         payment_method_types_map | ||||
|                             .entry(payment_method) | ||||
|                             .or_default() | ||||
|                             .extend(payment_method_types_vec.iter().filter_map( | ||||
|                                 |req_payment_method_types| { | ||||
|                                     req_payment_method_types.get_payment_method_type() | ||||
|                                 }, | ||||
|                             )); | ||||
|                     } | ||||
|                 }, | ||||
|             ); | ||||
|         }); | ||||
|  | ||||
|     Ok(services::ApplicationResponse::Json( | ||||
|  | ||||
| @ -567,14 +567,19 @@ impl Payments { | ||||
|     pub fn server(state: AppState) -> Scope { | ||||
|         let mut route = web::scope("/v2/payments").app_data(web::Data::new(state)); | ||||
|         route = route | ||||
|             .service( | ||||
|                 web::resource("") | ||||
|                     .route(web::post().to(payments::payments_create_and_confirm_intent)), | ||||
|             ) | ||||
|             .service( | ||||
|                 web::resource("/create-intent") | ||||
|                     .route(web::post().to(payments::payments_create_intent)), | ||||
|             ) | ||||
|             .service(web::resource("/filter").route(web::get().to(payments::get_payment_filters))) | ||||
|             .service( | ||||
|                 web::resource("/profile/filter") | ||||
|                     .route(web::get().to(payments::get_payment_filters_profile)), | ||||
|             ) | ||||
|             .service( | ||||
|                 web::resource("") | ||||
|                     .route(web::post().to(payments::payments_create_and_confirm_intent)), | ||||
|             ) | ||||
|             .service(web::resource("/list").route(web::get().to(payments::payments_list))) | ||||
|             .service( | ||||
|                 web::resource("/aggregate").route(web::get().to(payments::get_payments_aggregates)), | ||||
|  | ||||
| @ -1386,7 +1386,7 @@ pub async fn get_filters_for_payments( | ||||
| } | ||||
|  | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsFilters))] | ||||
| #[cfg(all(feature = "olap", feature = "v1"))] | ||||
| #[cfg(feature = "olap")] | ||||
| pub async fn get_payment_filters( | ||||
|     state: web::Data<app::AppState>, | ||||
|     req: actix_web::HttpRequest, | ||||
| @ -1408,6 +1408,33 @@ pub async fn get_payment_filters( | ||||
|     .await | ||||
| } | ||||
|  | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsFilters))] | ||||
| #[cfg(all(feature = "olap", feature = "v2"))] | ||||
| pub async fn get_payment_filters_profile( | ||||
|     state: web::Data<app::AppState>, | ||||
|     req: actix_web::HttpRequest, | ||||
| ) -> impl Responder { | ||||
|     let flow = Flow::PaymentsFilters; | ||||
|     Box::pin(api::server_wrap( | ||||
|         flow, | ||||
|         state, | ||||
|         &req, | ||||
|         (), | ||||
|         |state, auth: auth::AuthenticationData, _, _| { | ||||
|             payments::get_payment_filters( | ||||
|                 state, | ||||
|                 auth.merchant_account, | ||||
|                 Some(vec![auth.profile.get_id().clone()]), | ||||
|             ) | ||||
|         }, | ||||
|         &auth::JWTAuth { | ||||
|             permission: Permission::ProfilePaymentRead, | ||||
|         }, | ||||
|         api_locking::LockAction::NotApplicable, | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
|  | ||||
| #[instrument(skip_all, fields(flow = ?Flow::PaymentsFilters))] | ||||
| #[cfg(all(feature = "olap", feature = "v1"))] | ||||
| pub async fn get_payment_filters_profile( | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Aniket Burman
					Aniket Burman