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
feat(payment-links): expose template generation as wasm builds (#10225)
Kashif431922af1a12
diff --git a/Cargo.lock b/Cargo.lockindex ac52cc6cf3..a180c565e0 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4374,6 +4374,7 @@ dependencies = ["http 0.2.12","masking 0.1.0","mime",+ "payment_link","router_derive","router_env","rustc-hash 1.1.0",@@ -6068,6 +6069,25 @@ version = "0.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"+[[package]]+name = "payment_link"+version = "0.1.0"+dependencies = [+ "api_models",+ "common_utils",+ "error-stack 0.4.1",+ "getrandom 0.2.16",+ "router_env",+ "serde",+ "serde_json",+ "tera",+ "thiserror 1.0.69",+ "toml 0.8.22",+ "url",+ "urlencoding",+ "wasm-bindgen",+]+[[package]]name = "payment_methods"version = "0.1.0"@@ -7302,6 +7322,7 @@ dependencies = ["once_cell","openidconnect","openssl",+ "payment_link","payment_methods","pm_auth","prost-types",diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 54c6940140..48ba263b74 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -10883,7 +10883,7 @@ pub enum PaymentLinkData {PaymentLinkStatusDetails(Box<PaymentLinkStatusDetails>),}-#[derive(Debug, serde::Serialize, Clone)]+#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]pub struct PaymentLinkDetails {pub amount: StringMajorUnit,pub currency: api_enums::Currency,diff --git a/crates/cards/src/validate.rs b/crates/cards/src/validate.rsindex ed0647cd21..aaa07f96bc 100644--- a/crates/cards/src/validate.rs+++ b/crates/cards/src/validate.rs@@ -145,7 +145,7 @@ impl FromStr for CardNumber {];#[cfg(not(target_arch = "wasm32"))]let valid_test_cards = match router_env_which() {- Env::Development | Env::Sandbox => valid_test_cards,+ Env::Development | Env::Sandbox | Env::Integ => valid_test_cards,Env::Production => vec![],};@@ -174,7 +174,7 @@ impl FromStr for NetworkToken {];#[cfg(not(target_arch = "wasm32"))]let valid_test_network_tokens = match router_env_which() {- Env::Development | Env::Sandbox => valid_test_network_tokens,+ Env::Development | Env::Sandbox | Env::Integ => valid_test_network_tokens,Env::Production => vec![],};diff --git a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rsindex 36783535ee..326fbd24dc 100644--- a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs@@ -681,7 +681,9 @@ impl From<SantanderPaymentStatus> for AttemptStatus {impl From<router_env::env::Env> for Environment {fn from(item: router_env::env::Env) -> Self {match item {- router_env::env::Env::Sandbox | router_env::env::Env::Development => Self::Sandbox,+ router_env::env::Env::Sandbox+ | router_env::env::Env::Development+ | router_env::env::Env::Integ => Self::Sandbox,router_env::env::Env::Production => Self::Production,}}diff --git a/crates/hyperswitch_domain_models/Cargo.toml b/crates/hyperswitch_domain_models/Cargo.tomlindex 5075cfc901..935bd42e64 100644--- a/crates/hyperswitch_domain_models/Cargo.toml+++ b/crates/hyperswitch_domain_models/Cargo.toml@@ -13,8 +13,8 @@ encryption_service = []olap = []payouts = ["api_models/payouts"]frm = ["api_models/frm"]-v2 = ["api_models/v2", "diesel_models/v2", "common_utils/v2", "common_types/v2"]-v1 = ["api_models/v1", "diesel_models/v1", "common_utils/v1", "common_types/v1"]+v2 = ["api_models/v2", "diesel_models/v2", "common_utils/v2", "common_types/v2", "payment_link/v2"]+v1 = ["api_models/v1", "diesel_models/v1", "common_utils/v1", "common_types/v1", "payment_link/v1"]tokenization_v2 = ["api_models/tokenization_v2", "diesel_models/tokenization_v2"]dummy_connector = []revenue_recovery= []@@ -28,6 +28,7 @@ common_utils = { version = "0.1.0", path = "../common_utils", features = ["asynccommon_types = { version = "0.1.0", path = "../common_types" }diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"], default-features = false }masking = { version = "0.1.0", path = "../masking" }+payment_link = { version = "0.1.0", path = "../payment_link", default-features = false }router_derive = { version = "0.1.0", path = "../router_derive" }router_env = { version = "0.1.0", path = "../router_env" }diff --git a/crates/hyperswitch_domain_models/src/api.rs b/crates/hyperswitch_domain_models/src/api.rsindex 723cc458e7..b0280d9e42 100644--- a/crates/hyperswitch_domain_models/src/api.rs+++ b/crates/hyperswitch_domain_models/src/api.rs@@ -52,7 +52,7 @@ impl<T: ApiEventMetric> ApiEventMetric for ApplicationResponse<T> {}}-impl_api_event_type!(Miscellaneous, (PaymentLinkFormData, GenericLinkFormData));+impl_api_event_type!(Miscellaneous, (GenericLinkFormData));#[derive(Debug, PartialEq)]pub struct RedirectionFormData {@@ -64,22 +64,8 @@ pub struct RedirectionFormData {#[derive(Debug, Eq, PartialEq)]pub enum PaymentLinkAction {- PaymentLinkFormData(PaymentLinkFormData),- PaymentLinkStatus(PaymentLinkStatusData),-}--#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)]-pub struct PaymentLinkFormData {- pub js_script: String,- pub css_script: String,- pub sdk_url: url::Url,- pub html_meta_tags: String,-}--#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)]-pub struct PaymentLinkStatusData {- pub js_script: String,- pub css_script: String,+ PaymentLinkFormData(payment_link::PaymentLinkFormData),+ PaymentLinkStatus(payment_link::PaymentLinkStatusData),}#[derive(Debug, Eq, PartialEq)]@@ -96,7 +82,7 @@ pub enum GenericLinksData {PayoutLink(GenericLinkFormData),PayoutLinkStatus(GenericLinkStatusData),PaymentMethodCollectStatus(GenericLinkStatusData),- SecurePaymentLink(PaymentLinkFormData),+ SecurePaymentLink(payment_link::PaymentLinkFormData),}impl Display for GenericLinksData {diff --git a/crates/payment_link/Cargo.toml b/crates/payment_link/Cargo.tomlnew file mode 100644index 0000000000..da9e1591d9--- /dev/null+++ b/crates/payment_link/Cargo.toml@@ -0,0 +1,42 @@+[package]+name = "payment_link"+description = "Payment Link rendering and WASM bindings"+version = "0.1.0"+edition.workspace = true+rust-version.workspace = true+license.workspace = true++[lib]+crate-type = ["rlib", "cdylib"]++[features]+default = ["v1"]+v1 = ["api_models/v1"]+v2 = ["api_models/v2"]+wasm = ["dep:wasm-bindgen", "getrandom/js"]++[dependencies]+serde = { version = "1.0.219", features = ["derive"] }+serde_json = "1.0.140"+tera = "1.20.0"+url = { version = "2.5.4", features = ["serde"] }+urlencoding = "2.1.3"+error-stack = "0.4.1"+thiserror = "1.0.69"+wasm-bindgen = { version = "0.2", optional = true }++# First party crates+api_models = { path = "../api_models", default-features = false }+common_utils = { path = "../common_utils" }+getrandom = { version = "0.2.16", optional = true }++[build-dependencies]+router_env = { path = "../router_env" }+toml = "0.8"+serde = { version = "1.0.219", features = ["derive"] }++[package.metadata.wasm-pack.profile.release]+wasm-opt = ["--enable-bulk-memory", "--enable-nontrapping-float-to-int"]++[lints]+workspace = truediff --git a/crates/payment_link/build.rs b/crates/payment_link/build.rsnew file mode 100644index 0000000000..d05887cc18--- /dev/null+++ b/crates/payment_link/build.rs@@ -0,0 +1,59 @@+use std::{collections::HashMap, fs, str::FromStr};++use router_env::env::Env;+use serde::Deserialize;++fn main() {+ // Manually deserialize ENVIRONMENT variable to Env enum+ let environment = std::env::var("ENVIRONMENT")+ .ok()+ .and_then(|env_str| Env::from_str(&env_str).ok())+ .unwrap_or_else(|| {+ #[cfg(debug_assertions)]+ let default = Env::Development;+ #[cfg(not(debug_assertions))]+ let default = Env::Production;+ default+ });++ // Use the payment_link specific SDK URL configuration+ let sdk_config_path = "config/sdk_urls.toml";++ // Tell cargo to rerun if config file changes+ println!("cargo:rerun-if-changed={}", sdk_config_path);+ println!("cargo:rerun-if-env-changed=ENVIRONMENT");++ // Read and parse SDK URLs TOML file+ #[allow(clippy::panic)]+ let config_content = fs::read_to_string(sdk_config_path).unwrap_or_else(|e| {+ panic!(+ "Failed to read SDK config file '{}': {}",+ sdk_config_path, e+ );+ });++ #[allow(clippy::panic)]+ let config: HashMap<Env, EnvConfig> = toml::from_str(&config_content).unwrap_or_else(|e| {+ panic!("Failed to parse TOML in '{}': {}", sdk_config_path, e);+ });++ // Extract SDK URL for the current environment+ #[allow(clippy::panic)]+ let sdk_url = config+ .get(&environment)+ .map(|c| c.sdk_url.as_str())+ .unwrap_or_else(|| {+ panic!(+ "Missing [{}] section in config file: {}",+ environment, sdk_config_path+ )+ });++ // Set environment variable for compile-time access+ println!("cargo:rustc-env=SDK_URL={}", sdk_url);+}++#[derive(Debug, Deserialize)]+struct EnvConfig {+ sdk_url: String,+}diff --git a/crates/payment_link/config/sdk_urls.toml b/crates/payment_link/config/sdk_urls.tomlnew file mode 100644index 0000000000..3e42c90b03--- /dev/null+++ b/crates/payment_link/config/sdk_urls.toml@@ -0,0 +1,23 @@+# SDK URL Configuration for Payment Link WASM Builds+#+# Used ONLY for WASM builds - read at compile-time by build.rs and embedded into the WASM binary.+# Router uses different SDK URLs from config/*.toml files (can be overridden by env vars at runtime).+#+# We don't use router's configs because build.rs cannot replicate router's complex runtime+# configuration resolution (TOML + env var overrides). This simplified config only needs+# the ENVIRONMENT env var to select the appropriate SDK URL.+#+# Usage: ENVIRONMENT=integ wasm-pack build --features wasm --target web+# Environments must match router_env::Env enum: development, integ, sandbox, production++[development]+sdk_url = "http://localhost:9050/HyperLoader.js"++[integ]+sdk_url = "https://dev.hyperswitch.io/v0/HyperLoader.js"++[sandbox]+sdk_url = "https://beta.hyperswitch.io/v1/HyperLoader.js"++[production]+sdk_url = "https://checkout.hyperswitch.io/v0/HyperLoader.js"diff --git a/crates/payment_link/src/css_generator.rs b/crates/payment_link/src/css_generator.rsnew file mode 100644index 0000000000..beff892ff1--- /dev/null+++ b/crates/payment_link/src/css_generator.rs@@ -0,0 +1,100 @@+use std::collections::HashMap;++use api_models::admin::PaymentLinkConfig;+use error_stack::{Result, ResultExt};++#[derive(Debug, thiserror::Error)]+pub enum PaymentLinkError {+ #[error("Invalid CSS selector: {0}")]+ InvalidCssSelector(String),+}++pub fn get_css_script(payment_link_config: &PaymentLinkConfig) -> Result<String, PaymentLinkError> {+ let custom_rules_css_option = payment_link_config+ .payment_link_ui_rules+ .as_ref()+ .map(generate_dynamic_css)+ .transpose()?;++ let color_scheme_css = get_color_scheme_css(payment_link_config);++ if let Some(custom_rules_css) = custom_rules_css_option {+ Ok(format!("{color_scheme_css}\n{custom_rules_css}"))+ } else {+ Ok(color_scheme_css)+ }+}++fn get_color_scheme_css(payment_link_config: &PaymentLinkConfig) -> String {+ let background_primary_color = payment_link_config+ .background_colour+ .clone()+ .unwrap_or(payment_link_config.theme.clone());+ format!(+ ":root {{+ --primary-color: {background_primary_color};+ }}"+ )+}++fn generate_dynamic_css(+ rules: &HashMap<String, HashMap<String, String>>,+) -> Result<String, PaymentLinkError> {+ if rules.is_empty() {+ return Ok(String::new());+ }++ let mut css_string = String::new();+ css_string.push_str("/* Dynamically Injected UI Rules */\n");++ for (selector, styles_map) in rules {+ if selector.trim().is_empty() {+ return Err(PaymentLinkError::InvalidCssSelector(+ "CSS selector cannot be empty.".to_string(),+ ))+ .attach_printable("Empty CSS selector found in payment_link_ui_rules")?;+ }++ css_string.push_str(selector);+ css_string.push_str(" {\n");++ for (prop_camel_case, css_value) in styles_map {+ let css_property = camel_to_kebab(prop_camel_case);++ css_string.push_str(" ");+ css_string.push_str(&css_property);+ css_string.push_str(": ");+ css_string.push_str(css_value);+ css_string.push_str(";\n");+ }+ css_string.push_str("}\n");+ }+ Ok(css_string)+}++fn camel_to_kebab(s: &str) -> String {+ let mut result = String::new();+ if s.is_empty() {+ return result;+ }++ let chars: Vec<char> = s.chars().collect();++ for (i, &ch) in chars.iter().enumerate() {+ if ch.is_uppercase() {+ let should_add_dash = i > 0+ && (chars.get(i - 1).map(|c| c.is_lowercase()).unwrap_or(false)+ || (i + 1 < chars.len()+ && chars.get(i + 1).map(|c| c.is_lowercase()).unwrap_or(false)+ && chars.get(i - 1).map(|c| c.is_uppercase()).unwrap_or(false)));++ if should_add_dash {+ result.push('-');+ }+ result.push(ch.to_ascii_lowercase());+ } else {+ result.push(ch);+ }+ }+ result+}diff --git a/crates/payment_link/src/js_generator.rs b/crates/payment_link/src/js_generator.rsnew file mode 100644index 0000000000..4c637576c9--- /dev/null+++ b/crates/payment_link/src/js_generator.rs@@ -0,0 +1,16 @@+use api_models::payments::PaymentLinkData;+use error_stack::{Result, ResultExt};++#[derive(Debug, thiserror::Error)]+pub enum PaymentLinkError {+ #[error("Failed to serialize payment link data")]+ SerializationFailed,+}++pub fn get_js_script(payment_details: &PaymentLinkData) -> Result<String, PaymentLinkError> {+ let payment_details_str = serde_json::to_string(payment_details)+ .change_context(PaymentLinkError::SerializationFailed)+ .attach_printable("Failed to serialize PaymentLinkData")?;+ let url_encoded_str = urlencoding::encode(&payment_details_str);+ Ok(format!("window.__PAYMENT_DETAILS = '{url_encoded_str}';"))+}diff --git a/crates/payment_link/src/lib.rs b/crates/payment_link/src/lib.rsnew file mode 100644index 0000000000..eea6d90954--- /dev/null+++ b/crates/payment_link/src/lib.rs@@ -0,0 +1,39 @@+pub mod css_generator;+pub mod js_generator;+pub mod meta_tags;+pub mod template_renderer;+pub mod types;++#[cfg(feature = "wasm")]+pub mod wasm;++pub use css_generator::get_css_script;+pub use js_generator::get_js_script;+pub use meta_tags::get_meta_tags_html;+pub use template_renderer::{+ build_payment_link_html, build_secure_payment_link_html, get_payment_link_status,+};+pub use types::{PaymentLinkFormData, PaymentLinkStatusData};+// WASM bindings - thin wrappers around implementation functions in wasm.rs+#[cfg(feature = "wasm")]+use wasm_bindgen::prelude::*;++/// Generate a payment link HTML preview from configuration JSON+///+/// This function is exported to JavaScript when compiled as WASM.+/// It wraps the implementation function in wasm.rs.+#[cfg(feature = "wasm")]+#[wasm_bindgen]+pub fn generate_payment_link_preview(config_json: &str) -> Result<String, JsValue> {+ wasm::generate_payment_link_preview_impl(config_json).map_err(|e| JsValue::from_str(&e))+}++/// Validate payment link configuration and return validation results as JSON+///+/// This function is exported to JavaScript when compiled as WASM.+/// It wraps the implementation function in wasm.rs.+#[cfg(feature = "wasm")]+#[wasm_bindgen]+pub fn validate_payment_link_config(config_json: &str) -> Result<String, JsValue> {+ wasm::validate_payment_link_config_impl(config_json).map_err(|e| JsValue::from_str(&e))+}diff --git a/crates/payment_link/src/meta_tags.rs b/crates/payment_link/src/meta_tags.rsnew file mode 100644index 0000000000..ccaba31fa5--- /dev/null+++ b/crates/payment_link/src/meta_tags.rs@@ -0,0 +1,13 @@+use api_models::payments::PaymentLinkDetails;++pub fn get_meta_tags_html(payment_details: &PaymentLinkDetails) -> String {+ format!(+ r#"<meta property="og:title" content="Payment request from {0}"/>+ <meta property="og:description" content="{1}"/>"#,+ payment_details.merchant_name.clone(),+ payment_details+ .merchant_description+ .clone()+ .unwrap_or_default()+ )+}diff --git a/crates/payment_link/src/template_renderer.rs b/crates/payment_link/src/template_renderer.rsnew file mode 100644index 0000000000..51d54de58d--- /dev/null+++ b/crates/payment_link/src/template_renderer.rs@@ -0,0 +1,189 @@+use error_stack::{Result, ResultExt};+use tera::{Context, Tera};++use crate::types::{PaymentLinkFormData, PaymentLinkStatusData};++#[derive(Debug, thiserror::Error)]+pub enum PaymentLinkError {+ #[error("Failed to render template")]+ TemplateRenderError,+ #[error("Failed to build template")]+ TemplateBuildError,+}++pub fn build_payment_link_html(+ payment_link_data: PaymentLinkFormData,+) -> Result<String, PaymentLinkError> {+ let (tera, mut context) = build_payment_link_template(payment_link_data)+ .change_context(PaymentLinkError::TemplateBuildError)+ .attach_printable("Failed to build payment link's HTML template")?;++ let payment_link_initiator = include_str!(+ "../../router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js"+ )+ .to_string();+ context.insert("payment_link_initiator", &payment_link_initiator);++ tera.render("payment_link", &context)+ .change_context(PaymentLinkError::TemplateRenderError)+ .attach_printable("Error while rendering open payment link's HTML template")+}++pub fn build_secure_payment_link_html(+ payment_link_data: PaymentLinkFormData,+) -> Result<String, PaymentLinkError> {+ let (tera, mut context) = build_payment_link_template(payment_link_data)+ .change_context(PaymentLinkError::TemplateBuildError)+ .attach_printable("Failed to build payment link's HTML template")?;++ let payment_link_initiator = include_str!(+ "../../router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js"+ )+ .to_string();+ context.insert("payment_link_initiator", &payment_link_initiator);++ tera.render("payment_link", &context)+ .change_context(PaymentLinkError::TemplateRenderError)+ .attach_printable("Error while rendering secure payment link's HTML template")+}++fn build_payment_link_template(+ payment_link_data: PaymentLinkFormData,+) -> Result<(Tera, Context), PaymentLinkError> {+ let mut tera = Tera::default();++ let css_template =+ include_str!("../../router/src/core/payment_link/payment_link_initiate/payment_link.css")+ .to_string();+ let _ = tera.add_raw_template("payment_link_css", &css_template);+ let mut context = Context::new();+ context.insert("css_color_scheme", &payment_link_data.css_script);++ let rendered_css = tera+ .render("payment_link_css", &context)+ .change_context(PaymentLinkError::TemplateRenderError)?;++ let js_template =+ include_str!("../../router/src/core/payment_link/payment_link_initiate/payment_link.js")+ .to_string();+ let _ = tera.add_raw_template("payment_link_js", &js_template);++ context.insert("payment_details_js_script", &payment_link_data.js_script);+ let sdk_origin = payment_link_data+ .sdk_url+ .host_str()+ .ok_or(PaymentLinkError::TemplateBuildError)+ .attach_printable("Host missing for payment link SDK URL")+ .and_then(|host| {+ if host == "localhost" {+ let port = payment_link_data+ .sdk_url+ .port()+ .ok_or(PaymentLinkError::TemplateBuildError)+ .attach_printable("Port missing for localhost in SDK URL")?;+ Ok(format!(+ "{}://{}:{}",+ payment_link_data.sdk_url.scheme(),+ host,+ port+ ))+ } else {+ Ok(format!("{}://{}", payment_link_data.sdk_url.scheme(), host))+ }+ })?;+ context.insert("sdk_origin", &sdk_origin);++ let rendered_js = tera+ .render("payment_link_js", &context)+ .change_context(PaymentLinkError::TemplateRenderError)?;++ let logging_template =+ include_str!("../../router/src/services/redirection/assets/redirect_error_logs_push.js")+ .to_string();+ let locale_template = include_str!("../../router/src/core/payment_link/locale.js").to_string();++ let html_template =+ include_str!("../../router/src/core/payment_link/payment_link_initiate/payment_link.html")+ .to_string();+ let _ = tera.add_raw_template("payment_link", &html_template);++ context.insert("rendered_meta_tag_html", &payment_link_data.html_meta_tags);+ context.insert(+ "preload_link_tags",+ &get_preload_link_html_template(&payment_link_data.sdk_url),+ );+ context.insert(+ "hyperloader_sdk_link",+ &get_hyper_loader_sdk(&payment_link_data.sdk_url),+ );+ context.insert("locale_template", &locale_template);+ context.insert("rendered_css", &rendered_css);+ context.insert("rendered_js", &rendered_js);+ context.insert("logging_template", &logging_template);++ Ok((tera, context))+}++fn get_hyper_loader_sdk(sdk_url: &url::Url) -> String {+ format!("<script src=\"{sdk_url}\" onload=\"initializeSDK()\"></script>")+}++fn get_preload_link_html_template(sdk_url: &url::Url) -> String {+ format!(+ r#"<link rel="preload" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800" as="style">+ <link rel="preload" href="{sdk_url}" as="script">"#,+ )+}++pub fn get_payment_link_status(+ payment_link_data: PaymentLinkStatusData,+) -> Result<String, PaymentLinkError> {+ let mut tera = Tera::default();++ // Add modification to css template with dynamic data+ let css_template =+ include_str!("../../router/src/core/payment_link/payment_link_status/status.css")+ .to_string();+ let _ = tera.add_raw_template("payment_link_css", &css_template);+ let mut context = Context::new();+ context.insert("css_color_scheme", &payment_link_data.css_script);++ let rendered_css = tera+ .render("payment_link_css", &context)+ .change_context(PaymentLinkError::TemplateRenderError)?;++ //Locale template+ let locale_template = include_str!("../../router/src/core/payment_link/locale.js");++ // Logging template+ let logging_template =+ include_str!("../../router/src/services/redirection/assets/redirect_error_logs_push.js")+ .to_string();++ // Add modification to js template with dynamic data+ let js_template =+ include_str!("../../router/src/core/payment_link/payment_link_status/status.js")+ .to_string();+ let _ = tera.add_raw_template("payment_link_js", &js_template);+ context.insert("payment_details_js_script", &payment_link_data.js_script);++ let rendered_js = tera+ .render("payment_link_js", &context)+ .change_context(PaymentLinkError::TemplateRenderError)?;++ // Modify Html template with rendered js and rendered css files+ let html_template =+ include_str!("../../router/src/core/payment_link/payment_link_status/status.html")+ .to_string();+ let _ = tera.add_raw_template("payment_link_status", &html_template);++ context.insert("rendered_css", &rendered_css);+ context.insert("locale_template", &locale_template);++ context.insert("rendered_js", &rendered_js);+ context.insert("logging_template", &logging_template);++ tera.render("payment_link_status", &context)+ .change_context(PaymentLinkError::TemplateRenderError)+ .attach_printable("Error while rendering payment link status page")+}diff --git a/crates/payment_link/src/types.rs b/crates/payment_link/src/types.rsnew file mode 100644index 0000000000..d91ee08c6b--- /dev/null+++ b/crates/payment_link/src/types.rs@@ -0,0 +1,22 @@+//! Payment link specific types++use common_utils::{+ events::{ApiEventMetric, ApiEventsType},+ impl_api_event_type,+};++#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)]+pub struct PaymentLinkFormData {+ pub js_script: String,+ pub css_script: String,+ pub sdk_url: url::Url,+ pub html_meta_tags: String,+}++#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)]+pub struct PaymentLinkStatusData {+ pub js_script: String,+ pub css_script: String,+}++impl_api_event_type!(Miscellaneous, (PaymentLinkFormData, PaymentLinkStatusData));diff --git a/crates/payment_link/src/wasm.rs b/crates/payment_link/src/wasm.rsnew file mode 100644index 0000000000..7a4911e714--- /dev/null+++ b/crates/payment_link/src/wasm.rs@@ -0,0 +1,126 @@+use api_models::{admin::PaymentLinkConfig, payments::PaymentLinkData};++use crate::{+ build_payment_link_html, get_css_script, get_js_script, get_meta_tags_html, PaymentLinkFormData,+};++const SDK_URL: &str = env!("SDK_URL");++/// Implementation function for generating payment link preview+/// Called by the wasm_bindgen wrapper in lib.rs+pub fn generate_payment_link_preview_impl(config_json: &str) -> Result<String, String> {+ let payment_link_details: api_models::payments::PaymentLinkDetails =+ serde_json::from_str(config_json)+ .map_err(|e| format!("Failed to deserialize PaymentLinkDetails: {}", e))?;++ let mut payment_link_config = PaymentLinkConfig {+ theme: payment_link_details.theme.clone(),+ logo: payment_link_details.merchant_logo.clone(),+ seller_name: payment_link_details.merchant_name.clone(),+ sdk_layout: payment_link_details.sdk_layout.clone(),+ display_sdk_only: payment_link_details.display_sdk_only,+ hide_card_nickname_field: payment_link_details.hide_card_nickname_field,+ show_card_form_by_default: payment_link_details.show_card_form_by_default,+ transaction_details: payment_link_details.transaction_details.clone(),+ background_image: payment_link_details.background_image.clone(),+ details_layout: payment_link_details.details_layout,+ branding_visibility: payment_link_details.branding_visibility,+ payment_button_text: payment_link_details.payment_button_text.clone(),+ custom_message_for_card_terms: payment_link_details.custom_message_for_card_terms.clone(),+ payment_button_colour: payment_link_details.payment_button_colour.clone(),+ skip_status_screen: payment_link_details.skip_status_screen,+ background_colour: payment_link_details.background_colour.clone(),+ payment_button_text_colour: payment_link_details.payment_button_text_colour.clone(),+ sdk_ui_rules: payment_link_details.sdk_ui_rules.clone(),+ enable_button_only_on_form_ready: payment_link_details.enable_button_only_on_form_ready,+ payment_form_header_text: payment_link_details.payment_form_header_text.clone(),+ payment_form_label_type: payment_link_details.payment_form_label_type,+ show_card_terms: payment_link_details.show_card_terms,+ is_setup_mandate_flow: payment_link_details.is_setup_mandate_flow,+ color_icon_card_cvc_error: payment_link_details.color_icon_card_cvc_error.clone(),+ enabled_saved_payment_method: false,+ allowed_domains: None,+ payment_link_ui_rules: None,+ };++ if let Ok(config_from_json) = serde_json::from_str::<PaymentLinkConfig>(config_json) {+ payment_link_config.enabled_saved_payment_method =+ config_from_json.enabled_saved_payment_method;+ payment_link_config.allowed_domains = config_from_json.allowed_domains;+ payment_link_config.payment_link_ui_rules = config_from_json.payment_link_ui_rules;+ }++ let sdk_url = url::Url::parse(SDK_URL).map_err(|e| format!("Invalid SDK URL: {}", e))?;++ let js_script = get_js_script(&PaymentLinkData::PaymentLinkDetails(Box::new(+ payment_link_details.clone(),+ )))+ .map_err(|e| format!("Failed to generate JS script: {:?}", e))?;++ let css_script = get_css_script(&payment_link_config)+ .map_err(|e| format!("Failed to generate CSS script: {:?}", e))?;++ let html_meta_tags = get_meta_tags_html(&payment_link_details);++ let payment_link_form_data = PaymentLinkFormData {+ js_script,+ sdk_url,+ css_script,+ html_meta_tags,+ };++ build_payment_link_html(payment_link_form_data)+ .map_err(|e| format!("Failed to build payment link HTML: {:?}", e))+}++/// Implementation function for validating payment link config+/// Called by the wasm_bindgen wrapper in lib.rs+pub fn validate_payment_link_config_impl(config_json: &str) -> Result<String, String> {+ let config: api_models::payments::PaymentLinkDetails =+ serde_json::from_str(config_json).map_err(|e| format!("Failed to parse config: {}", e))?;++ let mut errors = Vec::new();+ let mut warnings = Vec::new();++ if !config.theme.starts_with('#') || config.theme.len() != 7 {+ errors.push("Theme color must be a valid hex color (e.g., #4E6ADD)".to_string());+ }++ if let Some(bg_color) = &config.background_colour {+ if !bg_color.starts_with('#') || bg_color.len() != 7 {+ errors.push("Background color must be a valid hex color (e.g., #FFFFFF)".to_string());+ }+ }++ if !config.merchant_logo.is_empty() && !config.merchant_logo.starts_with("http") {+ warnings.push("Merchant logo should be a valid HTTP/HTTPS URL".to_string());+ }++ let valid_layouts = ["accordion", "tabs", "spaced_accordion"];+ if !valid_layouts.contains(&config.sdk_layout.as_str()) {+ errors.push(format!(+ "SDK layout must be one of: {}",+ valid_layouts.join(", ")+ ));+ }++ if config.merchant_name.is_empty() {+ errors.push("Merchant name is required".to_string());+ }++ if config.client_secret.is_empty() {+ errors.push("Client secret is required".to_string());+ }++ if config.pub_key.is_empty() {+ errors.push("Publishable key is required".to_string());+ }++ let validation_result = serde_json::json!({+ "valid": errors.is_empty(),+ "errors": errors,+ "warnings": warnings+ });++ Ok(validation_result.to_string())+}diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.tomlindex 71cb0f54bf..4a4ba4987c 100644--- a/crates/router/Cargo.toml+++ b/crates/router/Cargo.toml@@ -34,7 +34,7 @@ payout_retry = ["payouts"]recon = ["email", "api_models/recon"]retry = []v2 = [ "common_default", "api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2", "kgraph_utils/v2", "common_utils/v2", "hyperswitch_connectors/v2", "hyperswitch_interfaces/v2", "common_types/v2", "revenue_recovery", "scheduler/v2", "euclid/v2", "payment_methods/v2", "tokenization_v2", "subscriptions/v2"]-v1 = ["common_default", "api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "hyperswitch_interfaces/v1", "kgraph_utils/v1", "common_utils/v1", "hyperswitch_connectors/v1", "common_types/v1", "scheduler/v1", "payment_methods/v1", "subscriptions/v1"]+v1 = ["common_default", "api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "hyperswitch_interfaces/v1", "kgraph_utils/v1", "common_utils/v1", "hyperswitch_connectors/v1", "common_types/v1", "scheduler/v1", "payment_link/v1", "payment_methods/v1", "subscriptions/v1"]dynamic_routing = ["external_services/dynamic_routing", "storage_impl/dynamic_routing", "api_models/dynamic_routing"]revenue_recovery = ["api_models/revenue_recovery", "hyperswitch_interfaces/revenue_recovery", "hyperswitch_domain_models/revenue_recovery", "hyperswitch_connectors/revenue_recovery", "external_services/revenue_recovery", "dep:prost-types"]tokenization_v2 = ["api_models/tokenization_v2", "diesel_models/tokenization_v2", "hyperswitch_domain_models/tokenization_v2", "storage_impl/tokenization_v2"]@@ -142,6 +142,7 @@ router_derive = { version = "0.1.0", path = "../router_derive" }router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }scheduler = { version = "0.1.0", path = "../scheduler", default-features = false }storage_impl = { version = "0.1.0", path = "../storage_impl", default-features = false }+payment_link = { version = "0.1.0", path = "../payment_link", default-features = false }payment_methods = { version = "0.1.0", path = "../payment_methods", default-features = false }subscriptions = { version = "0.1.0", path = "../subscriptions", default-features = false }diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rsindex 7d989244fc..f55ec326d6 100644--- a/crates/router/src/core/payment_link.rs+++ b/crates/router/src/core/payment_link.rs@@ -1,6 +1,4 @@pub mod validator;-use std::collections::HashMap;-use actix_web::http::header;use api_models::{admin::PaymentLinkConfig,@@ -481,119 +479,20 @@ pub async fn initiate_payment_link_flow(}}-/*-The get_js_script function is used to inject dynamic value to payment_link sdk, which is unique to every payment.-*/--fn get_js_script(payment_details: &PaymentLinkData) -> RouterResult<String> {- let payment_details_str = serde_json::to_string(payment_details)+pub fn get_js_script(payment_details: &PaymentLinkData) -> RouterResult<String> {+ payment_link::get_js_script(payment_details).change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to serialize PaymentLinkData")?;- let url_encoded_str = urlencoding::encode(&payment_details_str);- Ok(format!("window.__PAYMENT_DETAILS = '{url_encoded_str}';"))-}--fn camel_to_kebab(s: &str) -> String {- let mut result = String::new();- if s.is_empty() {- return result;- }-- let chars: Vec<char> = s.chars().collect();-- for (i, &ch) in chars.iter().enumerate() {- if ch.is_uppercase() {- let should_add_dash = i > 0- && (chars.get(i - 1).map(|c| c.is_lowercase()).unwrap_or(false)- || (i + 1 < chars.len()- && chars.get(i + 1).map(|c| c.is_lowercase()).unwrap_or(false)- && chars.get(i - 1).map(|c| c.is_uppercase()).unwrap_or(false)));-- if should_add_dash {- result.push('-');- }- result.push(ch.to_ascii_lowercase());- } else {- result.push(ch);- }- }- result-}--fn generate_dynamic_css(- rules: &HashMap<String, HashMap<String, String>>,-) -> Result<String, errors::ApiErrorResponse> {- if rules.is_empty() {- return Ok(String::new());- }-- let mut css_string = String::new();- css_string.push_str("/* Dynamically Injected UI Rules */\n");-- for (selector, styles_map) in rules {- if selector.trim().is_empty() {- return Err(errors::ApiErrorResponse::InvalidRequestData {- message: "CSS selector cannot be empty.".to_string(),- });- }-- css_string.push_str(selector);- css_string.push_str(" {\n");-- for (prop_camel_case, css_value) in styles_map {- let css_property = camel_to_kebab(prop_camel_case);-- css_string.push_str(" ");- css_string.push_str(&css_property);- css_string.push_str(": ");- css_string.push_str(css_value);- css_string.push_str(";\n");- }- css_string.push_str("}\n");- }- Ok(css_string)}-fn get_payment_link_css_script(+pub fn get_payment_link_css_script(payment_link_config: &PaymentLinkConfig,-) -> Result<String, errors::ApiErrorResponse> {- let custom_rules_css_option = payment_link_config- .payment_link_ui_rules- .as_ref()- .map(generate_dynamic_css)- .transpose()?;-- let color_scheme_css = get_color_scheme_css(payment_link_config);-- if let Some(custom_rules_css) = custom_rules_css_option {- Ok(format!("{color_scheme_css}\n{custom_rules_css}"))- } else {- Ok(color_scheme_css)- }-}--fn get_color_scheme_css(payment_link_config: &PaymentLinkConfig) -> String {- let background_primary_color = payment_link_config- .background_colour- .clone()- .unwrap_or(payment_link_config.theme.clone());- format!(- ":root {{- --primary-color: {background_primary_color};- }}"- )+) -> RouterResult<String> {+ payment_link::get_css_script(payment_link_config)+ .change_context(errors::ApiErrorResponse::InternalServerError)}-fn get_meta_tags_html(payment_details: &api_models::payments::PaymentLinkDetails) -> String {- format!(- r#"<meta property="og:title" content="Payment request from {0}"/>- <meta property="og:description" content="{1}"/>"#,- payment_details.merchant_name.clone(),- payment_details- .merchant_description- .clone()- .unwrap_or_default()- )+pub fn get_meta_tags_html(payment_details: &api_models::payments::PaymentLinkDetails) -> String {+ payment_link::get_meta_tags_html(payment_details)}fn validate_sdk_requirements(@@ -971,7 +870,7 @@ pub async fn get_payment_link_status(// converting first letter of merchant name to upperCaselet merchant_name = capitalize_first_char(&payment_link_config.seller_name);- let css_script = get_color_scheme_css(&payment_link_config);+ let css_script = get_payment_link_css_script(&payment_link_config)?;let profile_id = payment_link.profile_iddiff --git a/crates/router/src/core/payments/vault_session.rs b/crates/router/src/core/payments/vault_session.rsindex 482267833d..b9c460c33f 100644--- a/crates/router/src/core/payments/vault_session.rs+++ b/crates/router/src/core/payments/vault_session.rs@@ -241,7 +241,7 @@ pub async fn generate_vault_session_details(router_types::ConnectorAuthType::SignatureKey { api_secret, .. },) => {let sdk_env = match state.conf.env {- Env::Sandbox | Env::Development => "sandbox",+ Env::Sandbox | Env::Development | Env::Integ => "sandbox",Env::Production => "live",}.to_string();diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex 98066a4d04..c1ab087d3c 100644--- a/crates/router/src/services/api.rs+++ b/crates/router/src/services/api.rs@@ -23,13 +23,12 @@ use common_utils::{consts::{DEFAULT_TENANT, TENANT_HEADER, X_HS_LATENCY},errors::{ErrorSwitch, ReportSwitchExt},};-use error_stack::{report, Report, ResultExt};+use error_stack::{Report, ResultExt};use hyperswitch_domain_models::router_data_v2::flow_common_types as common_types;pub use hyperswitch_domain_models::{api::{ApplicationResponse, GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData,- GenericLinks, PaymentLinkAction, PaymentLinkFormData, PaymentLinkStatusData,- RedirectionFormData,+ GenericLinks, PaymentLinkAction, RedirectionFormData,},payment_method_data::PaymentMethodData,router_response_types::RedirectForm,@@ -49,9 +48,9 @@ pub use hyperswitch_interfaces::{},};use masking::{Maskable, PeekInterface};+pub use payment_link::{PaymentLinkFormData, PaymentLinkStatusData};use router_env::{instrument, tracing, RequestId, Tag};use serde::Serialize;-use tera::{Context, Error as TeraError, Tera};use super::{authentication::AuthenticateAndFetch,@@ -1678,112 +1677,13 @@ pub fn build_redirection_form(}}-fn build_payment_link_template(- payment_link_data: PaymentLinkFormData,-) -> CustomResult<(Tera, Context), errors::ApiErrorResponse> {- let mut tera = Tera::default();-- // Add modification to css template with dynamic data- let css_template =- include_str!("../core/payment_link/payment_link_initiate/payment_link.css").to_string();- let _ = tera.add_raw_template("payment_link_css", &css_template);- let mut context = Context::new();- context.insert("css_color_scheme", &payment_link_data.css_script);-- let rendered_css = match tera.render("payment_link_css", &context) {- Ok(rendered_css) => rendered_css,- Err(tera_error) => {- crate::logger::warn!("{tera_error}");- Err(errors::ApiErrorResponse::InternalServerError)?- }- };-- // Add modification to js template with dynamic data- let js_template =- include_str!("../core/payment_link/payment_link_initiate/payment_link.js").to_string();-- let _ = tera.add_raw_template("payment_link_js", &js_template);-- context.insert("payment_details_js_script", &payment_link_data.js_script);- let sdk_origin = payment_link_data- .sdk_url- .host_str()- .ok_or_else(|| {- logger::error!("Host missing for payment link SDK URL");- report!(errors::ApiErrorResponse::InternalServerError)- })- .and_then(|host| {- if host == "localhost" {- let port = payment_link_data.sdk_url.port().ok_or_else(|| {- logger::error!("Port missing for localhost in SDK URL");- report!(errors::ApiErrorResponse::InternalServerError)- })?;- Ok(format!(- "{}://{}:{}",- payment_link_data.sdk_url.scheme(),- host,- port- ))- } else {- Ok(format!("{}://{}", payment_link_data.sdk_url.scheme(), host))- }- })?;- context.insert("sdk_origin", &sdk_origin);-- let rendered_js = match tera.render("payment_link_js", &context) {- Ok(rendered_js) => rendered_js,- Err(tera_error) => {- crate::logger::warn!("{tera_error}");- Err(errors::ApiErrorResponse::InternalServerError)?- }- };-- // Logging template- let logging_template =- include_str!("redirection/assets/redirect_error_logs_push.js").to_string();- //Locale template- let locale_template = include_str!("../core/payment_link/locale.js").to_string();-- // Modify Html template with rendered js and rendered css files- let html_template =- include_str!("../core/payment_link/payment_link_initiate/payment_link.html").to_string();-- let _ = tera.add_raw_template("payment_link", &html_template);-- context.insert("rendered_meta_tag_html", &payment_link_data.html_meta_tags);-- context.insert(- "preload_link_tags",- &get_preload_link_html_template(&payment_link_data.sdk_url),- );-- context.insert(- "hyperloader_sdk_link",- &get_hyper_loader_sdk(&payment_link_data.sdk_url),- );- context.insert("locale_template", &locale_template);- context.insert("rendered_css", &rendered_css);- context.insert("rendered_js", &rendered_js);-- context.insert("logging_template", &logging_template);-- Ok((tera, context))-}-pub fn build_payment_link_html(payment_link_data: PaymentLinkFormData,) -> CustomResult<String, errors::ApiErrorResponse> {- let (tera, mut context) = build_payment_link_template(payment_link_data)- .attach_printable("Failed to build payment link's HTML template")?;- let payment_link_initiator =- include_str!("../core/payment_link/payment_link_initiate/payment_link_initiator.js")- .to_string();- context.insert("payment_link_initiator", &payment_link_initiator);-- tera.render("payment_link", &context)- .map_err(|tera_error: TeraError| {- crate::logger::warn!("{tera_error}");- report!(errors::ApiErrorResponse::InternalServerError)+ payment_link::build_payment_link_html(payment_link_data)+ .map_err(|e| {+ logger::error!("Failed to build payment link HTML: {:?}", e);+ errors::ApiErrorResponse::InternalServerError}).attach_printable("Error while rendering open payment link's HTML template")}@@ -1791,91 +1691,23 @@ pub fn build_payment_link_html(pub fn build_secure_payment_link_html(payment_link_data: PaymentLinkFormData,) -> CustomResult<String, errors::ApiErrorResponse> {- let (tera, mut context) = build_payment_link_template(payment_link_data)- .attach_printable("Failed to build payment link's HTML template")?;- let payment_link_initiator =- include_str!("../core/payment_link/payment_link_initiate/secure_payment_link_initiator.js")- .to_string();- context.insert("payment_link_initiator", &payment_link_initiator);-- tera.render("payment_link", &context)- .map_err(|tera_error: TeraError| {- crate::logger::warn!("{tera_error}");- report!(errors::ApiErrorResponse::InternalServerError)+ payment_link::build_secure_payment_link_html(payment_link_data)+ .map_err(|e| {+ logger::error!("Failed to build secure payment link HTML: {:?}", e);+ errors::ApiErrorResponse::InternalServerError}).attach_printable("Error while rendering secure payment link's HTML template")}-fn get_hyper_loader_sdk(sdk_url: &url::Url) -> String {- format!("<script src=\"{sdk_url}\" onload=\"initializeSDK()\"></script>")-}--fn get_preload_link_html_template(sdk_url: &url::Url) -> String {- format!(- r#"<link rel="preload" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800" as="style">- <link rel="preload" href="{sdk_url}" as="script">"#,- )-}-pub fn get_payment_link_status(payment_link_data: PaymentLinkStatusData,) -> CustomResult<String, errors::ApiErrorResponse> {- let mut tera = Tera::default();-- // Add modification to css template with dynamic data- let css_template =- include_str!("../core/payment_link/payment_link_status/status.css").to_string();- let _ = tera.add_raw_template("payment_link_css", &css_template);- let mut context = Context::new();- context.insert("css_color_scheme", &payment_link_data.css_script);-- let rendered_css = match tera.render("payment_link_css", &context) {- Ok(rendered_css) => rendered_css,- Err(tera_error) => {- crate::logger::warn!("{tera_error}");- Err(errors::ApiErrorResponse::InternalServerError)?- }- };-- //Locale template- let locale_template = include_str!("../core/payment_link/locale.js");-- // Logging template- let logging_template =- include_str!("redirection/assets/redirect_error_logs_push.js").to_string();-- // Add modification to js template with dynamic data- let js_template =- include_str!("../core/payment_link/payment_link_status/status.js").to_string();- let _ = tera.add_raw_template("payment_link_js", &js_template);- context.insert("payment_details_js_script", &payment_link_data.js_script);-- let rendered_js = match tera.render("payment_link_js", &context) {- Ok(rendered_js) => rendered_js,- Err(tera_error) => {- crate::logger::warn!("{tera_error}");- Err(errors::ApiErrorResponse::InternalServerError)?- }- };-- // Modify Html template with rendered js and rendered css files- let html_template =- include_str!("../core/payment_link/payment_link_status/status.html").to_string();- let _ = tera.add_raw_template("payment_link_status", &html_template);-- context.insert("rendered_css", &rendered_css);- context.insert("locale_template", &locale_template);-- context.insert("rendered_js", &rendered_js);- context.insert("logging_template", &logging_template);-- match tera.render("payment_link_status", &context) {- Ok(rendered_html) => Ok(rendered_html),- Err(tera_error) => {- crate::logger::warn!("{tera_error}");- Err(errors::ApiErrorResponse::InternalServerError)?- }- }+ payment_link::get_payment_link_status(payment_link_data)+ .map_err(|e| {+ logger::error!("Failed to get payment link status: {:?}", e);+ errors::ApiErrorResponse::InternalServerError+ })+ .attach_printable("Error while rendering payment link status page")}pub fn extract_mapped_fields(diff --git a/crates/router_env/src/env.rs b/crates/router_env/src/env.rsindex 644f9b50a1..0af4bf314a 100644--- a/crates/router_env/src/env.rs+++ b/crates/router_env/src/env.rs@@ -19,7 +19,17 @@ pub mod vars {/// Current environment.#[derive(- Debug, Default, Deserialize, Serialize, Clone, Copy, strum::Display, strum::EnumString,+ Debug,+ Default,+ Deserialize,+ Serialize,+ Clone,+ Copy,+ PartialEq,+ Eq,+ Hash,+ strum::Display,+ strum::EnumString,)]#[serde(rename_all = "lowercase")]#[strum(serialize_all = "lowercase")]@@ -27,6 +37,8 @@ pub enum Env {/// Development environment.#[default]Development,+ /// Integration environment.+ Integ,/// Sandbox environment.Sandbox,/// Production environment.@@ -44,10 +56,11 @@ pub fn which() -> Env {}/// Three letter (lowercase) prefix corresponding to the current environment.-/// Either `dev`, `snd` or `prd`.+/// Either `dev`, `integ`, `snd` or `prd`.pub fn prefix_for_env() -> &'static str {match which() {Env::Development => "dev",+ Env::Integ => "integ",Env::Sandbox => "snd",Env::Production => "prd",}