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(payment_links): Add Validation On Not Allowing Custom T&C When Domain is set to Hyperswitch Hosted (#10355)
Sayak Bhattacharyaf19d0676b3c6
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex ccd89e9883..dd8979beeb 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -24813,6 +24813,11 @@"type": "string","description": "Hex color for the CVC icon during error state","nullable": true+ },+ "payment_test_mode": {+ "type": "boolean",+ "description": "Indicates whether the merchant is testing or live",+ "nullable": true}}},diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 798a87b5ac..e1218c55df 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -18116,6 +18116,11 @@"type": "string","description": "Hex color for the CVC icon during error state","nullable": true+ },+ "payment_test_mode": {+ "type": "boolean",+ "description": "Indicates whether the merchant is testing or live",+ "nullable": true}}},diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex 9bbcc9a45c..58e9f01e5e 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -3389,6 +3389,8 @@ pub struct PaymentLinkConfigRequest {pub is_setup_mandate_flow: Option<bool>,/// Hex color for the CVC icon during error statepub color_icon_card_cvc_error: Option<String>,+ /// Indicates whether the merchant is testing or live+ pub payment_test_mode: Option<bool>,}#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rsindex 0b8ff3043b..a7ac93805e 100644--- a/crates/hyperswitch_domain_models/src/lib.rs+++ b/crates/hyperswitch_domain_models/src/lib.rs@@ -596,6 +596,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>show_card_terms,is_setup_mandate_flow,color_icon_card_cvc_error,+ payment_test_mode: None,}}}diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rsindex 611bc45fbe..f26a8f04ed 100644--- a/crates/router/src/core/payment_link.rs+++ b/crates/router/src/core/payment_link.rs@@ -619,7 +619,7 @@ pub fn get_payment_link_config_based_on_priority(payment_link_config_id: Option<String>,) -> Result<(PaymentLinkConfig, String), error_stack::Report<errors::ApiErrorResponse>> {let (domain_name, business_theme_configs, allowed_domains, branding_visibility) =- if let Some(business_config) = business_link_config {+ if let Some(ref business_config) = business_link_config {(business_config.domain_name@@ -630,18 +630,19 @@ pub fn get_payment_link_config_based_on_priority(}).unwrap_or_else(|| default_domain_name.clone()),payment_link_config_id+ .as_ref().and_then(|id| {business_config.business_specific_configs.as_ref()- .and_then(|specific_configs| specific_configs.get(&id).cloned())+ .and_then(|specific_configs| specific_configs.get(id).cloned())})- .or(business_config.default_config),- business_config.allowed_domains,+ .or(business_config.default_config.clone()),+ business_config.allowed_domains.clone(),business_config.branding_visibility,)} else {- (default_domain_name, None, None, None)+ (default_domain_name.clone(), None, None, None)};let (@@ -747,6 +748,47 @@ pub fn get_payment_link_config_based_on_priority(color_icon_card_cvc_error,};+ let has_custom_tnc = payment_link_config.custom_message_for_card_terms.is_some()+ || payment_link_config+ .custom_message_for_payment_method_types+ .is_some();+ let is_default_domain = domain_name == default_domain_name;+ let is_test_mode = payment_create_link_config+ .and_then(|mode| mode.theme_config.payment_test_mode)+ .unwrap_or(false);+ let is_production = matches!(router_env::env::which(), router_env::Env::Production);++ // We do further checks only when Merchant is using our default domain and has passed custom T&C -> Which is not allowed to do+ if is_default_domain && has_custom_tnc {+ match (is_test_mode, is_production) {+ // Custom T&C cannot be passed when base url is default domain+ (false, true) => {+ return Err(errors::ApiErrorResponse::InvalidRequestData {+ message: format!(+ "payment_link_config.custom_message_for_card_terms cannot be passed when base url is set to: {domain_name}"+ ),+ }+ .into())+ }+ // Test mode must be true to pass custom tnc+ (false, false) => {+ return Err(errors::ApiErrorResponse::InvalidRequestData {+ message: "To pass payment_link_config.custom_message_for_card_terms, set payment_link_config.payment_test_mode = true".to_string()+ }+ .into(),+ )}+ // Test Mode cannot be set to True when Env is Production+ (true, true) => {+ return Err(errors::ApiErrorResponse::InvalidRequestData {+ message: "Cannot set payment_link_config.payment_test_mode = true in Production".to_string()+ }+ .into(),+ )}+ // Test mode is true and the env is non Production so we are allowed to pass custom T&C with our default domain+ (true,false) => ()+ }+ }+Ok((payment_link_config, domain_name))}diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex f1c4537a66..71e3ea3d89 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -6667,6 +6667,7 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>show_card_terms: config.show_card_terms,is_setup_mandate_flow: config.is_setup_mandate_flow,color_icon_card_cvc_error: config.color_icon_card_cvc_error,+ payment_test_mode: None,}}}diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex befac790f1..910ad0b634 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -2205,6 +2205,7 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>show_card_terms: item.show_card_terms,is_setup_mandate_flow: item.is_setup_mandate_flow,color_icon_card_cvc_error: item.color_icon_card_cvc_error,+ payment_test_mode: None,}}}