Skip to content

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

refactor(router): changed payment method token TTL to api contract based config from const value (#5115)

Sahkal Poddar3bbdfb5a1c76
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index d2bfebcc42..cc4229979f 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -6902,7 +6902,7 @@
"intent_fulfillment_time": {
"type": "integer",
"format": "int32",
- "description": "Will be used to expire client secret after certain amount of time to be supplied in seconds\n(900) for 15 mins",
+ "description": "Will be used to determine the time till which your payment will be active once the payment session starts",
"example": 900,
"nullable": true,
"minimum": 0
@@ -7059,7 +7059,7 @@
"intent_fulfillment_time": {
"type": "integer",
"format": "int64",
- "description": "Will be used to expire client secret after certain amount of time to be supplied in seconds\n(900) for 15 mins",
+ "description": "Will be used to determine the time till which your payment will be active once the payment session starts",
"example": 900,
"nullable": true
},
@@ -11339,12 +11339,6 @@
],
"nullable": true
},
- "intent_fulfillment_time": {
- "type": "integer",
- "format": "int64",
- "description": "Will be used to expire client secret after certain amount of time to be supplied in seconds\n(900) for 15 mins",
- "nullable": true
- },
"organization_id": {
"type": "string",
"description": "The organization id merchant is associated with"
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index 58e11c4d0d..cb268262fb 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -268,10 +268,6 @@ pub struct MerchantAccountResponse {
#[schema(value_type = Option<RoutingAlgorithm>, max_length = 255, example = r#"{"type": "single", "data": "stripe" }"#)]
pub frm_routing_algorithm: Option<serde_json::Value>,
- ///Will be used to expire client secret after certain amount of time to be supplied in seconds
- ///(900) for 15 mins
- pub intent_fulfillment_time: Option<i64>,
-
/// The organization id merchant is associated with
pub organization_id: String,
@@ -920,8 +916,7 @@ pub struct BusinessProfileCreate {
#[schema(value_type = Option<Object>,example = json!({"type": "single", "data": "stripe"}))]
pub routing_algorithm: Option<serde_json::Value>,
- ///Will be used to expire client secret after certain amount of time to be supplied in seconds
- ///(900) for 15 mins
+ /// Will be used to determine the time till which your payment will be active once the payment session starts
#[schema(example = 900)]
pub intent_fulfillment_time: Option<u32>,
@@ -1010,8 +1005,7 @@ pub struct BusinessProfileResponse {
#[schema(value_type = Option<Object>,example = json!({"type": "single", "data": "stripe"}))]
pub routing_algorithm: Option<serde_json::Value>,
- ///Will be used to expire client secret after certain amount of time to be supplied in seconds
- ///(900) for 15 mins
+ /// Will be used to determine the time till which your payment will be active once the payment session starts
#[schema(example = 900)]
pub intent_fulfillment_time: Option<i64>,
@@ -1095,8 +1089,7 @@ pub struct BusinessProfileUpdate {
#[schema(value_type = Option<Object>,example = json!({"type": "single", "data": "stripe"}))]
pub routing_algorithm: Option<serde_json::Value>,
- ///Will be used to expire client secret after certain amount of time to be supplied in seconds
- ///(900) for 15 mins
+ /// Will be used to determine the time till which your payment will be active once the payment session starts
#[schema(example = 900)]
pub intent_fulfillment_time: Option<u32>,
diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rs
index 38c8997358..efb60149c0 100644
--- a/crates/common_utils/src/consts.rs
+++ b/crates/common_utils/src/consts.rs
@@ -72,6 +72,9 @@ pub const DEFAULT_SDK_LAYOUT: &str = "tabs";
/// Payment intent default client secret expiry (in seconds)
pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;
+/// Payment intent fulfillment time (in seconds)
+pub const DEFAULT_INTENT_FULFILLMENT_TIME: i64 = 15 * 60;
+
/// Default bool for Display sdk only
pub const DEFAULT_DISPLAY_SDK_ONLY: bool = false;
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index bffc524133..d3091875f4 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -102,6 +102,12 @@ pub const MAX_SESSION_EXPIRY: u32 = 7890000;
/// Min payment session expiry
pub const MIN_SESSION_EXPIRY: u32 = 60;
+/// Max payment intent fulfillment expiry
+pub const MAX_INTENT_FULFILLMENT_EXPIRY: u32 = 1800;
+
+/// Min payment intent fulfillment expiry
+pub const MIN_INTENT_FULFILLMENT_EXPIRY: u32 = 60;
+
pub const LOCKER_HEALTH_CALL_PATH: &str = "/health";
pub const AUTHENTICATION_ID_PREFIX: &str = "authn";
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index b86fed02f3..dabe115529 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -1520,6 +1520,11 @@ pub async fn create_business_profile(
if let Some(session_expiry) = &request.session_expiry {
helpers::validate_session_expiry(session_expiry.to_owned())?;
}
+
+ if let Some(intent_fulfillment_expiry) = &request.intent_fulfillment_time {
+ helpers::validate_intent_fulfillment_expiry(intent_fulfillment_expiry.to_owned())?;
+ }
+
let db = state.store.as_ref();
let key_store = db
.get_merchant_key_store_by_merchant_id(merchant_id, &db.get_master_key().to_vec().into())
@@ -1637,6 +1642,10 @@ pub async fn update_business_profile(
helpers::validate_session_expiry(session_expiry.to_owned())?;
}
+ if let Some(intent_fulfillment_expiry) = &request.intent_fulfillment_time {
+ helpers::validate_intent_fulfillment_expiry(intent_fulfillment_expiry.to_owned())?;
+ }
+
let webhook_details = request
.webhook_details
.as_ref()
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index faa28ffdbc..23bbc944f6 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -42,6 +42,7 @@ pub async fn retrieve_payment_method(
payment_intent: &PaymentIntent,
payment_attempt: &PaymentAttempt,
merchant_key_store: &domain::MerchantKeyStore,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(Option<payments::PaymentMethodData>, Option<String>)> {
match pm_data {
pm_opt @ Some(pm @ api::PaymentMethodData::Card(_)) => {
@@ -52,6 +53,7 @@ pub async fn retrieve_payment_method(
enums::PaymentMethod::Card,
pm,
merchant_key_store,
+ business_profile,
)
.await?;
@@ -74,6 +76,7 @@ pub async fn retrieve_payment_method(
enums::PaymentMethod::BankTransfer,
pm,
merchant_key_store,
+ business_profile,
)
.await?;
@@ -87,6 +90,7 @@ pub async fn retrieve_payment_method(
enums::PaymentMethod::Wallet,
pm,
merchant_key_store,
+ business_profile,
)
.await?;
@@ -100,6 +104,7 @@ pub async fn retrieve_payment_method(
enums::PaymentMethod::BankRedirect,
pm,
merchant_key_store,
+ business_profile,
)
.await?;
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 5fb923704c..8a3d896233 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -3511,6 +3511,31 @@ pub async fn list_customer_payment_method(
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
//let mca = query::find_mca_by_merchant_id(conn, &merchant_account.merchant_id)?;
let mut customer_pms = Vec::new();
+
+ let profile_id = payment_intent
+ .as_ref()
+ .async_map(|payment_intent| async {
+ core_utils::get_profile_id_from_business_details(
+ payment_intent.business_country,
+ payment_intent.business_label.as_ref(),
+ &merchant_account,
+ payment_intent.profile_id.as_ref(),
+ db,
+ false,
+ )
+ .await
+ .attach_printable("Could not find profile id from business details")
+ })
+ .await
+ .transpose()?;
+
+ let business_profile = core_utils::validate_and_get_business_profile(
+ db,
+ profile_id.as_ref(),
+ &merchant_account.merchant_id,
+ )
+ .await?;
+
for pm in resp.into_iter() {
let parent_payment_method_token = generate_id(consts::ID_LENGTH, "token");
@@ -3659,19 +3684,23 @@ pub async fn list_customer_payment_method(
};
customer_pms.push(pma.to_owned());
- let intent_created = payment_intent.as_ref().map(|intent| intent.created_at);
-
let redis_conn = state
.store
.get_redis_conn()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to get redis connection")?;
+
+ let intent_fulfillment_time = business_profile
+ .as_ref()
+ .and_then(|b_profile| b_profile.intent_fulfillment_time)
+ .unwrap_or(consts::DEFAULT_INTENT_FULFILLMENT_TIME);
+
ParentPaymentMethodToken::create_key_for_token((
&parent_payment_method_token,
pma.payment_method,
))
.insert(
- intent_created,
+ intent_fulfillment_time,
payment_method_retrieval_context.hyperswitch_token_data,
state,
)
@@ -3690,18 +3719,9 @@ pub async fn list_customer_payment_method(
"pm_token_{}_{}_{}",
parent_payment_method_token, pma.payment_method, pm_metadata.0
);
- let current_datetime_utc = common_utils::date_time::now();
- let time_elapsed = current_datetime_utc
- - payment_intent
- .as_ref()
- .map(|intent| intent.created_at)
- .unwrap_or_else(|| current_datetime_utc);
+
redis_conn
- .set_key_with_expiry(
- &key,
- pm_metadata.1,
- consts::TOKEN_TTL - time_elapsed.whole_seconds(),
- )
+ .set_key_with_expiry(&key, pm_metadata.1, intent_fulfillment_time)
.await
.change_context(errors::StorageError::KVError)
.change_context(errors::ApiErrorResponse::InternalServerError)
@@ -3731,29 +3751,6 @@ pub async fn list_customer_payment_method(
.await
.transpose()?;
- let profile_id = payment_intent
- .as_ref()
- .async_map(|payment_intent| async {
- crate::core::utils::get_profile_id_from_business_details(
- payment_intent.business_country,
- payment_intent.business_label.as_ref(),
- &merchant_account,
- payment_intent.profile_id.as_ref(),
- db,
- false,
- )
- .await
- .attach_printable("Could not find profile id from business details")
- })
- .await
- .transpose()?;
- let business_profile = core_utils::validate_and_get_business_profile(
- db,
- profile_id.as_ref(),
- &merchant_account.merchant_id,
- )
- .await?;
-
if let Some((payment_attempt, payment_intent, business_profile)) = payment_attempt
.zip(payment_intent)
.zip(business_profile)
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 69c55b152e..f65cc052ea 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -197,6 +197,7 @@ where
&validate_result,
&key_store,
&customer,
+ Some(&business_profile),
)
.await?;
@@ -1440,6 +1441,7 @@ where
&merchant_connector_account,
key_store,
customer,
+ Some(business_profile),
)
.await?;
*payment_data = pd;
@@ -2306,6 +2308,7 @@ pub async fn get_connector_tokenization_action_when_confirm_true<F, Req>(
merchant_connector_account: &helpers::MerchantConnectorAccountType,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(PaymentData<F>, TokenizationAction)>
where
F: Send + Clone,
@@ -2372,6 +2375,7 @@ where
validate_result.storage_scheme,
merchant_key_store,
customer,
+ business_profile,
)
.await?;
payment_data.payment_method_data = payment_method_data;
@@ -2390,6 +2394,7 @@ where
validate_result.storage_scheme,
merchant_key_store,
customer,
+ business_profile,
)
.await?;
@@ -2431,6 +2436,7 @@ pub async fn tokenize_in_router_when_confirm_false_or_external_authentication<F,
validate_result: &operations::ValidateResult<'_>,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<PaymentData<F>>
where
F: Send + Clone,
@@ -2449,6 +2455,7 @@ where
validate_result.storage_scheme,
merchant_key_store,
customer,
+ business_profile,
)
.await?;
payment_data.payment_method_data = payment_method_data;
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index a16f5ca44f..58f061115a 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -2050,6 +2050,7 @@ pub async fn make_pm_data<'a, F: Clone, R>(
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
storage_scheme: common_enums::enums::MerchantStorageScheme,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, R>,
Option<api::PaymentMethodData>,
@@ -2128,6 +2129,7 @@ pub async fn make_pm_data<'a, F: Clone, R>(
&payment_data.payment_intent,
&payment_data.payment_attempt,
merchant_key_store,
+ business_profile,
)
.await?;
@@ -2148,6 +2150,7 @@ pub async fn store_in_vault_and_generate_ppmt(
payment_attempt: &PaymentAttempt,
payment_method: enums::PaymentMethod,
merchant_key_store: &domain::MerchantKeyStore,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<String> {
let router_token = vault::Vault::store_payment_method_data_in_locker(
state,
@@ -2165,10 +2168,15 @@ pub async fn store_in_vault_and_generate_ppmt(
payment_method,
))
});
+
+ let intent_fulfillment_time = business_profile
+ .and_then(|b_profile| b_profile.intent_fulfillment_time)
+ .unwrap_or(consts::DEFAULT_FULFILLMENT_TIME);
+
if let Some(key_for_hyperswitch_token) = key_for_hyperswitch_token {
key_for_hyperswitch_token
.insert(
- Some(payment_intent.created_at),
+ intent_fulfillment_time,
storage::PaymentTokenData::temporary_generic(router_token),
state,
)
@@ -2184,6 +2192,7 @@ pub async fn store_payment_method_data_in_vault(
payment_method: enums::PaymentMethod,
payment_method_data: &api::PaymentMethodData,
merchant_key_store: &domain::MerchantKeyStore,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<Option<String>> {
if should_store_payment_method_data_in_vault(
&state.conf.temp_locker_enable_config,
@@ -2198,6 +2207,7 @@ pub async fn store_payment_method_data_in_vault(
payment_attempt,
payment_method,
merchant_key_store,
+ business_profile,
)
.await?;
@@ -4611,6 +4621,22 @@ pub fn validate_session_expiry(session_expiry: u32) -> Result<(), errors::ApiErr
}
}
+// This function validates the intent fulfillment time expiry set by the merchant in the request
+pub fn validate_intent_fulfillment_expiry(
+ intent_fulfillment_time: u32,
+) -> Result<(), errors::ApiErrorResponse> {
+ if !(consts::MIN_INTENT_FULFILLMENT_EXPIRY..=consts::MAX_INTENT_FULFILLMENT_EXPIRY)
+ .contains(&intent_fulfillment_time)
+ {
+ Err(errors::ApiErrorResponse::InvalidRequestData {
+ message: "intent_fulfillment_time should be between 60(1 min) to 1800(30 mins)."
+ .to_string(),
+ })
+ } else {
+ Ok(())
+ }
+}
+
pub fn add_connector_response_to_additional_payment_data(
additional_payment_data: api_models::payments::AdditionalPaymentData,
connector_response_payment_method_data: AdditionalPaymentMethodConnectorResponse,
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index b7eaf5fc0e..f5bc401465 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -132,6 +132,7 @@ pub trait Domain<F: Clone, R>: Send + Sync {
storage_scheme: enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, R>,
Option<api::PaymentMethodData>,
@@ -303,6 +304,7 @@ where
storage_scheme: enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsRetrieveRequest>,
Option<api::PaymentMethodData>,
@@ -315,6 +317,7 @@ where
merchant_key_store,
customer,
storage_scheme,
+ business_profile,
)
.await
}
@@ -373,6 +376,7 @@ where
_storage_scheme: enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
_customer: &Option<domain::Customer>,
+ _business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsCaptureRequest>,
Option<api::PaymentMethodData>,
@@ -447,6 +451,7 @@ where
_storage_scheme: enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
_customer: &Option<domain::Customer>,
+ _business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsCancelRequest>,
Option<api::PaymentMethodData>,
@@ -510,6 +515,7 @@ where
_storage_scheme: enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
_customer: &Option<domain::Customer>,
+ _business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsRejectRequest>,
Option<api::PaymentMethodData>,
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index b2e8696730..4fd427e38f 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -377,6 +377,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for CompleteAuthorize {
storage_scheme: storage_enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsRequest>,
Option<api::PaymentMethodData>,
@@ -389,6 +390,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for CompleteAuthorize {
merchant_key_store,
customer,
storage_scheme,
+ business_profile,
)
.await?;
Ok((op, payment_method_data, pm_id))
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 9c1e753776..5e35b918a0 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -695,6 +695,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
storage_scheme: storage_enums::MerchantStorageScheme,
key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsRequest>,
Option<api::PaymentMethodData>,
@@ -707,6 +708,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentConfirm {
key_store,
customer,
storage_scheme,
+ business_profile,
)
.await?;
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 718d12f1c0..b8045487d9 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -505,6 +505,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentCreate {
storage_scheme: enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsRequest>,
Option<api::PaymentMethodData>,
@@ -517,6 +518,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentCreate {
merchant_key_store,
customer,
storage_scheme,
+ business_profile,
)
.await
}
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index cd63d3aedb..503a5c5f2b 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -327,6 +327,7 @@ where
_storage_scheme: storage_enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
_customer: &Option<domain::Customer>,
+ _business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'b, F, api::PaymentsSessionRequest>,
Option<api::PaymentMethodData>,
diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs
index 865da4fb79..c4096c6ea5 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -300,6 +300,7 @@ where
storage_scheme: storage_enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsStartRequest>,
Option<api::PaymentMethodData>,
@@ -319,6 +320,7 @@ where
merchant_key_store,
customer,
storage_scheme,
+ business_profile,
)
.await
} else {
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index afe571275b..5d4a5037b7 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -90,6 +90,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
storage_scheme: enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsRequest>,
Option<api::PaymentMethodData>,
@@ -102,6 +103,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
merchant_key_store,
customer,
storage_scheme,
+ business_profile,
)
.await
}
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 8095660d4f..c34a40fd90 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -514,6 +514,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentUpdate {
storage_scheme: storage_enums::MerchantStorageScheme,
merchant_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
+ business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, api::PaymentsRequest>,
Option<api::PaymentMethodData>,
@@ -526,6 +527,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentUpdate {
merchant_key_store,
customer,
storage_scheme,
+ business_profile,
)
.await
}
diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
index 249306693a..61a629df62 100644
--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
@@ -318,6 +318,7 @@ impl<F: Clone + Send> Domain<F, PaymentsIncrementalAuthorizationRequest>
_storage_scheme: enums::MerchantStorageScheme,
_merchant_key_store: &domain::MerchantKeyStore,
_customer: &Option<domain::Customer>,
+ _business_profile: Option<&diesel_models::business_profile::BusinessProfile>,
) -> RouterResult<(
BoxedOperation<'a, F, PaymentsIncrementalAuthorizationRequest>,
Option<api::PaymentMethodData>,
diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs
index c83b9483c4..bc74857215 100644
--- a/crates/router/src/routes/payment_methods.rs
+++ b/crates/router/src/routes/payment_methods.rs
@@ -1,9 +1,8 @@
use actix_web::{web, HttpRequest, HttpResponse};
-use common_utils::{consts::TOKEN_TTL, errors::CustomResult, id_type};
+use common_utils::{errors::CustomResult, id_type};
use diesel_models::enums::IntentStatus;
use error_stack::ResultExt;
use router_env::{instrument, logger, tracing, Flow};
-use time::PrimitiveDateTime;
use super::app::{AppState, SessionState};
use crate::{
@@ -484,7 +483,7 @@ impl ParentPaymentMethodToken {
}
pub async fn insert(
&self,
- intent_created_at: Option<PrimitiveDateTime>,
+ fulfillment_time: i64,
token: PaymentTokenData,
state: &SessionState,
) -> CustomResult<(), errors::ApiErrorResponse> {
@@ -497,14 +496,8 @@ impl ParentPaymentMethodToken {
.get_redis_conn()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to get redis connection")?;
- let current_datetime_utc = common_utils::date_time::now();
- let time_elapsed = current_datetime_utc - intent_created_at.unwrap_or(current_datetime_utc);
redis_conn
- .set_key_with_expiry(
- &self.key_for_token,
- token_json_str,
- TOKEN_TTL - time_elapsed.whole_seconds(),
- )
+ .set_key_with_expiry(&self.key_for_token, token_json_str, fulfillment_time)
.await
.change_context(errors::StorageError::KVError)
.change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs
index 36c3ba9621..cb801b934e 100644
--- a/crates/router/src/types/api/admin.rs
+++ b/crates/router/src/types/api/admin.rs
@@ -44,7 +44,6 @@ impl TryFrom<domain::MerchantAccount> for MerchantAccountResponse {
locker_id: item.locker_id,
primary_business_details,
frm_routing_algorithm: item.frm_routing_algorithm,
- intent_fulfillment_time: item.intent_fulfillment_time,
#[cfg(feature = "payouts")]
payout_routing_algorithm: item.payout_routing_algorithm,
organization_id: item.organization_id,
@@ -173,7 +172,8 @@ impl ForeignTryFrom<(domain::MerchantAccount, BusinessProfileCreate)>
intent_fulfillment_time: request
.intent_fulfillment_time
.map(i64::from)
- .or(merchant_account.intent_fulfillment_time),
+ .or(merchant_account.intent_fulfillment_time)
+ .or(Some(common_utils::consts::DEFAULT_INTENT_FULFILLMENT_TIME)),
frm_routing_algorithm: request
.frm_routing_algorithm
.or(merchant_account.frm_routing_algorithm),