feat(router): add sdk_next_action in payment method list response (#9922)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sai Harsha Vardhan
2025-10-29 12:35:37 +05:30
committed by GitHub
parent d6bbdde18c
commit 0d43f48c45
7 changed files with 78 additions and 3 deletions

View File

@ -20871,6 +20871,13 @@
} }
} }
} }
},
{
"type": "string",
"description": "The next action is to perform eligibility check",
"enum": [
"eligibility_check"
]
} }
] ]
}, },
@ -23744,7 +23751,8 @@
"mandate_payment", "mandate_payment",
"show_surcharge_breakup_screen", "show_surcharge_breakup_screen",
"request_external_three_ds_authentication", "request_external_three_ds_authentication",
"is_tax_calculation_enabled" "is_tax_calculation_enabled",
"sdk_next_action"
], ],
"properties": { "properties": {
"redirect_url": { "redirect_url": {
@ -23800,6 +23808,9 @@
"is_tax_calculation_enabled": { "is_tax_calculation_enabled": {
"type": "boolean", "type": "boolean",
"description": "flag that indicates whether to calculate tax on the order amount" "description": "flag that indicates whether to calculate tax on the order amount"
},
"sdk_next_action": {
"$ref": "#/components/schemas/SdkNextAction"
} }
} }
}, },

View File

@ -15823,6 +15823,13 @@
} }
} }
} }
},
{
"type": "string",
"description": "The next action is to perform eligibility check",
"enum": [
"eligibility_check"
]
} }
] ]
}, },

View File

@ -2044,6 +2044,10 @@ pub struct PaymentMethodListResponse {
/// flag that indicates whether to calculate tax on the order amount /// flag that indicates whether to calculate tax on the order amount
pub is_tax_calculation_enabled: bool, pub is_tax_calculation_enabled: bool,
/// indicates the next action to be performed by the SDK
#[schema(value_type = SdkNextAction)]
pub sdk_next_action: payments::SdkNextAction,
} }
#[cfg(feature = "v1")] #[cfg(feature = "v1")]

View File

@ -8113,6 +8113,8 @@ pub enum NextActionCall {
AwaitMerchantCallback, AwaitMerchantCallback,
/// The next action is to deny the payment with an error message /// The next action is to deny the payment with an error message
Deny { message: String }, Deny { message: String },
/// The next action is to perform eligibility check
EligibilityCheck,
} }
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)] #[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]

View File

@ -226,4 +226,9 @@ impl MerchantId {
self.get_string_repr() self.get_string_repr()
) )
} }
/// Get should perform eligibility check key for payment
pub fn get_should_perform_eligibility_check_key(&self) -> String {
format!("should_perform_eligibility_{}", self.get_string_repr())
}
} }

View File

@ -79,7 +79,10 @@ use crate::{
core::{ core::{
configs, configs,
errors::{self, StorageErrorExt}, errors::{self, StorageErrorExt},
payment_methods::{network_tokenization, transformers as payment_methods, vault}, payment_methods::{
network_tokenization, transformers as payment_methods, utils as payment_method_utils,
vault,
},
payments::{ payments::{
helpers, helpers,
routing::{self, SessionFlowRoutingInput}, routing::{self, SessionFlowRoutingInput},
@ -3475,6 +3478,11 @@ pub async fn list_payment_methods(
.as_ref() .as_ref()
.and_then(|intent| intent.request_external_three_ds_authentication) .and_then(|intent| intent.request_external_three_ds_authentication)
.unwrap_or(false); .unwrap_or(false);
let sdk_next_action = payment_method_utils::get_sdk_next_action_for_payment_method_list(
db,
merchant_context.get_merchant_account().get_id(),
)
.await;
let merchant_surcharge_configs = if let Some((payment_attempt, payment_intent)) = let merchant_surcharge_configs = if let Some((payment_attempt, payment_intent)) =
payment_attempt.as_ref().zip(payment_intent) payment_attempt.as_ref().zip(payment_intent)
{ {
@ -3554,6 +3562,7 @@ pub async fn list_payment_methods(
collect_shipping_details_from_wallets, collect_shipping_details_from_wallets,
collect_billing_details_from_wallets, collect_billing_details_from_wallets,
is_tax_calculation_enabled: is_tax_connector_enabled && !skip_external_tax_calculation, is_tax_calculation_enabled: is_tax_connector_enabled && !skip_external_tax_calculation,
sdk_next_action,
}, },
)) ))
} }

View File

@ -14,9 +14,11 @@ use euclid::frontend::dir;
use hyperswitch_constraint_graph as cgraph; use hyperswitch_constraint_graph as cgraph;
use kgraph_utils::{error::KgraphError, transformers::IntoDirValue}; use kgraph_utils::{error::KgraphError, transformers::IntoDirValue};
use masking::ExposeInterface; use masking::ExposeInterface;
#[cfg(feature = "v1")]
use router_env::logger;
use storage_impl::redis::cache::{CacheKey, PM_FILTERS_CGRAPH_CACHE}; use storage_impl::redis::cache::{CacheKey, PM_FILTERS_CGRAPH_CACHE};
use crate::{configs::settings, routes::SessionState}; use crate::{configs::settings, db::StorageInterface, routes::SessionState};
#[cfg(feature = "v2")] #[cfg(feature = "v2")]
use crate::{ use crate::{
db::{ db::{
@ -811,6 +813,41 @@ fn compile_accepted_currency_for_mca(
)) ))
} }
pub async fn get_merchant_config_for_eligibility_check(
db: &dyn StorageInterface,
merchant_id: &common_utils::id_type::MerchantId,
) -> bool {
let config = db
.find_config_by_key_unwrap_or(
&merchant_id.get_should_perform_eligibility_check_key(),
Some("false".to_string()),
)
.await;
match config {
Ok(conf) => conf.config == "true",
Err(error) => {
logger::error!(?error);
false
}
}
}
pub async fn get_sdk_next_action_for_payment_method_list(
db: &dyn StorageInterface,
merchant_id: &common_utils::id_type::MerchantId,
) -> api_models::payments::SdkNextAction {
let should_perform_eligibility_check =
get_merchant_config_for_eligibility_check(db, merchant_id).await;
let next_action_call = if should_perform_eligibility_check {
api_models::payments::NextActionCall::EligibilityCheck
} else {
api_models::payments::NextActionCall::Confirm
};
api_models::payments::SdkNextAction {
next_action: next_action_call,
}
}
#[cfg(feature = "v2")] #[cfg(feature = "v2")]
pub(super) async fn retrieve_payment_token_data( pub(super) async fn retrieve_payment_token_data(
state: &SessionState, state: &SessionState,