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

feat(payment_link): make status page redirect delay configurable (#14128)

Aniket Burman3be07567ea9a
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index b42993c5c5..c684a51400 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -31639,6 +31639,13 @@
"type": "string",
"description": "Custom text for the separator shown between wallet and card payment method sections",
"nullable": true
+ },
+ "redirect_delay_seconds": {
+ "type": "integer",
+ "format": "int32",
+ "description": "Duration in seconds before the status page auto-redirects to the return URL.\nSet to 0 to disable auto-redirect. Maximum value is 900 seconds. Defaults to 5 seconds.",
+ "nullable": true,
+ "minimum": 0
}
}
},
@@ -31834,6 +31841,15 @@
"example": "Or pay with",
"nullable": true,
"maxLength": 64
+ },
+ "redirect_delay_seconds": {
+ "type": "integer",
+ "format": "int32",
+ "description": "Duration in seconds before the status page auto-redirects to the return URL.\nSet to 0 to disable auto-redirect. Maximum value is 900 seconds. Defaults to 5 seconds.",
+ "example": 10,
+ "nullable": true,
+ "maximum": 900,
+ "minimum": 0
}
}
},
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 904f2dee0d..b0ef8efefc 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -22902,6 +22902,13 @@
"type": "string",
"description": "Custom text for the separator shown between wallet and card payment method sections",
"nullable": true
+ },
+ "redirect_delay_seconds": {
+ "type": "integer",
+ "format": "int32",
+ "description": "Duration in seconds before the status page auto-redirects to the return URL.\nSet to 0 to disable auto-redirect. Maximum value is 900 seconds. Defaults to 5 seconds.",
+ "nullable": true,
+ "minimum": 0
}
}
},
@@ -23097,6 +23104,15 @@
"example": "Or pay with",
"nullable": true,
"maxLength": 64
+ },
+ "redirect_delay_seconds": {
+ "type": "integer",
+ "format": "int32",
+ "description": "Duration in seconds before the status page auto-redirects to the return URL.\nSet to 0 to disable auto-redirect. Maximum value is 900 seconds. Defaults to 5 seconds.",
+ "example": 10,
+ "nullable": true,
+ "maximum": 900,
+ "minimum": 0
}
}
},
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index 95706fd86a..4f0f61cbea 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -3699,6 +3699,10 @@ pub struct PaymentLinkConfigRequest {
/// Custom text for the separator shown between wallet and card payment method sections
#[schema(value_type = Option<String>, max_length = 64, example = "Or pay with")]
pub payment_methods_separator_text: Option<String>,
+ /// Duration in seconds before the status page auto-redirects to the return URL.
+ /// Set to 0 to disable auto-redirect. Maximum value is 900 seconds. Defaults to 5 seconds.
+ #[schema(value_type = Option<u32>, example = 10, minimum = 0, maximum = 900)]
+ pub redirect_delay_seconds: Option<u32>,
}
impl PaymentLinkConfigRequest {
@@ -3708,7 +3712,16 @@ impl PaymentLinkConfigRequest {
if let Some(custom_message) = self.custom_message_for_payment_method_types.as_ref() {
custom_message.validate().map_err(|e| e.to_string())?;
}
- Ok(())
+
+ self.redirect_delay_seconds
+ .filter(|&delay| delay > consts::MAX_PAYMENT_LINK_REDIRECT_DELAY_SECONDS)
+ .map(|_| {
+ Err(format!(
+ "redirect_delay_seconds must not exceed {} seconds",
+ consts::MAX_PAYMENT_LINK_REDIRECT_DELAY_SECONDS
+ ))
+ })
+ .unwrap_or(Ok(()))
}
}
@@ -3834,6 +3847,9 @@ pub struct PaymentLinkConfig {
pub show_merchant_name: Option<bool>,
/// Custom text for the separator shown between wallet and card payment method sections
pub payment_methods_separator_text: Option<String>,
+ /// Duration in seconds before the status page auto-redirects to the return URL.
+ /// Set to 0 to disable auto-redirect. Maximum value is 900 seconds. Defaults to 5 seconds.
+ pub redirect_delay_seconds: Option<u32>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
@@ -3947,6 +3963,7 @@ mod tests {
color_icon_card_cvc_error: None,
show_merchant_name: None,
payment_methods_separator_text: None,
+ redirect_delay_seconds: None,
};
assert!(safe_request.validate().is_ok());
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index cabbea188a..32f0c7c7ef 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -13248,6 +13248,7 @@ pub struct PaymentLinkStatusDetails {
pub unified_message: Option<String>,
pub capture_method: Option<common_enums::CaptureMethod>,
pub setup_future_usage_applied: Option<common_enums::FutureUsage>,
+ pub redirect_delay_seconds: Option<u32>,
}
#[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)]
diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rs
index ae44408f37..56b76b6b7e 100644
--- a/crates/common_utils/src/consts.rs
+++ b/crates/common_utils/src/consts.rs
@@ -84,6 +84,9 @@ pub const PROPHETPAY_TOKEN: &str = "cctoken";
/// Payment intent default client secret expiry (in seconds)
pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;
+/// Maximum allowed redirect delay in seconds for payment link status page
+pub const MAX_PAYMENT_LINK_REDIRECT_DELAY_SECONDS: u32 = 900;
+
/// Payment intent fulfillment time (in seconds)
pub const DEFAULT_INTENT_FULFILLMENT_TIME: i64 = 15 * 60;
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index dddeeecbf7..c41b7faff4 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -657,6 +657,7 @@ pub struct PaymentLinkConfigRequest {
pub color_icon_card_cvc_error: Option<String>,
pub show_merchant_name: Option<bool>,
pub payment_methods_separator_text: Option<String>,
+ pub redirect_delay_seconds: Option<u32>,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs
index 6f067513f2..c453cbdc80 100644
--- a/crates/diesel_models/src/payment_intent.rs
+++ b/crates/diesel_models/src/payment_intent.rs
@@ -282,6 +282,8 @@ pub struct PaymentLinkConfigRequestForPayments {
pub show_merchant_name: Option<bool>,
/// Custom text for the separator shown between wallet and card payment method sections
pub payment_methods_separator_text: Option<String>,
+ /// Duration in seconds before the status page auto-redirects. Set to 0 to disable auto-redirect. Maximum 900 seconds.
+ pub redirect_delay_seconds: Option<u32>,
}
common_utils::impl_to_sql_from_sql_json!(PaymentLinkConfigRequestForPayments);
diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rs
index 9aa3f54abf..a9fdb72e0d 100644
--- a/crates/hyperswitch_domain_models/src/lib.rs
+++ b/crates/hyperswitch_domain_models/src/lib.rs
@@ -1156,6 +1156,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
color_icon_card_cvc_error: item.color_icon_card_cvc_error,
show_merchant_name: item.show_merchant_name,
payment_methods_separator_text: item.payment_methods_separator_text,
+ redirect_delay_seconds: item.redirect_delay_seconds,
}
}
fn convert_back(self) -> api_models::admin::PaymentLinkConfigRequest {
@@ -1188,6 +1189,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
color_icon_card_cvc_error,
show_merchant_name,
payment_methods_separator_text,
+ redirect_delay_seconds,
} = self;
api_models::admin::PaymentLinkConfigRequest {
theme,
@@ -1224,6 +1226,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
color_icon_card_cvc_error,
show_merchant_name,
payment_methods_separator_text,
+ redirect_delay_seconds,
}
}
}
diff --git a/crates/payment_link/src/wasm.rs b/crates/payment_link/src/wasm.rs
index fa419c1397..11c2d189a5 100644
--- a/crates/payment_link/src/wasm.rs
+++ b/crates/payment_link/src/wasm.rs
@@ -52,6 +52,7 @@ pub fn generate_payment_link_preview_impl(config_json: &str) -> Result<String, S
.clone(),
show_merchant_name: payment_link_details.show_merchant_name,
payment_methods_separator_text: payment_link_details.payment_methods_separator_text.clone(),
+ redirect_delay_seconds: None,
};
if let Ok(config_from_json) = serde_json::from_str::<PaymentLinkConfig>(config_json) {
diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs
index 7db306457b..96dc338533 100644
--- a/crates/router/src/core/payment_link.rs
+++ b/crates/router/src/core/payment_link.rs
@@ -156,6 +156,7 @@ pub async fn form_payment_link_data(
color_icon_card_cvc_error: None,
show_merchant_name: Some(DEFAULT_SHOW_MERCHANT_NAME),
payment_methods_separator_text: None,
+ redirect_delay_seconds: None,
}
};
@@ -286,6 +287,7 @@ pub async fn form_payment_link_data(
unified_message: payment_attempt.unified_message,
capture_method: payment_attempt.capture_method,
setup_future_usage_applied: payment_attempt.setup_future_usage_applied,
+ redirect_delay_seconds: payment_link_config.redirect_delay_seconds,
};
return Ok((
@@ -766,6 +768,7 @@ pub fn get_payment_link_config_based_on_priority(
color_icon_card_cvc_error,
show_merchant_name,
payment_methods_separator_text,
+ redirect_delay_seconds,
) = get_payment_link_config_value!(
payment_create_link_config,
business_theme_configs,
@@ -788,6 +791,7 @@ pub fn get_payment_link_config_based_on_priority(
(color_icon_card_cvc_error),
(show_merchant_name),
(payment_methods_separator_text),
+ (redirect_delay_seconds),
);
let payment_link_config =
@@ -824,6 +828,7 @@ pub fn get_payment_link_config_based_on_priority(
color_icon_card_cvc_error,
show_merchant_name,
payment_methods_separator_text,
+ redirect_delay_seconds,
};
common_utils::validation::ValidateXSSOrSQLi::validate_xss_or_sqli(&payment_link_config)
@@ -949,6 +954,7 @@ pub async fn get_payment_link_status(
color_icon_card_cvc_error: None,
show_merchant_name: Some(DEFAULT_SHOW_MERCHANT_NAME),
payment_methods_separator_text: None,
+ redirect_delay_seconds: None,
}
};
@@ -1033,6 +1039,7 @@ pub async fn get_payment_link_status(
unified_message: unified_translated_message,
capture_method: payment_attempt.capture_method,
setup_future_usage_applied: payment_attempt.setup_future_usage_applied,
+ redirect_delay_seconds: payment_link_config.redirect_delay_seconds,
};
let js_script = get_js_script(&PaymentLinkData::PaymentLinkStatusDetails(Box::new(
payment_details,
diff --git a/crates/router/src/core/payment_link/payment_link_status/status.js b/crates/router/src/core/payment_link/payment_link_status/status.js
index 863c423975..e1737f5596 100644
--- a/crates/router/src/core/payment_link/payment_link_status/status.js
+++ b/crates/router/src/core/payment_link/payment_link_status/status.js
@@ -332,38 +332,47 @@ function renderStatusDetails(paymentDetails) {
statusRedirectTextNode instanceof HTMLDivElement &&
typeof paymentDetails.return_url === "string"
) {
- var timeout = 5,
+ var timeout =
+ paymentDetails.redirect_delay_seconds !== undefined &&
+ paymentDetails.redirect_delay_seconds !== null
+ ? paymentDetails.redirect_delay_seconds
+ : 5,
j = 0;
- for (var i = 0; i <= timeout; i++) {
- setTimeout(function () {
- var secondsLeft = timeout - j++;
- var innerText =
- secondsLeft === 0
- ? translations.redirecting
- : translations.redirectingIn + secondsLeft + " " + translations.seconds;
- // @ts-ignore
- statusRedirectTextNode.innerText = innerText;
- if (secondsLeft === 0) {
- // Form query params
- var queryParams = {
- payment_id: paymentDetails.payment_id,
- status: paymentDetails.status,
- };
- var url = new URL(paymentDetails.return_url);
- var params = new URLSearchParams(url.search);
- // Attach query params to return_url
- for (var key in queryParams) {
- if (queryParams.hasOwnProperty(key)) {
- params.set(key, queryParams[key]);
+ if (timeout === 0) {
+ // Auto-redirect disabled by merchant config
+ statusRedirectTextNode.innerText = "";
+ } else {
+ for (var i = 0; i <= timeout; i++) {
+ setTimeout(function () {
+ var secondsLeft = timeout - j++;
+ var innerText =
+ secondsLeft === 0
+ ? translations.redirecting
+ : translations.redirectingIn + secondsLeft + " " + translations.seconds;
+ // @ts-ignore
+ statusRedirectTextNode.innerText = innerText;
+ if (secondsLeft === 0) {
+ // Form query params
+ var queryParams = {
+ payment_id: paymentDetails.payment_id,
+ status: paymentDetails.status,
+ };
+ var url = new URL(paymentDetails.return_url);
+ var params = new URLSearchParams(url.search);
+ // Attach query params to return_url
+ for (var key in queryParams) {
+ if (queryParams.hasOwnProperty(key)) {
+ params.set(key, queryParams[key]);
+ }
}
+ url.search = params.toString();
+ setTimeout(function () {
+ // Finally redirect
+ window.top.location.href = url.toString();
+ }, 1000);
}
- url.search = params.toString();
- setTimeout(function () {
- // Finally redirect
- window.top.location.href = url.toString();
- }, 1000);
- }
- }, i * 1000);
+ }, i * 1000);
+ }
}
}
}
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index e98b812d8a..b9531721c9 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -8205,7 +8205,30 @@ pub fn validate_payment_link_request(
message: "return_url must be sent while creating a payment link".to_string(),
});
}
- Ok(())
+
+ #[cfg(feature = "v1")]
+ let redirect_delay = request
+ .payment_link_config
+ .as_ref()
+ .and_then(|config| config.theme_config.redirect_delay_seconds);
+
+ #[cfg(feature = "v2")]
+ let redirect_delay = request
+ .payment_link_config
+ .as_ref()
+ .and_then(|config| config.redirect_delay_seconds);
+
+ redirect_delay
+ .filter(|&delay| delay > common_utils::consts::MAX_PAYMENT_LINK_REDIRECT_DELAY_SECONDS)
+ .map(|_| {
+ Err(errors::ApiErrorResponse::InvalidRequestData {
+ message: format!(
+ "redirect_delay_seconds must not exceed {} seconds",
+ common_utils::consts::MAX_PAYMENT_LINK_REDIRECT_DELAY_SECONDS
+ ),
+ })
+ })
+ .unwrap_or(Ok(()))
}
/// Creates a lookup key for issuer error codes with network and code
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 130391cd7a..2f6d25f672 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -7967,6 +7967,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
color_icon_card_cvc_error: config.color_icon_card_cvc_error,
show_merchant_name: config.show_merchant_name,
payment_methods_separator_text: config.payment_methods_separator_text,
+ redirect_delay_seconds: config.redirect_delay_seconds,
}
}
}
@@ -8046,6 +8047,7 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
color_icon_card_cvc_error: config.color_icon_card_cvc_error,
show_merchant_name: config.show_merchant_name,
payment_methods_separator_text: config.payment_methods_separator_text,
+ redirect_delay_seconds: config.redirect_delay_seconds,
}
}
}
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 86606b9578..4f7bac824c 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -2664,6 +2664,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
color_icon_card_cvc_error: item.color_icon_card_cvc_error,
show_merchant_name: item.show_merchant_name,
payment_methods_separator_text: item.payment_methods_separator_text,
+ redirect_delay_seconds: item.redirect_delay_seconds,
}
}
}
@@ -2703,6 +2704,7 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
color_icon_card_cvc_error: item.color_icon_card_cvc_error,
show_merchant_name: item.show_merchant_name,
payment_methods_separator_text: item.payment_methods_separator_text,
+ redirect_delay_seconds: item.redirect_delay_seconds,
}
}
}