-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(router): get route for applepay_verified_domains (#2157)
- Loading branch information
1 parent
05696d3
commit fb1760b
Showing
7 changed files
with
157 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use common_utils::errors::CustomResult; | ||
use error_stack::{Report, ResultExt}; | ||
|
||
use crate::{ | ||
core::errors::{self, utils::StorageErrorExt}, | ||
logger, | ||
routes::AppState, | ||
types, | ||
types::storage, | ||
}; | ||
|
||
pub async fn check_existence_and_add_domain_to_db( | ||
state: &AppState, | ||
merchant_id: String, | ||
merchant_connector_id: String, | ||
domain_from_req: Vec<String>, | ||
) -> CustomResult<Vec<String>, errors::ApiErrorResponse> { | ||
let key_store = state | ||
.store | ||
.get_merchant_key_store_by_merchant_id( | ||
&merchant_id, | ||
&state.store.get_master_key().to_vec().into(), | ||
) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?; | ||
|
||
let merchant_connector_account = state | ||
.store | ||
.find_by_merchant_connector_account_merchant_id_merchant_connector_id( | ||
&merchant_id, | ||
&merchant_connector_id, | ||
&key_store, | ||
) | ||
.await | ||
.change_context(errors::ApiErrorResponse::InternalServerError)?; | ||
|
||
let mut already_verified_domains = merchant_connector_account | ||
.applepay_verified_domains | ||
.clone() | ||
.unwrap_or_default(); | ||
|
||
let mut new_verified_domains: Vec<String> = domain_from_req | ||
.into_iter() | ||
.filter(|req_domain| !already_verified_domains.contains(req_domain)) | ||
.collect(); | ||
|
||
already_verified_domains.append(&mut new_verified_domains); | ||
let updated_mca = storage::MerchantConnectorAccountUpdate::Update { | ||
merchant_id: None, | ||
connector_type: None, | ||
connector_name: None, | ||
connector_account_details: None, | ||
test_mode: None, | ||
disabled: None, | ||
merchant_connector_id: None, | ||
payment_methods_enabled: None, | ||
metadata: None, | ||
frm_configs: None, | ||
connector_webhook_details: None, | ||
applepay_verified_domains: Some(already_verified_domains.clone()), | ||
}; | ||
state | ||
.store | ||
.update_merchant_connector_account( | ||
merchant_connector_account, | ||
updated_mca.into(), | ||
&key_store, | ||
) | ||
.await | ||
.change_context(errors::ApiErrorResponse::InternalServerError) | ||
.attach_printable_lazy(|| { | ||
format!("Failed while updating MerchantConnectorAccount: id: {merchant_connector_id}") | ||
})?; | ||
|
||
Ok(already_verified_domains.clone()) | ||
} | ||
|
||
pub fn log_applepay_verification_response_if_error( | ||
response: &Result<Result<types::Response, types::Response>, Report<errors::ApiClientError>>, | ||
) { | ||
if let Err(error) = response.as_ref() { | ||
logger::error!(applepay_domain_verification_error= ?error); | ||
}; | ||
response.as_ref().ok().map(|res| { | ||
res.as_ref() | ||
.map_err(|error| logger::error!(applepay_domain_verification_error= ?error)) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters