Skip to content

Commit 177d8e5

Browse files
feat(router): new get route for derivation of verified applepay domain (#2121)
1 parent fea5c4d commit 177d8e5

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

crates/api_models/src/verifications.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,19 @@ pub struct ApplepayMerchantVerificationRequest {
2121
#[serde(rename_all = "camelCase")]
2222
pub struct ApplepayMerchantResponse {
2323
pub status_message: String,
24-
pub status_code: String,
24+
pub status_code: u16,
25+
}
26+
27+
/// QueryParams to be send by the merchant for fetching the verified domains
28+
#[derive(Debug, serde::Deserialize)]
29+
#[serde(rename_all = "camelCase")]
30+
pub struct ApplepayGetVerifiedDomainsParam {
31+
pub business_profile_id: String,
32+
}
33+
/// Response to be sent for derivation of the already verified domains
34+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
35+
#[serde(rename_all = "camelCase")]
36+
pub struct ApplepayVerifiedDomainsResponse {
37+
pub status_code: u16,
38+
pub verified_domains: Vec<String>,
2539
}

crates/router/src/routes/app.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::dummy_connector::*;
1212
#[cfg(feature = "payouts")]
1313
use super::payouts::*;
1414
#[cfg(all(feature = "olap", feature = "kms"))]
15-
use super::verification::apple_pay_merchant_registration;
15+
use super::verification::{apple_pay_merchant_registration, retrieve_apple_pay_verified_domains};
1616
#[cfg(feature = "olap")]
1717
use super::{admin::*, api_keys::*, disputes::*, files::*};
1818
use super::{cache::*, health::*};
@@ -589,5 +589,9 @@ impl Verify {
589589
web::resource("/{merchant_id}/apple_pay")
590590
.route(web::post().to(apple_pay_merchant_registration)),
591591
)
592+
.service(
593+
web::resource("/applepay_verified_domains")
594+
.route(web::get().to(retrieve_apple_pay_verified_domains)),
595+
)
592596
}
593597
}

crates/router/src/routes/verification.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
utils::verification,
1010
};
1111

12+
#[cfg(all(feature = "olap", feature = "kms"))]
1213
#[instrument(skip_all, fields(flow = ?Flow::Verification))]
1314
pub async fn apple_pay_merchant_registration(
1415
state: web::Data<AppState>,
@@ -28,3 +29,28 @@ pub async fn apple_pay_merchant_registration(
2829
)
2930
.await
3031
}
32+
33+
#[instrument(skip_all, fields(flow = ?Flow::Verification))]
34+
pub async fn retrieve_apple_pay_verified_domains(
35+
state: web::Data<AppState>,
36+
req: HttpRequest,
37+
params: web::Query<verifications::ApplepayGetVerifiedDomainsParam>,
38+
) -> impl Responder {
39+
let flow = Flow::Verification;
40+
let business_profile_id = &params.business_profile_id;
41+
42+
api::server_wrap(
43+
flow,
44+
state.get_ref(),
45+
&req,
46+
business_profile_id.clone(),
47+
|state, _, _| {
48+
verification::get_verified_apple_domains_with_business_profile_id(
49+
&*state.store,
50+
business_profile_id.clone(),
51+
)
52+
},
53+
auth::auth_type(&auth::ApiKeyAuth, &auth::JWTAuth, req.headers()),
54+
)
55+
.await
56+
}

crates/router/src/utils/verification.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,42 @@ use actix_web::web;
22
#[cfg(all(feature = "olap", feature = "kms"))]
33
use api_models::verifications::{self, ApplepayMerchantResponse};
44
use common_utils::errors::CustomResult;
5-
use diesel_models::business_profile::{BusinessProfile, BusinessProfileUpdateInternal};
5+
use diesel_models::business_profile;
66
use error_stack::{Report, ResultExt};
77
#[cfg(feature = "kms")]
88
use external_services::kms;
99

1010
use crate::{
1111
core::errors::{self, api_error_response},
12+
db::StorageInterface,
1213
headers, logger,
1314
routes::AppState,
1415
services, types, utils,
1516
};
1617

1718
const APPLEPAY_INTERNAL_MERCHANT_NAME: &str = "Applepay_merchant";
1819

20+
pub async fn get_verified_apple_domains_with_business_profile_id(
21+
db: &dyn StorageInterface,
22+
profile_id: String,
23+
) -> CustomResult<
24+
services::ApplicationResponse<api_models::verifications::ApplepayVerifiedDomainsResponse>,
25+
api_error_response::ApiErrorResponse,
26+
> {
27+
let verified_domains = db
28+
.find_business_profile_by_profile_id(&profile_id)
29+
.await
30+
.change_context(api_error_response::ApiErrorResponse::ResourceIdNotFound)?
31+
.applepay_verified_domains
32+
.unwrap_or_default();
33+
Ok(services::api::ApplicationResponse::Json(
34+
api_models::verifications::ApplepayVerifiedDomainsResponse {
35+
status_code: 200,
36+
verified_domains,
37+
},
38+
))
39+
}
40+
1941
pub async fn verify_merchant_creds_for_applepay(
2042
state: &AppState,
2143
_req: &actix_web::HttpRequest,
@@ -94,14 +116,14 @@ pub async fn verify_merchant_creds_for_applepay(
94116
.await
95117
.change_context(api_error_response::ApiErrorResponse::InternalServerError)?;
96118
services::api::ApplicationResponse::Json(ApplepayMerchantResponse {
97-
status_code: "200".to_string(),
119+
status_code: 200,
98120
status_message: "Applepay verification Completed".to_string(),
99121
})
100122
}
101123
Err(error) => {
102124
logger::error!(?error);
103125
services::api::ApplicationResponse::Json(ApplepayMerchantResponse {
104-
status_code: "200".to_string(),
126+
status_code: 200,
105127
status_message: "Applepay verification Failed".to_string(),
106128
})
107129
}
@@ -113,7 +135,7 @@ async fn check_existence_and_add_domain_to_db(
113135
state: &AppState,
114136
business_profile_id: String,
115137
domain_from_req: Vec<String>,
116-
) -> CustomResult<BusinessProfile, errors::StorageError> {
138+
) -> CustomResult<business_profile::BusinessProfile, errors::StorageError> {
117139
let business_profile = state
118140
.store
119141
.find_business_profile_by_profile_id(&business_profile_id)
@@ -130,7 +152,7 @@ async fn check_existence_and_add_domain_to_db(
130152

131153
already_verified_domains.append(&mut new_verified_domains);
132154

133-
let update_business_profile = BusinessProfileUpdateInternal {
155+
let update_business_profile = business_profile::BusinessProfileUpdateInternal {
134156
applepay_verified_domains: Some(already_verified_domains),
135157
profile_name: Some(business_profile.profile_name),
136158
modified_at: Some(business_profile.modified_at),
@@ -154,6 +176,7 @@ async fn check_existence_and_add_domain_to_db(
154176
.update_business_profile_by_profile_id(business_profile_to_update, update_business_profile)
155177
.await
156178
}
179+
157180
fn log_applepay_verification_response_if_error(
158181
response: &Result<Result<types::Response, types::Response>, Report<errors::ApiClientError>>,
159182
) {

0 commit comments

Comments
 (0)