mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(payments): get new filters for payments list (#4174)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Sampras Lopes <lsampras@pm.me>
This commit is contained in:
@ -518,6 +518,12 @@ pub struct MerchantConnectorWebhookDetails {
|
||||
pub additional_secret: Option<Secret<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
pub struct MerchantConnectorInfo {
|
||||
pub connector_label: String,
|
||||
pub merchant_connector_id: String,
|
||||
}
|
||||
|
||||
/// Response of creating a new Merchant Connector for the merchant account."
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
|
||||
@ -9,8 +9,8 @@ use crate::{
|
||||
},
|
||||
payments::{
|
||||
PaymentIdType, PaymentListConstraints, PaymentListFilterConstraints, PaymentListFilters,
|
||||
PaymentListResponse, PaymentListResponseV2, PaymentsApproveRequest, PaymentsCancelRequest,
|
||||
PaymentsCaptureRequest, PaymentsExternalAuthenticationRequest,
|
||||
PaymentListFiltersV2, PaymentListResponse, PaymentListResponseV2, PaymentsApproveRequest,
|
||||
PaymentsCancelRequest, PaymentsCaptureRequest, PaymentsExternalAuthenticationRequest,
|
||||
PaymentsExternalAuthenticationResponse, PaymentsIncrementalAuthorizationRequest,
|
||||
PaymentsRejectRequest, PaymentsRequest, PaymentsResponse, PaymentsRetrieveRequest,
|
||||
PaymentsStartRequest, RedirectionResponse,
|
||||
@ -158,6 +158,11 @@ impl ApiEventMetric for PaymentListFilters {
|
||||
Some(ApiEventsType::ResourceListAPI)
|
||||
}
|
||||
}
|
||||
impl ApiEventMetric for PaymentListFiltersV2 {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::ResourceListAPI)
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiEventMetric for PaymentListConstraints {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
use std::{collections::HashMap, fmt, num::NonZeroI64};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fmt,
|
||||
num::NonZeroI64,
|
||||
};
|
||||
|
||||
use cards::CardNumber;
|
||||
use common_utils::{
|
||||
@ -19,8 +23,11 @@ use url::Url;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use crate::{
|
||||
admin, disputes, enums as api_enums, ephemeral_key::EphemeralKeyCreateResponse,
|
||||
mandates::RecurringDetails, refunds,
|
||||
admin::{self, MerchantConnectorInfo},
|
||||
disputes, enums as api_enums,
|
||||
ephemeral_key::EphemeralKeyCreateResponse,
|
||||
mandates::RecurringDetails,
|
||||
refunds,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
@ -3419,6 +3426,20 @@ pub struct PaymentListFilters {
|
||||
pub authentication_type: Vec<enums::AuthenticationType>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
pub struct PaymentListFiltersV2 {
|
||||
/// The list of available connector filters
|
||||
pub connector: HashMap<String, Vec<MerchantConnectorInfo>>,
|
||||
/// The list of available currency filters
|
||||
pub currency: Vec<enums::Currency>,
|
||||
/// The list of available payment status filters
|
||||
pub status: Vec<enums::IntentStatus>,
|
||||
/// The list payment method and their corresponding types
|
||||
pub payment_method: HashMap<enums::PaymentMethod, HashSet<enums::PaymentMethodType>>,
|
||||
/// The list of available authentication types
|
||||
pub authentication_type: Vec<enums::AuthenticationType>,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash, ToSchema,
|
||||
)]
|
||||
|
||||
@ -1153,6 +1153,7 @@ pub enum MerchantStorageScheme {
|
||||
serde::Deserialize,
|
||||
serde::Serialize,
|
||||
strum::Display,
|
||||
strum::EnumIter,
|
||||
strum::EnumString,
|
||||
)]
|
||||
#[router_derive::diesel_enum(storage_type = "db_enum")]
|
||||
|
||||
@ -11,8 +11,12 @@ pub mod tokenization;
|
||||
pub mod transformers;
|
||||
pub mod types;
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::{fmt::Debug, marker::PhantomData, ops::Deref, time::Instant, vec::IntoIter};
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
use api_models::admin::MerchantConnectorInfo;
|
||||
use api_models::{
|
||||
self, enums,
|
||||
mandates::RecurringDetails,
|
||||
@ -33,6 +37,8 @@ use router_env::{instrument, tracing};
|
||||
#[cfg(feature = "olap")]
|
||||
use router_types::transformers::ForeignFrom;
|
||||
use scheduler::utils as pt_utils;
|
||||
#[cfg(feature = "olap")]
|
||||
use strum::IntoEnumIterator;
|
||||
use time;
|
||||
|
||||
pub use self::operations::{
|
||||
@ -2619,6 +2625,89 @@ pub async fn get_filters_for_payments(
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
pub async fn get_payment_filters(
|
||||
state: AppState,
|
||||
merchant: domain::MerchantAccount,
|
||||
) -> RouterResponse<api::PaymentListFiltersV2> {
|
||||
let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) =
|
||||
super::admin::list_payment_connectors(state, merchant.merchant_id).await?
|
||||
{
|
||||
data
|
||||
} else {
|
||||
return Err(errors::ApiErrorResponse::InternalServerError.into());
|
||||
};
|
||||
|
||||
let mut connector_map: HashMap<String, Vec<MerchantConnectorInfo>> = HashMap::new();
|
||||
let mut payment_method_types_map: HashMap<
|
||||
enums::PaymentMethod,
|
||||
HashSet<enums::PaymentMethodType>,
|
||||
> = HashMap::new();
|
||||
|
||||
// populate connector map
|
||||
merchant_connector_accounts
|
||||
.iter()
|
||||
.filter_map(|merchant_connector_account| {
|
||||
merchant_connector_account
|
||||
.connector_label
|
||||
.as_ref()
|
||||
.map(|label| {
|
||||
let info = MerchantConnectorInfo {
|
||||
connector_label: label.clone(),
|
||||
merchant_connector_id: merchant_connector_account
|
||||
.merchant_connector_id
|
||||
.clone(),
|
||||
};
|
||||
(merchant_connector_account.connector_name.clone(), info)
|
||||
})
|
||||
})
|
||||
.for_each(|(connector_name, info)| {
|
||||
connector_map
|
||||
.entry(connector_name.clone())
|
||||
.or_default()
|
||||
.push(info);
|
||||
});
|
||||
|
||||
// populate payment method type map
|
||||
merchant_connector_accounts
|
||||
.iter()
|
||||
.flat_map(|merchant_connector_account| {
|
||||
merchant_connector_account.payment_methods_enabled.as_ref()
|
||||
})
|
||||
.map(|payment_methods_enabled| {
|
||||
payment_methods_enabled
|
||||
.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()))
|
||||
})
|
||||
})
|
||||
.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),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Ok(services::ApplicationResponse::Json(
|
||||
api::PaymentListFiltersV2 {
|
||||
connector: connector_map,
|
||||
currency: enums::Currency::iter().collect(),
|
||||
status: enums::IntentStatus::iter().collect(),
|
||||
payment_method: payment_method_types_map,
|
||||
authentication_type: enums::AuthenticationType::iter().collect(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn add_process_sync_task(
|
||||
db: &dyn StorageInterface,
|
||||
payment_attempt: &storage::PaymentAttempt,
|
||||
|
||||
@ -318,6 +318,7 @@ impl Payments {
|
||||
.route(web::post().to(payments_list_by_filter)),
|
||||
)
|
||||
.service(web::resource("/filter").route(web::post().to(get_filters_for_payments)))
|
||||
.service(web::resource("/filter_v2").route(web::get().to(get_payment_filters)))
|
||||
}
|
||||
#[cfg(feature = "oltp")]
|
||||
{
|
||||
|
||||
@ -114,6 +114,7 @@ impl From<Flow> for ApiIdentifier {
|
||||
| Flow::PaymentsSessionToken
|
||||
| Flow::PaymentsStart
|
||||
| Flow::PaymentsList
|
||||
| Flow::PaymentsFilters
|
||||
| Flow::PaymentsRedirect
|
||||
| Flow::PaymentsIncrementalAuthorization
|
||||
| Flow::PaymentsExternalAuthentication
|
||||
|
||||
@ -959,6 +959,29 @@ pub async fn get_filters_for_payments(
|
||||
.await
|
||||
}
|
||||
|
||||
#[instrument(skip_all, fields(flow = ?Flow::PaymentsFilters))]
|
||||
#[cfg(feature = "olap")]
|
||||
pub async fn get_payment_filters(
|
||||
state: web::Data<app::AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
) -> impl Responder {
|
||||
let flow = Flow::PaymentsFilters;
|
||||
api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
(),
|
||||
|state, auth, _, _| payments::get_payment_filters(state, auth.merchant_account),
|
||||
auth::auth_type(
|
||||
&auth::ApiKeyAuth,
|
||||
&auth::JWTAuth(Permission::PaymentRead),
|
||||
req.headers(),
|
||||
),
|
||||
api_locking::LockAction::NotApplicable,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(feature = "oltp")]
|
||||
#[instrument(skip_all, fields(flow = ?Flow::PaymentsApprove, payment_id))]
|
||||
// #[post("/{payment_id}/approve")]
|
||||
|
||||
@ -3,10 +3,10 @@ pub use api_models::payments::{
|
||||
CryptoData, CustomerAcceptance, HeaderPayload, MandateAmountData, MandateData,
|
||||
MandateTransactionType, MandateType, MandateValidationFields, NextActionType, OnlineMandate,
|
||||
PayLaterData, PaymentIdType, PaymentListConstraints, PaymentListFilterConstraints,
|
||||
PaymentListFilters, PaymentListResponse, PaymentListResponseV2, PaymentMethodData,
|
||||
PaymentMethodDataRequest, PaymentMethodDataResponse, PaymentOp, PaymentRetrieveBody,
|
||||
PaymentRetrieveBodyWithCredentials, PaymentsApproveRequest, PaymentsCancelRequest,
|
||||
PaymentsCaptureRequest, PaymentsExternalAuthenticationRequest,
|
||||
PaymentListFilters, PaymentListFiltersV2, PaymentListResponse, PaymentListResponseV2,
|
||||
PaymentMethodData, PaymentMethodDataRequest, PaymentMethodDataResponse, PaymentOp,
|
||||
PaymentRetrieveBody, PaymentRetrieveBodyWithCredentials, PaymentsApproveRequest,
|
||||
PaymentsCancelRequest, PaymentsCaptureRequest, PaymentsExternalAuthenticationRequest,
|
||||
PaymentsIncrementalAuthorizationRequest, PaymentsRedirectRequest, PaymentsRedirectionResponse,
|
||||
PaymentsRejectRequest, PaymentsRequest, PaymentsResponse, PaymentsResponseForm,
|
||||
PaymentsRetrieveRequest, PaymentsSessionRequest, PaymentsSessionResponse, PaymentsStartRequest,
|
||||
|
||||
@ -151,6 +151,8 @@ pub enum Flow {
|
||||
PaymentsStart,
|
||||
/// Payments list flow.
|
||||
PaymentsList,
|
||||
// Payments filters flow
|
||||
PaymentsFilters,
|
||||
#[cfg(feature = "payouts")]
|
||||
/// Payouts create flow
|
||||
PayoutsCreate,
|
||||
|
||||
Reference in New Issue
Block a user