Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(payment_method): add OLAP payment method retrieve endpoint for dashboard (#12070)

Shankar Singh Cbbc6ed030822
diff --git a/crates/api_models/src/events/payment.rs b/crates/api_models/src/events/payment.rs
index 38febddab2..8421531a6c 100644
--- a/crates/api_models/src/events/payment.rs
+++ b/crates/api_models/src/events/payment.rs
@@ -9,8 +9,8 @@ use super::{
};
#[cfg(feature = "v2")]
use crate::payment_methods::{
- ListMethodsForPaymentMethodsRequest, PaymentMethodGetTokenDetailsResponse,
- PaymentMethodListResponseForSession,
+ ListMethodsForPaymentMethodsRequest, PaymentMethodDetailsResponse,
+ PaymentMethodGetTokenDetailsResponse, PaymentMethodListResponseForSession,
};
use crate::{
payment_methods::{
@@ -323,6 +323,17 @@ impl ApiEventMetric for PaymentMethodResponse {
}
}
+#[cfg(feature = "v2")]
+impl ApiEventMetric for PaymentMethodDetailsResponse {
+ fn get_api_event_type(&self) -> Option<ApiEventsType> {
+ Some(ApiEventsType::PaymentMethod {
+ payment_method_id: self.id.clone(),
+ payment_method_type: self.payment_method_type,
+ payment_method_subtype: self.payment_method_subtype,
+ })
+ }
+}
+
#[cfg(feature = "v1")]
impl ApiEventMetric for CustomerPaymentMethodUpdateResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs
index 3c2a83ed05..9a301cb992 100644
--- a/crates/api_models/src/payment_methods.rs
+++ b/crates/api_models/src/payment_methods.rs
@@ -1421,6 +1421,98 @@ pub struct PaymentMethodResponse {
pub acknowledgement_status: Option<common_enums::AcknowledgementStatus>,
}
+#[cfg(feature = "v2")]
+#[derive(Debug, serde::Serialize, serde::Deserialize, ToSchema, Clone)]
+pub struct PaymentMethodDetailsResponse {
+ /// The unique identifier of the Payment method
+ #[schema(value_type = String, example = "12345_pm_01926c58bc6e77c09e809964e72af8c8")]
+ pub id: id_type::GlobalPaymentMethodId,
+
+ /// Unique identifier for a merchant
+ #[schema(value_type = String, example = "merchant_1671528864")]
+ pub merchant_id: id_type::MerchantId,
+
+ /// The unique identifier of the customer.
+ #[schema(
+ min_length = 32,
+ max_length = 64,
+ example = "12345_cus_01926c58bc6e77c09e809964e72af8c8",
+ value_type = String
+ )]
+ pub customer_id: Option<id_type::GlobalCustomerId>,
+
+ /// The type of payment method use for the payment.
+ #[schema(value_type = PaymentMethod, example = "card")]
+ pub payment_method_type: Option<api_enums::PaymentMethod>,
+
+ /// This is a sub-category of payment method.
+ #[schema(value_type = Option<PaymentMethodType>, example = "credit")]
+ pub payment_method_subtype: Option<api_enums::PaymentMethodType>,
+
+ /// Indicates whether the payment method supports recurring payments. Optional.
+ #[schema(example = true)]
+ pub recurring_enabled: Option<bool>,
+
+ /// A timestamp (ISO 8601 code) that determines when the payment method was created
+ #[schema(value_type = Option<PrimitiveDateTime>, example = "2023-01-18T11:04:09.922Z")]
+ #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
+ pub created: Option<time::PrimitiveDateTime>,
+
+ /// A timestamp (ISO 8601 code) that determines when the payment method was last used
+ #[schema(value_type = Option<PrimitiveDateTime>, example = "2024-02-24T11:04:09.922Z")]
+ #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
+ pub last_used_at: Option<time::PrimitiveDateTime>,
+
+ /// The payment method details related to the payment method
+ pub payment_method_data: Option<PaymentMethodResponseData>,
+
+ /// The connector token details if available
+ pub connector_tokens: Option<Vec<ConnectorTokenDetails>>,
+
+ /// Network token details if available
+ pub network_token: Option<NetworkTokenResponse>,
+
+ /// The storage type for the payment method
+ #[schema(value_type = StorageType)]
+ pub storage_type: common_enums::StorageType,
+
+ /// The network transaction ID provided by the card network during a Customer Initiated Transaction (CIT)
+ /// when `setup_future_usage` is set to `off_session`.
+ #[schema(value_type = String)]
+ pub network_transaction_id: Option<hyperswitch_masking::Secret<String>>,
+
+ /// Billing details of the payment method
+ #[schema(value_type = Option<Address>)]
+ pub billing: Option<payments::Address>,
+
+ /// The acknowledgement status of the payment method update
+ #[schema(value_type = Option<AcknowledgementStatus>)]
+ pub acknowledgement_status: Option<common_enums::AcknowledgementStatus>,
+}
+
+#[cfg(feature = "v2")]
+impl From<PaymentMethodResponse> for PaymentMethodDetailsResponse {
+ fn from(resp: PaymentMethodResponse) -> Self {
+ Self {
+ id: resp.id,
+ merchant_id: resp.merchant_id,
+ customer_id: resp.customer_id,
+ payment_method_type: resp.payment_method_type,
+ payment_method_subtype: resp.payment_method_subtype,
+ recurring_enabled: resp.recurring_enabled,
+ created: resp.created,
+ last_used_at: resp.last_used_at,
+ payment_method_data: resp.payment_method_data,
+ connector_tokens: resp.connector_tokens,
+ network_token: resp.network_token,
+ storage_type: resp.storage_type,
+ network_transaction_id: resp.network_transaction_id,
+ billing: resp.billing,
+ acknowledgement_status: resp.acknowledgement_status,
+ }
+ }
+}
+
#[cfg(feature = "v2")]
#[derive(Clone, Copy, Debug, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct CardCVCTokenStorageDetails {
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index d2600feb64..2a7ea358b7 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -5067,6 +5067,32 @@ pub async fn retrieve_payment_method(
.map(services::ApplicationResponse::Json)
}
+#[cfg(all(feature = "v2", feature = "olap"))]
+#[instrument(skip_all)]
+pub async fn retrieve_payment_method_olap(
+ state: SessionState,
+ pm: api::PaymentMethodId,
+ profile: domain::Profile,
+ platform: domain::Platform,
+) -> RouterResponse<api::PaymentMethodDetailsResponse> {
+ let response = Box::pin(retrieve_payment_method(
+ state,
+ pm,
+ profile,
+ platform,
+ enums::ApiKeyType::External,
+ false,
+ ))
+ .await?
+ .get_json_body()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to get payment method response body")?;
+
+ Ok(services::ApplicationResponse::Json(
+ api::PaymentMethodDetailsResponse::from(response),
+ ))
+}
+
#[cfg(feature = "v2")]
#[instrument(skip_all)]
pub async fn fetch_payment_method_by_storage(
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index 570307c730..b5a929e7f6 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -1602,6 +1602,10 @@ impl PaymentMethods {
payment_methods::list_countries_currencies_for_connector_payment_method,
),
));
+ route = route.service(
+ web::resource("/{id}/details")
+ .route(web::get().to(payment_methods::payment_method_retrieve_olap_api)),
+ );
}
#[cfg(feature = "oltp")]
{
diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rs
index b49c070d69..d8107079d0 100644
--- a/crates/router/src/routes/lock_utils.rs
+++ b/crates/router/src/routes/lock_utils.rs
@@ -133,6 +133,7 @@ impl From<Flow> for ApiIdentifier {
| Flow::CustomerPaymentMethodsList
| Flow::GetPaymentMethodTokenData
| Flow::PaymentMethodsRetrieve
+ | Flow::PaymentMethodsRetrieveOlap
| Flow::PaymentMethodsUpdate
| Flow::PaymentMethodsDelete
| Flow::NetworkTokenStatusCheck
diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs
index 7ad9dbe4f6..f18dc11c83 100644
--- a/crates/router/src/routes/payment_methods.rs
+++ b/crates/router/src/routes/payment_methods.rs
@@ -914,6 +914,49 @@ pub async fn list_customer_payment_method_api(
.await
}
+#[cfg(all(feature = "v2", feature = "olap"))]
+#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsRetrieveOlap))]
+pub async fn payment_method_retrieve_olap_api(
+ state: web::Data<AppState>,
+ req: HttpRequest,
+ path: web::Path<String>,
+) -> HttpResponse {
+ let flow = Flow::PaymentMethodsRetrieveOlap;
+ let payload = web::Json(PaymentMethodId {
+ payment_method_id: path.into_inner(),
+ })
+ .into_inner();
+
+ Box::pin(api::server_wrap(
+ flow,
+ state,
+ &req,
+ payload,
+ |state, auth: auth::AuthenticationData, pm, _| {
+ payment_methods_routes::retrieve_payment_method_olap(
+ state,
+ pm,
+ auth.profile,
+ auth.platform,
+ )
+ },
+ auth::auth_type(
+ &auth::V2ApiKeyAuth {
+ allow_connected_scope_operation: true,
+ allow_platform_self_operation: true,
+ },
+ &auth::JWTAuth {
+ permission: Permission::MerchantCustomerRead,
+ allow_connected: true,
+ allow_platform: true,
+ },
+ req.headers(),
+ ),
+ api_locking::LockAction::NotApplicable,
+ ))
+ .await
+}
+
#[cfg(all(feature = "v2", feature = "olap"))]
#[instrument(skip_all, fields(flow = ?Flow::GetPaymentMethodTokenData))]
pub async fn get_payment_method_token_data(
diff --git a/crates/router/src/types/api/payment_methods.rs b/crates/router/src/types/api/payment_methods.rs
index e497b1a3f6..ea0fd6da32 100644
--- a/crates/router/src/types/api/payment_methods.rs
+++ b/crates/router/src/types/api/payment_methods.rs
@@ -7,8 +7,8 @@ pub use api_models::payment_methods::{
ListCountriesCurrenciesRequest, MigrateCardDetail, NetworkTokenDetailsPaymentMethod,
NetworkTokenDetailsResponse, NetworkTokenEligibilityRequest, NetworkTokenResponse,
PaymentMethodCollectLinkRenderRequest, PaymentMethodCollectLinkRequest, PaymentMethodCreate,
- PaymentMethodCreateData, PaymentMethodDeleteResponse, PaymentMethodId,
- PaymentMethodIntentConfirm, PaymentMethodIntentCreate, PaymentMethodListData,
+ PaymentMethodCreateData, PaymentMethodDeleteResponse, PaymentMethodDetailsResponse,
+ PaymentMethodId, PaymentMethodIntentConfirm, PaymentMethodIntentCreate, PaymentMethodListData,
PaymentMethodListResponseForSession, PaymentMethodMigrate, PaymentMethodMigrateResponse,
PaymentMethodResponse, PaymentMethodResponseData, PaymentMethodUpdate, PaymentMethodUpdateData,
PaymentMethodsData, ProxyCardDetails, RequestPaymentMethodTypes, TokenDataResponse,
diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rs
index 68fd1d2caf..e311964611 100644
--- a/crates/router_env/src/logger/types.rs
+++ b/crates/router_env/src/logger/types.rs
@@ -154,6 +154,8 @@ pub enum Flow {
PaymentMethodCollectLink,
/// Payment methods retrieve flow.
PaymentMethodsRetrieve,
+ /// Payment methods retrieve OLAP flow.
+ PaymentMethodsRetrieveOlap,
/// Payment methods update flow.
PaymentMethodsUpdate,
/// Payment methods delete flow.