From c0518c1136d24c4e7bd82ceb244fb23ec23a5547 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Thu, 4 Jul 2024 17:24:26 +0530 Subject: [PATCH 1/3] feat(router): pass fields to indicate if the customer address deatils to be connector from wallets --- crates/api_models/src/payment_methods.rs | 6 ++++++ crates/router/src/core/payment_methods/cards.rs | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index 0e2fd7b70393..6dbf20ef8ae9 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -795,6 +795,12 @@ pub struct PaymentMethodListResponse { /// flag to indicate whether to perform external 3ds authentication #[schema(example = true)] pub request_external_three_ds_authentication: bool, + + /// flag to indicate whether to collect shipping details from wallets or customer + pub collect_shipping_details_from_wallets: Option, + + /// flag to indicate whether to collect billing details from wallets or customer + pub collect_billing_details_from_wallets: Option, } #[derive(Eq, PartialEq, Hash, Debug, serde::Deserialize, ToSchema)] diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index e58e16cc631d..9180b8977abc 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -2703,14 +2703,14 @@ pub async fn list_payment_methods( if let Some((payment_attempt, payment_intent, business_profile)) = payment_attempt .as_ref() .zip(payment_intent) - .zip(business_profile) + .zip(business_profile.as_ref()) .map(|((pa, pi), bp)| (pa, pi, bp)) { Box::pin(call_surcharge_decision_management( state, &merchant_account, &key_store, - &business_profile, + business_profile, payment_attempt, payment_intent, billing_address, @@ -2720,6 +2720,14 @@ pub async fn list_payment_methods( } else { api_surcharge_decision_configs::MerchantSurchargeConfigs::default() }; + + let collect_shipping_details_from_wallets = business_profile + .as_ref() + .and_then(|bp| bp.collect_shipping_details_from_wallet_connector); + + let collect_billing_details_from_wallets = business_profile + .as_ref() + .and_then(|bp| bp.collect_billing_details_from_wallet_connector); Ok(services::ApplicationResponse::Json( api::PaymentMethodListResponse { redirect_url: merchant_account.return_url, @@ -2756,6 +2764,8 @@ pub async fn list_payment_methods( .unwrap_or_default(), currency, request_external_three_ds_authentication, + collect_shipping_details_from_wallets, + collect_billing_details_from_wallets, }, )) } From c270ea5d6deaf6ba8f81dbc3de2ca372dcc11c9f Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Thu, 4 Jul 2024 17:43:25 +0530 Subject: [PATCH 2/3] update the openapi spec --- api-reference/openapi_spec.json | 10 ++++++++++ crates/api_models/src/payment_methods.rs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index cbad4558da42..af5d1bbefcac 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -14278,6 +14278,16 @@ "type": "boolean", "description": "flag to indicate whether to perform external 3ds authentication", "example": true + }, + "collect_shipping_details_from_wallets": { + "type": "boolean", + "description": "flag that indicates whether to collect shipping details from wallets or from the customer", + "nullable": true + }, + "collect_billing_details_from_wallets": { + "type": "boolean", + "description": "flag that indicates whether to collect billing details from wallets or from the customer", + "nullable": true } } }, diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index 6dbf20ef8ae9..c8826c02089f 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -796,10 +796,10 @@ pub struct PaymentMethodListResponse { #[schema(example = true)] pub request_external_three_ds_authentication: bool, - /// flag to indicate whether to collect shipping details from wallets or customer + /// flag that indicates whether to collect shipping details from wallets or from the customer pub collect_shipping_details_from_wallets: Option, - /// flag to indicate whether to collect billing details from wallets or customer + /// flag that indicates whether to collect billing details from wallets or from the customer pub collect_billing_details_from_wallets: Option, } From e57016d06f759726cada1ecea4afa7db2f3418fb Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Fri, 5 Jul 2024 14:35:03 +0530 Subject: [PATCH 3/3] add header payload check in the create_apple_pay_session_response --- .../src/core/payments/flows/session_flow.rs | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs index 43900ac2b649..b52cf98b2874 100644 --- a/crates/router/src/core/payments/flows/session_flow.rs +++ b/crates/router/src/core/payments/flows/session_flow.rs @@ -170,6 +170,7 @@ async fn create_applepay_session_token( connector.connector_name.to_string(), delayed_response, payment_types::NextActionCall::Confirm, + header_payload, ) } else { // Get the apple pay metadata @@ -345,8 +346,8 @@ async fn create_applepay_session_token( )?; let apple_pay_session_response = match ( - header_payload.browser_name, - header_payload.x_client_platform, + header_payload.browser_name.clone(), + header_payload.x_client_platform.clone(), ) { (Some(common_enums::BrowserName::Safari), Some(common_enums::ClientPlatform::Web)) | (None, None) => { @@ -406,6 +407,7 @@ async fn create_applepay_session_token( connector.connector_name.to_string(), delayed_response, payment_types::NextActionCall::Confirm, + header_payload, ) } } @@ -489,6 +491,7 @@ fn create_apple_pay_session_response( connector_name: String, delayed_response: bool, next_action: payment_types::NextActionCall, + header_payload: api_models::payments::HeaderPayload, ) -> RouterResult { match session_response { Some(response) => Ok(types::PaymentsSessionRouterData { @@ -508,23 +511,40 @@ fn create_apple_pay_session_response( }), ..router_data.clone() }), - None => Ok(types::PaymentsSessionRouterData { - response: Ok(types::PaymentsResponseData::SessionResponse { - session_token: payment_types::SessionToken::ApplePay(Box::new( - payment_types::ApplepaySessionTokenResponse { - session_token_data: None, - payment_request_data: apple_pay_payment_request, - connector: connector_name, - delayed_session_token: delayed_response, - sdk_next_action: { payment_types::SdkNextAction { next_action } }, - connector_reference_id: None, - connector_sdk_public_key: None, - connector_merchant_id: None, - }, - )), - }), - ..router_data.clone() - }), + None => { + match ( + header_payload.browser_name, + header_payload.x_client_platform, + ) { + ( + Some(common_enums::BrowserName::Safari), + Some(common_enums::ClientPlatform::Web), + ) + | (None, None) => Ok(types::PaymentsSessionRouterData { + response: Ok(types::PaymentsResponseData::SessionResponse { + session_token: payment_types::SessionToken::NoSessionTokenReceived, + }), + ..router_data.clone() + }), + _ => Ok(types::PaymentsSessionRouterData { + response: Ok(types::PaymentsResponseData::SessionResponse { + session_token: payment_types::SessionToken::ApplePay(Box::new( + payment_types::ApplepaySessionTokenResponse { + session_token_data: None, + payment_request_data: apple_pay_payment_request, + connector: connector_name, + delayed_session_token: delayed_response, + sdk_next_action: { payment_types::SdkNextAction { next_action } }, + connector_reference_id: None, + connector_sdk_public_key: None, + connector_merchant_id: None, + }, + )), + }), + ..router_data.clone() + }), + } + } } }