mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 13:30:39 +08:00
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:
committed by
GitHub
parent
d6bbdde18c
commit
0d43f48c45
@ -20871,6 +20871,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The next action is to perform eligibility check",
|
||||
"enum": [
|
||||
"eligibility_check"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -23744,7 +23751,8 @@
|
||||
"mandate_payment",
|
||||
"show_surcharge_breakup_screen",
|
||||
"request_external_three_ds_authentication",
|
||||
"is_tax_calculation_enabled"
|
||||
"is_tax_calculation_enabled",
|
||||
"sdk_next_action"
|
||||
],
|
||||
"properties": {
|
||||
"redirect_url": {
|
||||
@ -23800,6 +23808,9 @@
|
||||
"is_tax_calculation_enabled": {
|
||||
"type": "boolean",
|
||||
"description": "flag that indicates whether to calculate tax on the order amount"
|
||||
},
|
||||
"sdk_next_action": {
|
||||
"$ref": "#/components/schemas/SdkNextAction"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -15823,6 +15823,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The next action is to perform eligibility check",
|
||||
"enum": [
|
||||
"eligibility_check"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@ -2044,6 +2044,10 @@ pub struct PaymentMethodListResponse {
|
||||
|
||||
/// flag that indicates whether to calculate tax on the order amount
|
||||
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")]
|
||||
|
||||
@ -8113,6 +8113,8 @@ pub enum NextActionCall {
|
||||
AwaitMerchantCallback,
|
||||
/// The next action is to deny the payment with an error message
|
||||
Deny { message: String },
|
||||
/// The next action is to perform eligibility check
|
||||
EligibilityCheck,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
|
||||
@ -226,4 +226,9 @@ impl MerchantId {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,10 @@ use crate::{
|
||||
core::{
|
||||
configs,
|
||||
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::{
|
||||
helpers,
|
||||
routing::{self, SessionFlowRoutingInput},
|
||||
@ -3475,6 +3478,11 @@ pub async fn list_payment_methods(
|
||||
.as_ref()
|
||||
.and_then(|intent| intent.request_external_three_ds_authentication)
|
||||
.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)) =
|
||||
payment_attempt.as_ref().zip(payment_intent)
|
||||
{
|
||||
@ -3554,6 +3562,7 @@ pub async fn list_payment_methods(
|
||||
collect_shipping_details_from_wallets,
|
||||
collect_billing_details_from_wallets,
|
||||
is_tax_calculation_enabled: is_tax_connector_enabled && !skip_external_tax_calculation,
|
||||
sdk_next_action,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@ -14,9 +14,11 @@ use euclid::frontend::dir;
|
||||
use hyperswitch_constraint_graph as cgraph;
|
||||
use kgraph_utils::{error::KgraphError, transformers::IntoDirValue};
|
||||
use masking::ExposeInterface;
|
||||
#[cfg(feature = "v1")]
|
||||
use router_env::logger;
|
||||
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")]
|
||||
use crate::{
|
||||
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")]
|
||||
pub(super) async fn retrieve_payment_token_data(
|
||||
state: &SessionState,
|
||||
|
||||
Reference in New Issue
Block a user