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(router): saving verified domains to business_profile table (#2109)
Prajjwal Kumar73da641b58bb
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex e0be641fe9..d0b27e53f4 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -1012,6 +1012,9 @@ pub struct BusinessProfileCreate {deserialize_with = "payout_routing_algorithm::deserialize_option")]pub payout_routing_algorithm: Option<serde_json::Value>,++ /// Verified applepay domains for a particular profile+ pub applepay_verified_domains: Option<Vec<String>>,}#[derive(Clone, Debug, ToSchema, Serialize)]@@ -1073,6 +1076,9 @@ pub struct BusinessProfileResponse {deserialize_with = "payout_routing_algorithm::deserialize_option")]pub payout_routing_algorithm: Option<serde_json::Value>,++ /// Verified applepay domains for a particular profile+ pub applepay_verified_domains: Option<Vec<String>>,}#[derive(Clone, Debug, Deserialize, ToSchema)]@@ -1127,4 +1133,7 @@ pub struct BusinessProfileUpdate {deserialize_with = "payout_routing_algorithm::deserialize_option")]pub payout_routing_algorithm: Option<serde_json::Value>,++ /// Verified applepay domains for a particular profile+ pub applepay_verified_domains: Option<Vec<String>>,}diff --git a/crates/api_models/src/verifications.rs b/crates/api_models/src/verifications.rsindex fc5009ce4f..d7d2b16c71 100644--- a/crates/api_models/src/verifications.rs+++ b/crates/api_models/src/verifications.rs@@ -13,6 +13,7 @@ pub struct ApplepayMerchantVerificationConfigs {#[serde(rename_all = "camelCase")]pub struct ApplepayMerchantVerificationRequest {pub domain_names: Vec<String>,+ pub business_profile_id: String,}/// Response to be sent for the verify/applepay apidiff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rsindex 23fe0aed33..f7b7b760f5 100644--- a/crates/diesel_models/src/business_profile.rs+++ b/crates/diesel_models/src/business_profile.rs@@ -30,6 +30,8 @@ pub struct BusinessProfile {pub frm_routing_algorithm: Option<serde_json::Value>,pub payout_routing_algorithm: Option<serde_json::Value>,pub is_recon_enabled: bool,+ #[diesel(deserialize_as = super::OptionalDieselArray<String>)]+ pub applepay_verified_domains: Option<Vec<String>>,}#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]@@ -51,6 +53,8 @@ pub struct BusinessProfileNew {pub frm_routing_algorithm: Option<serde_json::Value>,pub payout_routing_algorithm: Option<serde_json::Value>,pub is_recon_enabled: bool,+ #[diesel(deserialize_as = super::OptionalDieselArray<String>)]+ pub applepay_verified_domains: Option<Vec<String>>,}#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]@@ -69,6 +73,8 @@ pub struct BusinessProfileUpdateInternal {pub frm_routing_algorithm: Option<serde_json::Value>,pub payout_routing_algorithm: Option<serde_json::Value>,pub is_recon_enabled: Option<bool>,+ #[diesel(deserialize_as = super::OptionalDieselArray<String>)]+ pub applepay_verified_domains: Option<Vec<String>>,}impl From<BusinessProfileNew> for BusinessProfile {@@ -90,6 +96,7 @@ impl From<BusinessProfileNew> for BusinessProfile {frm_routing_algorithm: new.frm_routing_algorithm,payout_routing_algorithm: new.payout_routing_algorithm,is_recon_enabled: new.is_recon_enabled,+ applepay_verified_domains: new.applepay_verified_domains,}}}diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 31aa03ff4a..f6c2bed8ab 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -78,6 +78,7 @@ diesel::table! {frm_routing_algorithm -> Nullable<Jsonb>,payout_routing_algorithm -> Nullable<Jsonb>,is_recon_enabled -> Bool,+ applepay_verified_domains -> Nullable<Array<Nullable<Text>>>,}}diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex e146400685..7a3a6055f7 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -1166,6 +1166,7 @@ pub async fn update_business_profile(frm_routing_algorithm: request.frm_routing_algorithm,payout_routing_algorithm: request.payout_routing_algorithm,is_recon_enabled: None,+ applepay_verified_domains: request.applepay_verified_domains,};let updated_business_profile = dbdiff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rsindex 6a73c39bb2..94cdeae85f 100644--- a/crates/router/src/types/api/admin.rs+++ b/crates/router/src/types/api/admin.rs@@ -70,6 +70,7 @@ impl ForeignTryFrom<storage::business_profile::BusinessProfile> for BusinessProfintent_fulfillment_time: item.intent_fulfillment_time,frm_routing_algorithm: item.frm_routing_algorithm,payout_routing_algorithm: item.payout_routing_algorithm,+ applepay_verified_domains: item.applepay_verified_domains,})}}@@ -136,6 +137,7 @@ impl ForeignTryFrom<(domain::MerchantAccount, BusinessProfileCreate)>.payout_routing_algorithm.or(merchant_account.payout_routing_algorithm),is_recon_enabled: merchant_account.is_recon_enabled,+ applepay_verified_domains: request.applepay_verified_domains,})}}diff --git a/crates/router/src/utils/verification.rs b/crates/router/src/utils/verification.rsindex db50a47e35..7bb269e321 100644--- a/crates/router/src/utils/verification.rs+++ b/crates/router/src/utils/verification.rs@@ -1,6 +1,8 @@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 error_stack::{Report, ResultExt};#[cfg(feature = "kms")]use external_services::kms;@@ -19,7 +21,7 @@ pub async fn verify_merchant_creds_for_applepay(_req: &actix_web::HttpRequest,body: web::Json<verifications::ApplepayMerchantVerificationRequest>,kms_config: &kms::KmsConfig,-) -> common_utils::errors::CustomResult<+) -> CustomResult<services::ApplicationResponse<ApplepayMerchantResponse>,api_error_response::ApiErrorResponse,> {@@ -30,7 +32,6 @@ pub async fn verify_merchant_creds_for_applepay(let encrypted_cert = &state.conf.applepay_merchant_configs.merchant_cert;let encrypted_key = &state.conf.applepay_merchant_configs.merchant_cert_key;let applepay_endpoint = &state.conf.applepay_merchant_configs.applepay_endpoint;-let applepay_internal_merchant_identifier = kms::get_kms_client(kms_config).await.decrypt(encrypted_merchant_identifier)@@ -84,10 +85,19 @@ pub async fn verify_merchant_creds_for_applepay(// Error is already loggedOk(match applepay_response {- Ok(_) => services::api::ApplicationResponse::Json(ApplepayMerchantResponse {- status_code: "200".to_string(),- status_message: "Applepay verification Completed".to_string(),- }),+ Ok(_) => {+ check_existence_and_add_domain_to_db(+ state,+ body.business_profile_id.clone(),+ body.domain_names.clone(),+ )+ .await+ .change_context(api_error_response::ApiErrorResponse::InternalServerError)?;+ services::api::ApplicationResponse::Json(ApplepayMerchantResponse {+ status_code: "200".to_string(),+ status_message: "Applepay verification Completed".to_string(),+ })+ }Err(error) => {logger::error!(?error);services::api::ApplicationResponse::Json(ApplepayMerchantResponse {@@ -98,6 +108,52 @@ pub async fn verify_merchant_creds_for_applepay(})}+// Checks whether or not the domain verified is already present in db if not adds it+async fn check_existence_and_add_domain_to_db(+ state: &AppState,+ business_profile_id: String,+ domain_from_req: Vec<String>,+) -> CustomResult<BusinessProfile, errors::StorageError> {+ let business_profile = state+ .store+ .find_business_profile_by_profile_id(&business_profile_id)+ .await?;+ let business_profile_to_update = business_profile.clone();+ let mut already_verified_domains = business_profile+ .applepay_verified_domains+ .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 update_business_profile = BusinessProfileUpdateInternal {+ applepay_verified_domains: Some(already_verified_domains),+ profile_name: Some(business_profile.profile_name),+ modified_at: Some(business_profile.modified_at),+ return_url: business_profile.return_url,+ enable_payment_response_hash: Some(business_profile.enable_payment_response_hash),+ payment_response_hash_key: business_profile.payment_response_hash_key,+ redirect_to_merchant_with_http_post: Some(+ business_profile.redirect_to_merchant_with_http_post,+ ),+ webhook_details: business_profile.webhook_details,+ metadata: business_profile.metadata,+ routing_algorithm: business_profile.routing_algorithm,+ intent_fulfillment_time: business_profile.intent_fulfillment_time,+ frm_routing_algorithm: business_profile.frm_routing_algorithm,+ payout_routing_algorithm: business_profile.payout_routing_algorithm,+ is_recon_enabled: Some(business_profile.is_recon_enabled),+ };++ state+ .store+ .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>>,) {diff --git a/migrations/2023-09-08-112817_applepay_verified_domains_in_business_profile/down.sql b/migrations/2023-09-08-112817_applepay_verified_domains_in_business_profile/down.sqlnew file mode 100644index 0000000000..20c2ce7a52--- /dev/null+++ b/migrations/2023-09-08-112817_applepay_verified_domains_in_business_profile/down.sql@@ -0,0 +1,2 @@+ALTER TABLE business_profile DROP COLUMN IF EXISTS applepay_verified_domains;+diff --git a/migrations/2023-09-08-112817_applepay_verified_domains_in_business_profile/up.sql b/migrations/2023-09-08-112817_applepay_verified_domains_in_business_profile/up.sqlnew file mode 100644index 0000000000..8643a2f30a--- /dev/null+++ b/migrations/2023-09-08-112817_applepay_verified_domains_in_business_profile/up.sql@@ -0,0 +1,3 @@+ALTER TABLE business_profile+ADD COLUMN IF NOT EXISTS applepay_verified_domains text[];+