feat(router): collect billing details from wallet connector based on the collect_billing_details_from_wallet_connector field (#5065)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Shankar Singh C
2024-07-02 13:24:50 +05:30
committed by GitHub
parent 045e9742bd
commit ee9190bf4f
11 changed files with 103 additions and 32 deletions

View File

@ -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": {

View File

@ -950,9 +950,14 @@ pub struct BusinessProfileCreate {
/// Whether to use the billing details passed when creating the intent as payment method billing
pub 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 feature
pub 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 billing
pub 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.

View File

@ -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")]

View File

@ -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
}
}

View File

@ -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>,
}
}

View File

@ -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,
};

View File

@ -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 = 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_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_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 request
let 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 {

View File

@ -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,
};

View File

@ -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)),
})
}
}

View File

@ -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;

View File

@ -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;