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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(payment_link): derive redirection log endpoint from router base_url (#13401)
Sayak Bhattacharyab40c9369a521
diff --git a/crates/payment_link/src/consts.rs b/crates/payment_link/src/consts.rsindex 14a482b173..faa566c65f 100644--- a/crates/payment_link/src/consts.rs+++ b/crates/payment_link/src/consts.rs@@ -1,3 +1,8 @@+// Payment link constants+/// Default merchant logo link for payment links.pub const DEFAULT_MERCHANT_LOGO: &str ="https://live.hyperswitch.io/payment-link-assets/Merchant_placeholder.png";++/// Relative path for the redirection log endpoint.+pub const REDIRECTION_LOG_ENDPOINT: &str = "logs/redirection";diff --git a/crates/payment_link/src/template_renderer.rs b/crates/payment_link/src/template_renderer.rsindex 51d54de58d..671cb14b11 100644--- a/crates/payment_link/src/template_renderer.rs+++ b/crates/payment_link/src/template_renderer.rs@@ -120,6 +120,14 @@ fn build_payment_link_template(context.insert("rendered_css", &rendered_css);context.insert("rendered_js", &rendered_js);context.insert("logging_template", &logging_template);+ context.insert(+ "redirection_log_endpoint",+ payment_link_data+ .redirection_log_endpoint+ .as_ref()+ .map(|endpoint| endpoint.as_str())+ .unwrap_or(""),+ );Ok((tera, context))}@@ -171,6 +179,20 @@ pub fn get_payment_link_status(.render("payment_link_js", &context).change_context(PaymentLinkError::TemplateRenderError)?;+ // Make the backend-computed redirection log endpoint available to the+ // status.html template. The status page is rendered separately from the+ // payment initiate page, so it needs its own copy of the endpoint to keep+ // logs routed to the environment that generated the link. An empty string+ // is rendered for the WASM preview, where no real endpoint is available.+ context.insert(+ "redirection_log_endpoint",+ payment_link_data+ .redirection_log_endpoint+ .as_ref()+ .map(|endpoint| endpoint.as_str())+ .unwrap_or(""),+ );+// Modify Html template with rendered js and rendered css fileslet html_template =include_str!("../../router/src/core/payment_link/payment_link_status/status.html")diff --git a/crates/payment_link/src/types.rs b/crates/payment_link/src/types.rsindex 519ad6cf1a..00e52fda46 100644--- a/crates/payment_link/src/types.rs+++ b/crates/payment_link/src/types.rs@@ -13,12 +13,14 @@ pub struct PaymentLinkFormData {pub css_script: String,pub sdk_url: url::Url,pub html_meta_tags: String,+ pub redirection_log_endpoint: Option<url::Url>,}#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)]pub struct PaymentLinkStatusData {pub js_script: String,pub css_script: String,+ pub redirection_log_endpoint: Option<url::Url>,}#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]diff --git a/crates/payment_link/src/wasm.rs b/crates/payment_link/src/wasm.rsindex 875e560c3d..05042c4462 100644--- a/crates/payment_link/src/wasm.rs+++ b/crates/payment_link/src/wasm.rs@@ -77,6 +77,7 @@ pub fn generate_payment_link_preview_impl(config_json: &str) -> Result<String, Ssdk_url,css_script,html_meta_tags,+ redirection_log_endpoint: None,};build_payment_link_html(payment_link_form_data)diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rsindex 5041ced537..75242ccd5b 100644--- a/crates/router/src/core/payment_link.rs+++ b/crates/router/src/core/payment_link.rs@@ -40,6 +40,17 @@ use crate::{},};+fn get_redirection_log_endpoint(base_url: &str) -> RouterResult<url::Url> {+ format!(+ "{}/{}",+ base_url.trim_end_matches('/'),+ payment_link::consts::REDIRECTION_LOG_ENDPOINT+ )+ .parse::<url::Url>()+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to parse redirection log endpoint")+}+pub async fn retrieve_payment_link(state: SessionState,payment_link_id: String,@@ -359,6 +370,7 @@ pub async fn initiate_secure_payment_link_flow(let payment_link_error_data = services::PaymentLinkStatusData {js_script,css_script,+ redirection_log_endpoint: Some(get_redirection_log_endpoint(&state.base_url)?),};logger::info!("payment link data, for building payment link status page {:?}",@@ -401,6 +413,7 @@ pub async fn initiate_secure_payment_link_flow(sdk_url: state.conf.payment_link.sdk_url.clone(),css_script,html_meta_tags,+ redirection_log_endpoint: Some(get_redirection_log_endpoint(&state.base_url)?),};let allowed_domains = payment_link_config.allowed_domains@@ -457,6 +470,7 @@ pub async fn initiate_payment_link_flow(let payment_link_error_data = services::PaymentLinkStatusData {js_script,css_script,+ redirection_log_endpoint: Some(get_redirection_log_endpoint(&state.base_url)?),};logger::info!("payment link data, for building payment link status page {:?}",@@ -473,6 +487,7 @@ pub async fn initiate_payment_link_flow(sdk_url: state.conf.payment_link.sdk_url.clone(),css_script,html_meta_tags,+ redirection_log_endpoint: Some(get_redirection_log_endpoint(&state.base_url)?),};logger::info!("payment link data, for building open payment link {:?}",@@ -972,6 +987,7 @@ pub async fn get_payment_link_status(let payment_link_status_data = services::PaymentLinkStatusData {js_script,css_script,+ redirection_log_endpoint: Some(get_redirection_log_endpoint(&state.base_url)?),};Ok(services::ApplicationResponse::PaymentLinkForm(Box::new(services::api::PaymentLinkAction::PaymentLinkStatus(payment_link_status_data),diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.htmlindex ac04479e44..3871b236c9 100644--- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html+++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html@@ -302,6 +302,7 @@</div></div><script>+ window.__REDIRECTION_LOG_ENDPOINT = '{{redirection_log_endpoint}}';{{logging_template}}{{locale_template}}{{rendered_js}}diff --git a/crates/router/src/core/payment_link/payment_link_status/status.html b/crates/router/src/core/payment_link/payment_link_status/status.htmlindex 7531c8df44..cb3cd9e2e7 100644--- a/crates/router/src/core/payment_link/payment_link_status/status.html+++ b/crates/router/src/core/payment_link/payment_link_status/status.html@@ -11,6 +11,7 @@href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800"/><script>+ window.__REDIRECTION_LOG_ENDPOINT = '{{redirection_log_endpoint}}';{{logging_template}}{{locale_template}}{{ rendered_js }}diff --git a/crates/router/src/services/redirection/assets/redirect_error_logs_push.js b/crates/router/src/services/redirection/assets/redirect_error_logs_push.jsindex ee59bf7726..859b1ee54c 100644--- a/crates/router/src/services/redirection/assets/redirect_error_logs_push.js+++ b/crates/router/src/services/redirection/assets/redirect_error_logs_push.js@@ -24,10 +24,26 @@ function parseRoute(url) {}}+ /*+ * Payment-link pages set `window.__REDIRECTION_LOG_ENDPOINT` from the+ * backend, so prefer that value. It is authoritative because custom domains+ * can hide the real router hostname+ */function getEnvRoute(url) {+ // If the backend rendered a non-empty log endpoint string, use it unconditionally.+ const backendEndpoint = window.__REDIRECTION_LOG_ENDPOINT;+ if (+ typeof backendEndpoint === "string" &&+ backendEndpoint.length > 0+ ) {+ return backendEndpoint;+ }+const route = new URL(url).hostname;- return route === "api.hyperswitch.io" ? "https://api.hyperswitch.io/logs/redirection" : "https://sandbox.hyperswitch.io/logs/redirection";-}+ return route === "api.hyperswitch.io"+ ? "https://api.hyperswitch.io/logs/redirection"+ : "https://app.hyperswitch.io/api/logs/redirection";+ }async function postLog(log, urlToPost) {