From 0ba5d543496de040f637c5bf8d2529667d25e8a5 Mon Sep 17 00:00:00 2001 From: Ayush Anand <114248859+ayush22667@users.noreply.github.com> Date: Fri, 22 Aug 2025 18:35:42 +0530 Subject: [PATCH] feat(router): verify service for applepay merchant registration v2 (#8999) --- crates/router/src/core/verification.rs | 15 +++++--- crates/router/src/core/verification/utils.rs | 15 ++++---- crates/router/src/lib.rs | 6 +++- crates/router/src/routes/app.rs | 19 ++++++++-- crates/router/src/routes/verification.rs | 38 ++++++++++++++++++++ 5 files changed, 79 insertions(+), 14 deletions(-) diff --git a/crates/router/src/core/verification.rs b/crates/router/src/core/verification.rs index 3c1b95dd98..f7ed33be64 100644 --- a/crates/router/src/core/verification.rs +++ b/crates/router/src/core/verification.rs @@ -117,11 +117,16 @@ pub async fn get_verified_apple_domains_with_mid_mca_id( .unwrap_or_default(); #[cfg(feature = "v2")] - let verified_domains = { - let _ = merchant_connector_id; - let _ = key_store; - todo!() - }; + let verified_domains = db + .find_merchant_connector_account_by_id( + key_manager_state, + &merchant_connector_id, + &key_store, + ) + .await + .change_context(errors::ApiErrorResponse::ResourceIdNotFound)? + .applepay_verified_domains + .unwrap_or_default(); Ok(services::api::ApplicationResponse::Json( verifications::ApplepayVerifiedDomainsResponse { verified_domains }, diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rs index 81b916206a..fb38d0a619 100644 --- a/crates/router/src/core/verification/utils.rs +++ b/crates/router/src/core/verification/utils.rs @@ -43,12 +43,15 @@ pub async fn check_existence_and_add_domain_to_db( .change_context(errors::ApiErrorResponse::InternalServerError)?; #[cfg(feature = "v2")] - let merchant_connector_account: hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccount = { - let _ = merchant_connector_id; - let _ = key_store; - let _ = domain_from_req; - todo!() - }; + let merchant_connector_account = state + .store + .find_merchant_connector_account_by_id( + key_manager_state, + &merchant_connector_id, + &key_store, + ) + .await + .change_context(errors::ApiErrorResponse::InternalServerError)?; utils::validate_profile_id_from_auth_layer( profile_id_from_auth_layer, &merchant_connector_account, diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs index 4584bee172..00df2908f4 100644 --- a/crates/router/src/lib.rs +++ b/crates/router/src/lib.rs @@ -198,6 +198,11 @@ pub fn mk_app( .service(routes::Routing::server(state.clone())) .service(routes::Chat::server(state.clone())); + #[cfg(all(feature = "olap", any(feature = "v1", feature = "v2")))] + { + server_app = server_app.service(routes::Verify::server(state.clone())); + } + #[cfg(feature = "v1")] { server_app = server_app @@ -208,7 +213,6 @@ pub fn mk_app( .service(routes::ApplePayCertificatesMigration::server(state.clone())) .service(routes::PaymentLink::server(state.clone())) .service(routes::ConnectorOnboarding::server(state.clone())) - .service(routes::Verify::server(state.clone())) .service(routes::Analytics::server(state.clone())) .service(routes::WebhookEvents::server(state.clone())) .service(routes::FeatureMatrix::server(state.clone())); diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 1ff441c570..b5425e55ad 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -56,7 +56,7 @@ use super::refunds; use super::routing; #[cfg(all(feature = "oltp", feature = "v2"))] use super::tokenization as tokenization_routes; -#[cfg(all(feature = "olap", feature = "v1"))] +#[cfg(all(feature = "olap", any(feature = "v1", feature = "v2")))] use super::verification::{apple_pay_merchant_registration, retrieve_apple_pay_verified_domains}; #[cfg(feature = "oltp")] use super::webhooks::*; @@ -2362,7 +2362,6 @@ impl ThreeDsDecisionRule { #[cfg(feature = "olap")] pub struct Verify; - #[cfg(all(feature = "olap", feature = "v1"))] impl Verify { pub fn server(state: AppState) -> Scope { @@ -2379,6 +2378,22 @@ impl Verify { } } +#[cfg(all(feature = "olap", feature = "v2"))] +impl Verify { + pub fn server(state: AppState) -> Scope { + web::scope("/v2/verify") + .app_data(web::Data::new(state)) + .service( + web::resource("/apple-pay/{merchant_id}") + .route(web::post().to(apple_pay_merchant_registration)), + ) + .service( + web::resource("/applepay-verified-domains") + .route(web::get().to(retrieve_apple_pay_verified_domains)), + ) + } +} + pub struct UserDeprecated; #[cfg(all(feature = "olap", feature = "v2"))] diff --git a/crates/router/src/routes/verification.rs b/crates/router/src/routes/verification.rs index ed987fb76a..71b3c12dd7 100644 --- a/crates/router/src/routes/verification.rs +++ b/crates/router/src/routes/verification.rs @@ -46,6 +46,44 @@ pub async fn apple_pay_merchant_registration( .await } +#[cfg(all(feature = "olap", feature = "v2"))] +#[instrument(skip_all, fields(flow = ?Flow::Verification))] +pub async fn apple_pay_merchant_registration( + state: web::Data, + req: HttpRequest, + json_payload: web::Json, + path: web::Path, +) -> impl Responder { + let flow = Flow::Verification; + let merchant_id = path.into_inner(); + Box::pin(api::server_wrap( + flow, + state, + &req, + json_payload.into_inner(), + |state, auth: auth::AuthenticationData, body, _| { + verification::verify_merchant_creds_for_applepay( + state.clone(), + body, + merchant_id.clone(), + Some(auth.profile.get_id().clone()), + ) + }, + auth::auth_type( + &auth::V2ApiKeyAuth { + is_connected_allowed: false, + is_platform_allowed: false, + }, + &auth::JWTAuth { + permission: Permission::ProfileAccountWrite, + }, + req.headers(), + ), + api_locking::LockAction::NotApplicable, + )) + .await +} + #[instrument(skip_all, fields(flow = ?Flow::Verification))] pub async fn retrieve_apple_pay_verified_domains( state: web::Data,