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

fix(payment_link): add support for payment link ui rules in payment link wasm and added default logo (#13385)

Gitanjli6262532424e5
diff --git a/crates/payment_link/src/consts.rs b/crates/payment_link/src/consts.rs
new file mode 100644
index 0000000000..14a482b173
--- /dev/null
+++ b/crates/payment_link/src/consts.rs
@@ -0,0 +1,3 @@
+/// Default merchant logo link for payment links.
+pub const DEFAULT_MERCHANT_LOGO: &str =
+ "https://live.hyperswitch.io/payment-link-assets/Merchant_placeholder.png";
diff --git a/crates/payment_link/src/lib.rs b/crates/payment_link/src/lib.rs
index eea6d90954..9b2a4ac8f0 100644
--- a/crates/payment_link/src/lib.rs
+++ b/crates/payment_link/src/lib.rs
@@ -1,3 +1,4 @@
+pub mod consts;
pub mod css_generator;
pub mod js_generator;
pub mod meta_tags;
diff --git a/crates/payment_link/src/types.rs b/crates/payment_link/src/types.rs
index 6630117f6e..519ad6cf1a 100644
--- a/crates/payment_link/src/types.rs
+++ b/crates/payment_link/src/types.rs
@@ -1,5 +1,7 @@
//! Payment link specific types
+use std::collections::HashMap;
+
use common_utils::{
events::{ApiEventMetric, ApiEventsType},
impl_api_event_type,
@@ -31,6 +33,8 @@ pub struct PreloadSDKParams {
pub struct PaymentLinkPreviewConfig {
pub test_mode: Option<bool>,
pub preload_sdk_with_params: Option<PreloadSDKParams>,
+ #[serde(skip_serializing)]
+ pub payment_link_ui_rules: Option<HashMap<String, HashMap<String, String>>>,
#[serde(flatten)]
pub payment_link_details: api_models::payments::PaymentLinkDetails,
}
diff --git a/crates/payment_link/src/wasm.rs b/crates/payment_link/src/wasm.rs
index 5523489628..875e560c3d 100644
--- a/crates/payment_link/src/wasm.rs
+++ b/crates/payment_link/src/wasm.rs
@@ -1,8 +1,8 @@
use api_models::admin::PaymentLinkConfig;
use crate::{
- build_payment_link_html, get_css_script, get_js_script, get_meta_tags_html,
- types::PaymentLinkPreviewConfig, PaymentLinkFormData,
+ build_payment_link_html, consts::DEFAULT_MERCHANT_LOGO, get_css_script, get_js_script,
+ get_meta_tags_html, types::PaymentLinkPreviewConfig, PaymentLinkFormData,
};
const SDK_URL: &str = env!("SDK_URL");
@@ -10,9 +10,13 @@ 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 preview_config: PaymentLinkPreviewConfig = serde_json::from_str(config_json)
+ let mut preview_config: PaymentLinkPreviewConfig = serde_json::from_str(config_json)
.map_err(|e| format!("Failed to deserialize PaymentLinkPreviewConfig: {}", e))?;
+ if preview_config.payment_link_details.merchant_logo.is_empty() {
+ preview_config.payment_link_details.merchant_logo = DEFAULT_MERCHANT_LOGO.to_string();
+ }
+
let payment_link_details = &preview_config.payment_link_details;
let mut payment_link_config = PaymentLinkConfig {
@@ -42,7 +46,7 @@ pub fn generate_payment_link_preview_impl(config_json: &str) -> Result<String, S
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,
+ payment_link_ui_rules: preview_config.payment_link_ui_rules.clone(),
custom_message_for_payment_method_types: payment_link_details
.custom_message_for_payment_method_types
.clone(),
@@ -53,7 +57,9 @@ pub fn generate_payment_link_preview_impl(config_json: &str) -> Result<String, S
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;
+ if config_from_json.payment_link_ui_rules.is_some() {
+ 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))?;
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 53aea96cf9..e9def7713a 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -171,10 +171,6 @@ pub const DEFAULT_ENABLE_SAVED_PAYMENT_METHOD: bool = false;
/// [PaymentLink] Default bool for enabling button only when form is ready
pub const DEFAULT_ENABLE_BUTTON_ONLY_ON_FORM_READY: bool = false;
-/// Default Merchant Logo Link
-pub const DEFAULT_MERCHANT_LOGO: &str =
- "https://live.hyperswitch.io/payment-link-assets/Merchant_placeholder.png";
-
/// Default Payment Link Background color
pub const DEFAULT_BACKGROUND_COLOR: &str = "#212E46";
diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs
index ccaad16fe2..5041ced537 100644
--- a/crates/router/src/core/payment_link.rs
+++ b/crates/router/src/core/payment_link.rs
@@ -13,6 +13,7 @@ use error_stack::{report, ResultExt};
use futures::future;
use hyperswitch_domain_models::api::{GenericLinks, GenericLinksData};
use hyperswitch_masking::{PeekInterface, Secret};
+use payment_link::consts::DEFAULT_MERCHANT_LOGO;
use router_env::logger;
use time::PrimitiveDateTime;
@@ -24,8 +25,8 @@ use crate::{
consts::{
self, DEFAULT_ALLOWED_DOMAINS, DEFAULT_BACKGROUND_COLOR, DEFAULT_DISPLAY_SDK_ONLY,
DEFAULT_ENABLE_BUTTON_ONLY_ON_FORM_READY, DEFAULT_ENABLE_SAVED_PAYMENT_METHOD,
- DEFAULT_HIDE_CARD_NICKNAME_FIELD, DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG,
- DEFAULT_SDK_LAYOUT, DEFAULT_SHOW_CARD_FORM, DEFAULT_SHOW_MERCHANT_NAME,
+ DEFAULT_HIDE_CARD_NICKNAME_FIELD, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT,
+ DEFAULT_SHOW_CARD_FORM, DEFAULT_SHOW_MERCHANT_NAME,
},
errors::RouterResponse,
get_payment_link_config_value, get_payment_link_config_value_based_on_priority,