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): collect billing details from wallet connector based on the `collect_billing_details_from_wallet_connector` field (#5065)
Shankar Singh Cee9190bf4f29
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.jsonindex 4bb9346942..d2bfebcc42 100644--- a/api-reference/openapi_spec.json+++ b/api-reference/openapi_spec.json@@ -6959,7 +6959,16 @@},"collect_shipping_details_from_wallet_connector": {"type": "boolean",- "description": "A boolean value to indicate if customer shipping details needs to be sent for wallets payments",+ "description": "A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)",+ "default": false,+ "example": false,+ "nullable": true+ },+ "collect_billing_details_from_wallet_connector": {+ "type": "boolean",+ "description": "A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)",+ "default": false,+ "example": false,"nullable": true},"is_connector_agnostic_mit_enabled": {@@ -7108,7 +7117,16 @@},"collect_shipping_details_from_wallet_connector": {"type": "boolean",- "description": "A boolean value to indicate if customer shipping details needs to be sent for wallets payments",+ "description": "A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)",+ "default": false,+ "example": false,+ "nullable": true+ },+ "collect_billing_details_from_wallet_connector": {+ "type": "boolean",+ "description": "A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)",+ "default": false,+ "example": false,"nullable": true},"is_connector_agnostic_mit_enabled": {diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex 81761fac70..58e11c4d0d 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -950,9 +950,14 @@ pub struct BusinessProfileCreate {/// Whether to use the billing details passed when creating the intent as payment method billingpub use_billing_as_payment_method_billing: Option<bool>,- /// A boolean value to indicate if customer shipping details needs to be sent for wallets payments+ /// A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)+ #[schema(default = false, example = false)]pub collect_shipping_details_from_wallet_connector: Option<bool>,+ /// A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)+ #[schema(default = false, example = false)]+ pub collect_billing_details_from_wallet_connector: Option<bool>,+/// Indicates if the MIT (merchant initiated transaction) payments can be made connector/// agnostic, i.e., MITs may be processed through different connector than CIT (customer/// initiated transaction) based on the routing rules.@@ -1038,9 +1043,14 @@ pub struct BusinessProfileResponse {/// Merchant's config to support extended card info featurepub extended_card_info_config: Option<ExtendedCardInfoConfig>,- /// A boolean value to indicate if customer shipping details needs to be sent for wallets payments+ /// A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)+ #[schema(default = false, example = false)]pub collect_shipping_details_from_wallet_connector: Option<bool>,+ /// A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)+ #[schema(default = false, example = false)]+ pub collect_billing_details_from_wallet_connector: Option<bool>,+/// Indicates if the MIT (merchant initiated transaction) payments can be made connector/// agnostic, i.e., MITs may be processed through different connector than CIT (customer/// initiated transaction) based on the routing rules.@@ -1118,9 +1128,14 @@ pub struct BusinessProfileUpdate {// Whether to use the billing details passed when creating the intent as payment method billingpub use_billing_as_payment_method_billing: Option<bool>,- /// A boolean value to indicate if customer shipping details needs to be sent for wallets payments+ /// A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)+ #[schema(default = false, example = false)]pub collect_shipping_details_from_wallet_connector: Option<bool>,+ /// A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)+ #[schema(default = false, example = false)]+ pub collect_billing_details_from_wallet_connector: Option<bool>,+/// Indicates if the MIT (merchant initiated transaction) payments can be made connector/// agnostic, i.e., MITs may be processed through different connector than CIT (customer/// initiated transaction) based on the routing rules.diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex cd36c53a12..d8321524a1 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -4135,6 +4135,7 @@ pub struct GpayAllowedMethodsParameters {/// The list of allowed card networks (ex: AMEX,JCB etc)pub allowed_card_networks: Vec<String>,/// Is billing address required+ #[serde(skip_serializing_if = "Option::is_none")]pub billing_address_required: Option<bool>,/// Billing address parameters#[serde(skip_serializing_if = "Option::is_none")]diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rsindex b956140a65..48eedc6110 100644--- a/crates/diesel_models/src/business_profile.rs+++ b/crates/diesel_models/src/business_profile.rs@@ -41,6 +41,7 @@ pub struct BusinessProfile {pub is_connector_agnostic_mit_enabled: Option<bool>,pub use_billing_as_payment_method_billing: Option<bool>,pub collect_shipping_details_from_wallet_connector: Option<bool>,+ pub collect_billing_details_from_wallet_connector: Option<bool>,}#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]@@ -73,6 +74,7 @@ pub struct BusinessProfileNew {pub is_connector_agnostic_mit_enabled: Option<bool>,pub use_billing_as_payment_method_billing: Option<bool>,pub collect_shipping_details_from_wallet_connector: Option<bool>,+ pub collect_billing_details_from_wallet_connector: Option<bool>,}#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]@@ -102,6 +104,7 @@ pub struct BusinessProfileUpdateInternal {pub is_connector_agnostic_mit_enabled: Option<bool>,pub use_billing_as_payment_method_billing: Option<bool>,pub collect_shipping_details_from_wallet_connector: Option<bool>,+ pub collect_billing_details_from_wallet_connector: Option<bool>,}#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]@@ -128,6 +131,7 @@ pub enum BusinessProfileUpdate {extended_card_info_config: Option<pii::SecretSerdeValue>,use_billing_as_payment_method_billing: Option<bool>,collect_shipping_details_from_wallet_connector: Option<bool>,+ collect_billing_details_from_wallet_connector: Option<bool>,is_connector_agnostic_mit_enabled: Option<bool>,},ExtendedCardInfoUpdate {@@ -163,6 +167,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {extended_card_info_config,use_billing_as_payment_method_billing,collect_shipping_details_from_wallet_connector,+ collect_billing_details_from_wallet_connector,is_connector_agnostic_mit_enabled,} => Self {profile_name,@@ -186,6 +191,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {extended_card_info_config,use_billing_as_payment_method_billing,collect_shipping_details_from_wallet_connector,+ collect_billing_details_from_wallet_connector,is_connector_agnostic_mit_enabled,..Default::default()},@@ -235,6 +241,8 @@ impl From<BusinessProfileNew> for BusinessProfile {use_billing_as_payment_method_billing: new.use_billing_as_payment_method_billing,collect_shipping_details_from_wallet_connector: new.collect_shipping_details_from_wallet_connector,+ collect_billing_details_from_wallet_connector: new+ .collect_billing_details_from_wallet_connector,}}}@@ -265,6 +273,7 @@ impl BusinessProfileUpdate {is_connector_agnostic_mit_enabled,use_billing_as_payment_method_billing,collect_shipping_details_from_wallet_connector,+ collect_billing_details_from_wallet_connector,} = self.into();BusinessProfile {profile_name: profile_name.unwrap_or(source.profile_name),@@ -292,6 +301,7 @@ impl BusinessProfileUpdate {extended_card_info_config,use_billing_as_payment_method_billing,collect_shipping_details_from_wallet_connector,+ collect_billing_details_from_wallet_connector,..source}}diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 6149af1f50..98f1b2fbbe 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -203,6 +203,7 @@ diesel::table! {is_connector_agnostic_mit_enabled -> Nullable<Bool>,use_billing_as_payment_method_billing -> Nullable<Bool>,collect_shipping_details_from_wallet_connector -> Nullable<Bool>,+ collect_billing_details_from_wallet_connector -> Nullable<Bool>,}}diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 7d69b7f997..b86fed02f3 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -456,6 +456,7 @@ pub async fn update_business_profile_cascade(extended_card_info_config: None,use_billing_as_payment_method_billing: None,collect_shipping_details_from_wallet_connector: None,+ collect_billing_details_from_wallet_connector: None,is_connector_agnostic_mit_enabled: None,};@@ -1723,6 +1724,8 @@ pub async fn update_business_profile(use_billing_as_payment_method_billing: request.use_billing_as_payment_method_billing,collect_shipping_details_from_wallet_connector: request.collect_shipping_details_from_wallet_connector,+ collect_billing_details_from_wallet_connector: request+ .collect_billing_details_from_wallet_connector,is_connector_agnostic_mit_enabled: request.is_connector_agnostic_mit_enabled,};diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rsindex 1223d861eb..43900ac2b6 100644--- a/crates/router/src/core/payments/flows/session_flow.rs+++ b/crates/router/src/core/payments/flows/session_flow.rs@@ -295,23 +295,29 @@ async fn create_applepay_session_token(router_data.request.to_owned(),)?;- let billing_variants = enums::FieldType::get_billing_variants();-- let required_billing_contact_fields = is_dynamic_fields_required(- &state.conf.required_fields,- enums::PaymentMethod::Wallet,- enums::PaymentMethodType::ApplePay,- &connector.connector_name,- billing_variants,- )- .then_some(payment_types::ApplePayBillingContactFields(vec![- payment_types::ApplePayAddressParameters::PostalAddress,- ]));+ let required_billing_contact_fields = business_profile+ .collect_billing_details_from_wallet_connector+ .unwrap_or(false)+ .then_some({+ let billing_variants = enums::FieldType::get_billing_variants();+ is_dynamic_fields_required(+ &state.conf.required_fields,+ enums::PaymentMethod::Wallet,+ enums::PaymentMethodType::ApplePay,+ &connector.connector_name,+ billing_variants,+ )+ .then_some(payment_types::ApplePayBillingContactFields(vec![+ payment_types::ApplePayAddressParameters::PostalAddress,+ ]))+ })+ .flatten();- let required_shipping_contact_fields =- if business_profile.collect_shipping_details_from_wallet_connector == Some(true) {+ let required_shipping_contact_fields = business_profile+ .collect_shipping_details_from_wallet_connector+ .unwrap_or(false)+ .then_some({let shipping_variants = enums::FieldType::get_shipping_variants();-is_dynamic_fields_required(&state.conf.required_fields,enums::PaymentMethod::Wallet,@@ -324,9 +330,8 @@ async fn create_applepay_session_token(payment_types::ApplePayAddressParameters::Phone,payment_types::ApplePayAddressParameters::Email,]))- } else {- None- };+ })+ .flatten();// Get apple pay payment requestlet applepay_payment_request = get_apple_pay_payment_request(@@ -562,15 +567,20 @@ fn create_gpay_session_token(expected_format: "gpay_metadata_format".to_string(),})?;- let billing_variants = enums::FieldType::get_billing_variants();+ let is_billing_details_required =+ if business_profile.collect_billing_details_from_wallet_connector == Some(true) {+ let billing_variants = enums::FieldType::get_billing_variants();- let is_billing_details_required = is_dynamic_fields_required(- &state.conf.required_fields,- enums::PaymentMethod::Wallet,- enums::PaymentMethodType::GooglePay,- &connector.connector_name,- billing_variants,- );+ is_dynamic_fields_required(+ &state.conf.required_fields,+ enums::PaymentMethod::Wallet,+ enums::PaymentMethodType::GooglePay,+ &connector.connector_name,+ billing_variants,+ )+ } else {+ false+ };let billing_address_parameters =is_billing_details_required.then_some(payment_types::GpayBillingAddressParameters {diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rsindex caa976580b..b9f5da13cf 100644--- a/crates/router/src/core/routing/helpers.rs+++ b/crates/router/src/core/routing/helpers.rs@@ -285,6 +285,7 @@ pub async fn update_business_profile_active_algorithm_ref(extended_card_info_config: None,use_billing_as_payment_method_billing: None,collect_shipping_details_from_wallet_connector: None,+ collect_billing_details_from_wallet_connector: None,is_connector_agnostic_mit_enabled: None,};diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rsindex 77693157f6..36c3ba9621 100644--- a/crates/router/src/types/api/admin.rs+++ b/crates/router/src/types/api/admin.rs@@ -99,6 +99,8 @@ impl ForeignTryFrom<storage::business_profile::BusinessProfile> for BusinessProf.transpose()?,collect_shipping_details_from_wallet_connector: item.collect_shipping_details_from_wallet_connector,+ collect_billing_details_from_wallet_connector: item+ .collect_billing_details_from_wallet_connector,is_connector_agnostic_mit_enabled: item.is_connector_agnostic_mit_enabled,})}@@ -211,7 +213,11 @@ impl ForeignTryFrom<(domain::MerchantAccount, BusinessProfileCreate)>.use_billing_as_payment_method_billing.or(Some(true)),collect_shipping_details_from_wallet_connector: request- .collect_shipping_details_from_wallet_connector,+ .collect_shipping_details_from_wallet_connector+ .or(Some(false)),+ collect_billing_details_from_wallet_connector: request+ .collect_billing_details_from_wallet_connector+ .or(Some(false)),})}}diff --git a/migrations/2024-06-20-142013_collect_billing_details_from_wallet_connector/down.sql b/migrations/2024-06-20-142013_collect_billing_details_from_wallet_connector/down.sqlnew file mode 100644index 0000000000..417bdac8b5--- /dev/null+++ b/migrations/2024-06-20-142013_collect_billing_details_from_wallet_connector/down.sql@@ -0,0 +1,3 @@+-- This file should undo anything in `up.sql`++ALTER TABLE business_profile DROP COLUMN IF EXISTS collect_billing_details_from_wallet_connector;\ No newline at end of filediff --git a/migrations/2024-06-20-142013_collect_billing_details_from_wallet_connector/up.sql b/migrations/2024-06-20-142013_collect_billing_details_from_wallet_connector/up.sqlnew file mode 100644index 0000000000..edfda3f468--- /dev/null+++ b/migrations/2024-06-20-142013_collect_billing_details_from_wallet_connector/up.sql@@ -0,0 +1,3 @@+-- Your SQL goes here++ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS collect_billing_details_from_wallet_connector BOOLEAN DEFAULT FALSE;\ No newline at end of file