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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(reports): Add payment_response_hash_key to report generation Lambda payload (#12218)
Rohan Malid36844bcceae
diff --git a/crates/api_models/src/analytics.rs b/crates/api_models/src/analytics.rsindex 30973a9632..a7226164bb 100644--- a/crates/api_models/src/analytics.rs+++ b/crates/api_models/src/analytics.rs@@ -163,6 +163,7 @@ pub struct GenerateReportRequest {pub merchant_id: Option<common_utils::id_type::MerchantId>,pub auth: AuthInfo,pub email: Email,+ pub payment_response_hash_key: Option<String>,}#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]diff --git a/crates/router/src/analytics.rs b/crates/router/src/analytics.rsindex f54f33e16e..b02641b016 100644--- a/crates/router/src/analytics.rs+++ b/crates/router/src/analytics.rs@@ -46,6 +46,7 @@ pub mod routes {ApplicationResponse,},types::{domain::UserEmail, storage::UserRole},+ utils::get_payment_response_hash_key,};pub struct Analytics;@@ -1814,11 +1815,25 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_merchant_level_auth_info();+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_merchant_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -1903,11 +1918,14 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_org_level_auth_info();+let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: auth.platform.to_org_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: None,};let json_bytes =@@ -1920,18 +1938,11 @@ pub mod routes {.await.map(ApplicationResponse::Json)},- auth::auth_type(- &auth::ApiKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- },- &auth::JWTAuth {- permission: Permission::OrganizationReportRead,- allow_connected: true,- allow_platform: false,- },- req.headers(),- ),+ &auth::JWTAuth {+ permission: Permission::OrganizationReportRead,+ allow_connected: true,+ allow_platform: false,+ },api_locking::LockAction::NotApplicable,)).await@@ -1998,11 +2009,26 @@ pub mod routes {.change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();++ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_profile_level_auth_info(profile_id),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -2086,11 +2112,25 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_merchant_level_auth_info();+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_merchant_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -2174,11 +2214,14 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_org_level_auth_info();+let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: auth.platform.to_org_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: None,};let json_bytes =@@ -2191,18 +2234,11 @@ pub mod routes {.await.map(ApplicationResponse::Json)},- auth::auth_type(- &auth::ApiKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- },- &auth::JWTAuth {- permission: Permission::OrganizationReportRead,- allow_connected: true,- allow_platform: false,- },- req.headers(),- ),+ &auth::JWTAuth {+ permission: Permission::OrganizationReportRead,+ allow_connected: true,+ allow_platform: false,+ },api_locking::LockAction::NotApplicable,)).await@@ -2269,11 +2305,25 @@ pub mod routes {.change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_profile_level_auth_info(profile_id),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -2358,11 +2408,25 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_merchant_level_auth_info();+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_merchant_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -2447,11 +2511,14 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_org_level_auth_info();+let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: auth.platform.to_org_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: None,};let json_bytes =@@ -2464,18 +2531,11 @@ pub mod routes {.await.map(ApplicationResponse::Json)},- auth::auth_type(- &auth::ApiKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- },- &auth::JWTAuth {- permission: Permission::OrganizationReportRead,- allow_connected: true,- allow_platform: false,- },- req.headers(),- ),+ &auth::JWTAuth {+ permission: Permission::OrganizationReportRead,+ allow_connected: true,+ allow_platform: false,+ },api_locking::LockAction::NotApplicable,)).await@@ -2541,11 +2601,25 @@ pub mod routes {.change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_profile_level_auth_info(profile_id),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -2629,11 +2703,25 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_merchant_level_auth_info();+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_merchant_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -2717,11 +2805,14 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_org_level_auth_info();+let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: auth.platform.to_org_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: None,};let json_bytes =@@ -2734,18 +2825,11 @@ pub mod routes {.await.map(ApplicationResponse::Json)},- auth::auth_type::<auth::AuthenticationDataWithUserId, _>(- &auth::ApiKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- },- &auth::JWTAuth {- permission: Permission::OrganizationReportRead,- allow_connected: true,- allow_platform: false,- },- req.headers(),- ),+ &auth::JWTAuth {+ permission: Permission::OrganizationReportRead,+ allow_connected: true,+ allow_platform: false,+ },api_locking::LockAction::NotApplicable,)).await@@ -2818,11 +2902,26 @@ pub mod routes {auth.profile.get_id().clone()}};++ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_profile_level_auth_info(profile_id),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -2907,11 +3006,25 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_merchant_level_auth_info();+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_merchant_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =@@ -2996,11 +3109,14 @@ pub mod routes {..payload};+ let auth_info = auth.platform.to_org_level_auth_info();+let lambda_req = GenerateReportRequest {request: payload,merchant_id: None,- auth: auth.platform.to_org_level_auth_info(),+ auth: auth_info,email: user_email,+ payment_response_hash_key: None,};let json_bytes =@@ -3013,18 +3129,11 @@ pub mod routes {.await.map(ApplicationResponse::Json)},- auth::auth_type(- &auth::ApiKeyAuth {- allow_connected_scope_operation: true,- allow_platform_self_operation: false,- },- &auth::JWTAuth {- permission: Permission::OrganizationReportRead,- allow_connected: true,- allow_platform: false,- },- req.headers(),- ),+ &auth::JWTAuth {+ permission: Permission::OrganizationReportRead,+ allow_connected: true,+ allow_platform: false,+ },api_locking::LockAction::NotApplicable,)).await@@ -3090,11 +3199,25 @@ pub mod routes {.change_context(AnalyticsError::AccessForbiddenError)?.get_id().clone();+ let auth_info = auth.platform.to_profile_level_auth_info(profile_id);+ let hash_key = match &payload.return_url {+ Some(_) => {+ get_payment_response_hash_key(+ state.store.as_ref(),+ auth.platform.get_processor().get_key_store(),+ &auth_info,+ )+ .await?+ }+ None => None,+ };+let lambda_req = GenerateReportRequest {request: payload,merchant_id: Some(auth.platform.get_processor().get_account().get_id().clone()),- auth: auth.platform.to_profile_level_auth_info(profile_id),+ auth: auth_info,email: user_email,+ payment_response_hash_key: hash_key,};let json_bytes =diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rsindex d32288fd04..ff0051bd87 100644--- a/crates/router/src/utils.rs+++ b/crates/router/src/utils.rs@@ -16,6 +16,7 @@ pub mod user_role;pub mod verify_connector;use std::fmt::Debug;+use analytics::{enums::AuthInfo, errors::AnalyticsError};use api_models::{enums,payments::{self},@@ -54,6 +55,7 @@ use crate::{errors::{self, CustomResult, RouterResult, StorageErrorExt},payments as payments_core,},+ db::StorageInterface,headers::ACCEPT_LANGUAGE,logger,routes::{metrics, SessionState},@@ -1488,3 +1490,47 @@ pub async fn trigger_subscriptions_outgoing_webhook(Ok(())}++pub async fn get_payment_response_hash_key(+ store: &dyn StorageInterface,+ key_store: &domain::MerchantKeyStore,+ auth: &AuthInfo,+) -> Result<Option<String>, error_stack::Report<AnalyticsError>> {+ match auth {+ AuthInfo::ProfileLevel {+ merchant_id,+ profile_ids,+ ..+ } => {+ let profile_id = profile_ids.first().ok_or(AnalyticsError::UnknownError)?;+ let profile = store+ .find_business_profile_by_merchant_id_profile_id(key_store, merchant_id, profile_id)+ .await+ .change_context(AnalyticsError::UnknownError)?;+ Ok(profile.payment_response_hash_key)+ }+ AuthInfo::MerchantLevel { merchant_ids, .. } => {+ #[cfg(feature = "v1")]+ {+ let merchant_id = merchant_ids.first().ok_or(AnalyticsError::UnknownError)?;+ let merchant = store+ .find_merchant_account_by_merchant_id(merchant_id, key_store)+ .await+ .change_context(AnalyticsError::UnknownError)?;+ Ok(merchant.payment_response_hash_key)+ }+ #[cfg(feature = "v2")]+ {+ let merchant_id = merchant_ids.first().ok_or(AnalyticsError::UnknownError)?;+ let profiles = store+ .list_profile_by_merchant_id(key_store, merchant_id)+ .await+ .change_context(AnalyticsError::UnknownError)?;+ Ok(profiles+ .first()+ .and_then(|profile| profile.payment_response_hash_key.clone()))+ }+ }+ AuthInfo::OrgLevel { .. } => Ok(None),+ }+}