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(payouts): add payout report generation endpoints and configuration (#10073)
Venu Madhav Bandarupalli4174929beab1
diff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.tomlindex 2ea9388103..d14cb4f562 100644--- a/config/deployments/env_specific.toml+++ b/config/deployments/env_specific.toml@@ -249,6 +249,7 @@ queue_strategy = "Fifo" # Add the queue strategy used by the database bb8 cliedispute_function = "report_download_config_dispute_function" # Config to download dispute reportpayment_function = "report_download_config_payment_function" # Config to download payment reportrefund_function = "report_download_config_refund_function" # Config to download refund report+payout_function = "report_download_config_payout_function" # Config to download payout reportregion = "report_download_config_region" # Region of the bucket[opensearch]diff --git a/crates/analytics/src/lib.rs b/crates/analytics/src/lib.rsindex 5a9e3b6b06..b938e82e65 100644--- a/crates/analytics/src/lib.rs+++ b/crates/analytics/src/lib.rs@@ -1118,6 +1118,7 @@ pub struct ReportConfig {pub refund_function: String,pub dispute_function: String,pub authentication_function: String,+ pub payout_function: String,pub region: String,}@@ -1147,6 +1148,7 @@ pub enum AnalyticsFlow {GenerateDisputeReport,GenerateRefundReport,GenerateAuthenticationReport,+ GeneratePayoutReport,GetApiEventMetrics,GetApiEventFilters,GetConnectorEvents,diff --git a/crates/router/src/analytics.rs b/crates/router/src/analytics.rsindex e41b7e5953..817cacbf09 100644--- a/crates/router/src/analytics.rs+++ b/crates/router/src/analytics.rs@@ -98,6 +98,10 @@ pub mod routes {web::resource("report/payments").route(web::post().to(generate_merchant_payment_report)),)+ .service(+ web::resource("report/payouts")+ .route(web::post().to(generate_merchant_payout_report)),+ ).service(web::resource("report/authentications").route(web::post().to(generate_merchant_authentication_report)),@@ -226,6 +230,10 @@ pub mod routes {web::resource("report/payments").route(web::post().to(generate_merchant_payment_report)),)+ .service(+ web::resource("report/payouts")+ .route(web::post().to(generate_merchant_payout_report)),+ ).service(web::resource("report/authentications").route(web::post().to(generate_merchant_authentication_report),@@ -313,6 +321,10 @@ pub mod routes {web::resource("report/payments").route(web::post().to(generate_org_payment_report)),)+ .service(+ web::resource("report/payouts")+ .route(web::post().to(generate_org_payout_report)),+ ).service(web::resource("report/authentications").route(web::post().to(generate_org_authentication_report)),@@ -395,6 +407,10 @@ pub mod routes {web::resource("report/payments").route(web::post().to(generate_profile_payment_report)),)+ .service(+ web::resource("report/payouts")+ .route(web::post().to(generate_profile_payout_report)),+ ).service(web::resource("report/authentications").route(web::post().to(generate_profile_authentication_report),@@ -2014,6 +2030,161 @@ pub mod routes {.await}+ #[cfg(feature = "v1")]+ pub async fn generate_merchant_payout_report(+ state: web::Data<AppState>,+ req: actix_web::HttpRequest,+ json_payload: web::Json<ReportRequest>,+ ) -> impl Responder {+ let flow = AnalyticsFlow::GeneratePayoutReport;+ Box::pin(api::server_wrap(+ flow,+ state.clone(),+ &req,+ json_payload.into_inner(),+ |state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {+ let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)+ .await+ .change_context(AnalyticsError::UnknownError)?;++ let user_email = UserEmail::from_pii_email(user.email)+ .change_context(AnalyticsError::UnknownError)?+ .get_secret();++ let org_id = auth.merchant_account.get_org_id();+ let merchant_id = auth.merchant_account.get_id();+ let lambda_req = GenerateReportRequest {+ request: payload,+ merchant_id: Some(merchant_id.clone()),+ auth: AuthInfo::MerchantLevel {+ org_id: org_id.clone(),+ merchant_ids: vec![merchant_id.clone()],+ },+ email: user_email,+ };++ let json_bytes =+ serde_json::to_vec(&lambda_req).map_err(|_| AnalyticsError::UnknownError)?;+ invoke_lambda(+ &state.conf.report_download_config.payout_function,+ &state.conf.report_download_config.region,+ &json_bytes,+ )+ .await+ .map(ApplicationResponse::Json)+ },+ &auth::JWTAuth {+ permission: Permission::MerchantReportRead,+ },+ api_locking::LockAction::NotApplicable,+ ))+ .await+ }++ #[cfg(feature = "v1")]+ pub async fn generate_org_payout_report(+ state: web::Data<AppState>,+ req: actix_web::HttpRequest,+ json_payload: web::Json<ReportRequest>,+ ) -> impl Responder {+ let flow = AnalyticsFlow::GeneratePayoutReport;+ Box::pin(api::server_wrap(+ flow,+ state.clone(),+ &req,+ json_payload.into_inner(),+ |state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {+ let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)+ .await+ .change_context(AnalyticsError::UnknownError)?;++ let user_email = UserEmail::from_pii_email(user.email)+ .change_context(AnalyticsError::UnknownError)?+ .get_secret();++ let org_id = auth.merchant_account.get_org_id();+ let lambda_req = GenerateReportRequest {+ request: payload,+ merchant_id: None,+ auth: AuthInfo::OrgLevel {+ org_id: org_id.clone(),+ },+ email: user_email,+ };++ let json_bytes =+ serde_json::to_vec(&lambda_req).map_err(|_| AnalyticsError::UnknownError)?;+ invoke_lambda(+ &state.conf.report_download_config.payout_function,+ &state.conf.report_download_config.region,+ &json_bytes,+ )+ .await+ .map(ApplicationResponse::Json)+ },+ &auth::JWTAuth {+ permission: Permission::OrganizationReportRead,+ },+ api_locking::LockAction::NotApplicable,+ ))+ .await+ }++ #[cfg(feature = "v1")]+ pub async fn generate_profile_payout_report(+ state: web::Data<AppState>,+ req: actix_web::HttpRequest,+ json_payload: web::Json<ReportRequest>,+ ) -> impl Responder {+ let flow = AnalyticsFlow::GeneratePayoutReport;+ Box::pin(api::server_wrap(+ flow,+ state.clone(),+ &req,+ json_payload.into_inner(),+ |state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {+ let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)+ .await+ .change_context(AnalyticsError::UnknownError)?;++ let user_email = UserEmail::from_pii_email(user.email)+ .change_context(AnalyticsError::UnknownError)?+ .get_secret();+ let org_id = auth.merchant_account.get_org_id();+ let merchant_id = auth.merchant_account.get_id();+ let profile_id = auth+ .profile_id+ .ok_or(report!(UserErrors::JwtProfileIdMissing))+ .change_context(AnalyticsError::AccessForbiddenError)?;+ let lambda_req = GenerateReportRequest {+ request: payload,+ merchant_id: Some(merchant_id.clone()),+ auth: AuthInfo::ProfileLevel {+ org_id: org_id.clone(),+ merchant_id: merchant_id.clone(),+ profile_ids: vec![profile_id.clone()],+ },+ email: user_email,+ };++ let json_bytes =+ serde_json::to_vec(&lambda_req).map_err(|_| AnalyticsError::UnknownError)?;+ invoke_lambda(+ &state.conf.report_download_config.payout_function,+ &state.conf.report_download_config.region,+ &json_bytes,+ )+ .await+ .map(ApplicationResponse::Json)+ },+ &auth::JWTAuth {+ permission: Permission::ProfileReportRead,+ },+ api_locking::LockAction::NotApplicable,+ ))+ .await+ }+#[cfg(feature = "v1")]pub async fn generate_merchant_payment_report(state: web::Data<AppState>,