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(router): new get route for derivation of verified applepay domain (#2121)

Prajjwal Kumar177d8e523724
diff --git a/crates/api_models/src/verifications.rs b/crates/api_models/src/verifications.rs
index d7d2b16c71..3cb17fa0e5 100644
--- a/crates/api_models/src/verifications.rs
+++ b/crates/api_models/src/verifications.rs
@@ -21,5 +21,19 @@ pub struct ApplepayMerchantVerificationRequest {
#[serde(rename_all = "camelCase")]
pub struct ApplepayMerchantResponse {
pub status_message: String,
- pub status_code: String,
+ pub status_code: u16,
+}
+
+/// QueryParams to be send by the merchant for fetching the verified domains
+#[derive(Debug, serde::Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ApplepayGetVerifiedDomainsParam {
+ pub business_profile_id: String,
+}
+/// Response to be sent for derivation of the already verified domains
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ApplepayVerifiedDomainsResponse {
+ pub status_code: u16,
+ pub verified_domains: Vec<String>,
}
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index a89de10f39..fb519981d5 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -12,7 +12,7 @@ use super::dummy_connector::*;
#[cfg(feature = "payouts")]
use super::payouts::*;
#[cfg(all(feature = "olap", feature = "kms"))]
-use super::verification::apple_pay_merchant_registration;
+use super::verification::{apple_pay_merchant_registration, retrieve_apple_pay_verified_domains};
#[cfg(feature = "olap")]
use super::{admin::*, api_keys::*, disputes::*, files::*};
use super::{cache::*, health::*};
@@ -589,5 +589,9 @@ impl Verify {
web::resource("/{merchant_id}/apple_pay")
.route(web::post().to(apple_pay_merchant_registration)),
)
+ .service(
+ web::resource("/applepay_verified_domains")
+ .route(web::get().to(retrieve_apple_pay_verified_domains)),
+ )
}
}
diff --git a/crates/router/src/routes/verification.rs b/crates/router/src/routes/verification.rs
index 1de0803170..20b5c18850 100644
--- a/crates/router/src/routes/verification.rs
+++ b/crates/router/src/routes/verification.rs
@@ -9,6 +9,7 @@ use crate::{
utils::verification,
};
+#[cfg(all(feature = "olap", feature = "kms"))]
#[instrument(skip_all, fields(flow = ?Flow::Verification))]
pub async fn apple_pay_merchant_registration(
state: web::Data<AppState>,
@@ -28,3 +29,28 @@ pub async fn apple_pay_merchant_registration(
)
.await
}
+
+#[instrument(skip_all, fields(flow = ?Flow::Verification))]
+pub async fn retrieve_apple_pay_verified_domains(
+ state: web::Data<AppState>,
+ req: HttpRequest,
+ params: web::Query<verifications::ApplepayGetVerifiedDomainsParam>,
+) -> impl Responder {
+ let flow = Flow::Verification;
+ let business_profile_id = &params.business_profile_id;
+
+ api::server_wrap(
+ flow,
+ state.get_ref(),
+ &req,
+ business_profile_id.clone(),
+ |state, _, _| {
+ verification::get_verified_apple_domains_with_business_profile_id(
+ &*state.store,
+ business_profile_id.clone(),
+ )
+ },
+ auth::auth_type(&auth::ApiKeyAuth, &auth::JWTAuth, req.headers()),
+ )
+ .await
+}
diff --git a/crates/router/src/utils/verification.rs b/crates/router/src/utils/verification.rs
index 7bb269e321..46ff6d1fe2 100644
--- a/crates/router/src/utils/verification.rs
+++ b/crates/router/src/utils/verification.rs
@@ -2,13 +2,14 @@ use actix_web::web;
#[cfg(all(feature = "olap", feature = "kms"))]
use api_models::verifications::{self, ApplepayMerchantResponse};
use common_utils::errors::CustomResult;
-use diesel_models::business_profile::{BusinessProfile, BusinessProfileUpdateInternal};
+use diesel_models::business_profile;
use error_stack::{Report, ResultExt};
#[cfg(feature = "kms")]
use external_services::kms;
use crate::{
core::errors::{self, api_error_response},
+ db::StorageInterface,
headers, logger,
routes::AppState,
services, types, utils,
@@ -16,6 +17,27 @@ use crate::{
const APPLEPAY_INTERNAL_MERCHANT_NAME: &str = "Applepay_merchant";
+pub async fn get_verified_apple_domains_with_business_profile_id(
+ db: &dyn StorageInterface,
+ profile_id: String,
+) -> CustomResult<
+ services::ApplicationResponse<api_models::verifications::ApplepayVerifiedDomainsResponse>,
+ api_error_response::ApiErrorResponse,
+> {
+ let verified_domains = db
+ .find_business_profile_by_profile_id(&profile_id)
+ .await
+ .change_context(api_error_response::ApiErrorResponse::ResourceIdNotFound)?
+ .applepay_verified_domains
+ .unwrap_or_default();
+ Ok(services::api::ApplicationResponse::Json(
+ api_models::verifications::ApplepayVerifiedDomainsResponse {
+ status_code: 200,
+ verified_domains,
+ },
+ ))
+}
+
pub async fn verify_merchant_creds_for_applepay(
state: &AppState,
_req: &actix_web::HttpRequest,
@@ -94,14 +116,14 @@ pub async fn verify_merchant_creds_for_applepay(
.await
.change_context(api_error_response::ApiErrorResponse::InternalServerError)?;
services::api::ApplicationResponse::Json(ApplepayMerchantResponse {
- status_code: "200".to_string(),
+ status_code: 200,
status_message: "Applepay verification Completed".to_string(),
})
}
Err(error) => {
logger::error!(?error);
services::api::ApplicationResponse::Json(ApplepayMerchantResponse {
- status_code: "200".to_string(),
+ status_code: 200,
status_message: "Applepay verification Failed".to_string(),
})
}
@@ -113,7 +135,7 @@ async fn check_existence_and_add_domain_to_db(
state: &AppState,
business_profile_id: String,
domain_from_req: Vec<String>,
-) -> CustomResult<BusinessProfile, errors::StorageError> {
+) -> CustomResult<business_profile::BusinessProfile, errors::StorageError> {
let business_profile = state
.store
.find_business_profile_by_profile_id(&business_profile_id)
@@ -130,7 +152,7 @@ async fn check_existence_and_add_domain_to_db(
already_verified_domains.append(&mut new_verified_domains);
- let update_business_profile = BusinessProfileUpdateInternal {
+ let update_business_profile = business_profile::BusinessProfileUpdateInternal {
applepay_verified_domains: Some(already_verified_domains),
profile_name: Some(business_profile.profile_name),
modified_at: Some(business_profile.modified_at),
@@ -154,6 +176,7 @@ async fn check_existence_and_add_domain_to_db(
.update_business_profile_by_profile_id(business_profile_to_update, update_business_profile)
.await
}
+
fn log_applepay_verification_response_if_error(
response: &Result<Result<types::Response, types::Response>, Report<errors::ApiClientError>>,
) {