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(payments): [Payment links] Add configs for payment link (#7288)

Debarati Ghatak72080c67c792
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json
index 61ad3bf976..9c4339b7e3 100644
--- a/api-reference-v2/openapi_spec.json
+++ b/api-reference-v2/openapi_spec.json
@@ -13373,6 +13373,16 @@
"type": "string",
"description": "Text for payment link's handle confirm button",
"nullable": true
+ },
+ "custom_message_for_card_terms": {
+ "type": "string",
+ "description": "Text for customizing message for card terms",
+ "nullable": true
+ },
+ "payment_button_colour": {
+ "type": "string",
+ "description": "Custom background colour for payment link's handle confirm button",
+ "nullable": true
}
}
},
@@ -13463,6 +13473,16 @@
"type": "string",
"description": "Text for payment link's handle confirm button",
"nullable": true
+ },
+ "custom_message_for_card_terms": {
+ "type": "string",
+ "description": "Text for customizing message for card terms",
+ "nullable": true
+ },
+ "payment_button_colour": {
+ "type": "string",
+ "description": "Custom background colour for payment link's handle confirm button",
+ "nullable": true
}
}
},
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index 1919e9744f..57153fd233 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -16429,6 +16429,16 @@
"type": "string",
"description": "Text for payment link's handle confirm button",
"nullable": true
+ },
+ "custom_message_for_card_terms": {
+ "type": "string",
+ "description": "Text for customizing message for card terms",
+ "nullable": true
+ },
+ "payment_button_colour": {
+ "type": "string",
+ "description": "Custom background colour for payment link's handle confirm button",
+ "nullable": true
}
}
},
@@ -16519,6 +16529,16 @@
"type": "string",
"description": "Text for payment link's handle confirm button",
"nullable": true
+ },
+ "custom_message_for_card_terms": {
+ "type": "string",
+ "description": "Text for customizing message for card terms",
+ "nullable": true
+ },
+ "payment_button_colour": {
+ "type": "string",
+ "description": "Custom background colour for payment link's handle confirm button",
+ "nullable": true
}
}
},
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index c131243394..7a0ece8520 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -2708,6 +2708,10 @@ pub struct PaymentLinkConfigRequest {
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
/// Text for payment link's handle confirm button
pub payment_button_text: Option<String>,
+ /// Text for customizing message for card terms
+ pub custom_message_for_card_terms: Option<String>,
+ /// Custom background colour for payment link's handle confirm button
+ pub payment_button_colour: Option<String>,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
@@ -2779,6 +2783,10 @@ pub struct PaymentLinkConfig {
pub branding_visibility: Option<bool>,
/// Text for payment link's handle confirm button
pub payment_button_text: Option<String>,
+ /// Text for customizing message for card terms
+ pub custom_message_for_card_terms: Option<String>,
+ /// Custom background colour for payment link's handle confirm button
+ pub payment_button_colour: Option<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index f996de726e..bf7dd37739 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -7531,6 +7531,8 @@ pub struct PaymentLinkDetails {
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
pub branding_visibility: Option<bool>,
pub payment_button_text: Option<String>,
+ pub custom_message_for_card_terms: Option<String>,
+ pub payment_button_colour: Option<String>,
}
#[derive(Debug, serde::Serialize, Clone)]
@@ -7541,6 +7543,8 @@ pub struct SecurePaymentLinkDetails {
#[serde(flatten)]
pub payment_link_details: PaymentLinkDetails,
pub payment_button_text: Option<String>,
+ pub custom_message_for_card_terms: Option<String>,
+ pub payment_button_colour: Option<String>,
}
#[derive(Debug, serde::Serialize)]
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 2cbd7deb42..70f969bd2a 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -584,6 +584,8 @@ pub struct PaymentLinkConfigRequest {
pub background_image: Option<PaymentLinkBackgroundImageConfig>,
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
pub payment_button_text: Option<String>,
+ pub custom_message_for_card_terms: Option<String>,
+ pub payment_button_colour: Option<String>,
}
#[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 4cb48f6c36..57233306c2 100644
--- a/crates/diesel_models/src/payment_intent.rs
+++ b/crates/diesel_models/src/payment_intent.rs
@@ -171,6 +171,10 @@ pub struct PaymentLinkConfigRequestForPayments {
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
/// Text for payment link's handle confirm button
pub payment_button_text: Option<String>,
+ /// Text for customizing message for card terms
+ pub custom_message_for_card_terms: Option<String>,
+ /// Custom background colour for payment link's handle confirm button
+ pub payment_button_colour: Option<String>,
}
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 6c8f499388..3a1bd933b5 100644
--- a/crates/hyperswitch_domain_models/src/lib.rs
+++ b/crates/hyperswitch_domain_models/src/lib.rs
@@ -404,6 +404,8 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
)
}),
payment_button_text: item.payment_button_text,
+ custom_message_for_card_terms: item.custom_message_for_card_terms,
+ payment_button_colour: item.payment_button_colour,
}
}
fn convert_back(self) -> api_models::admin::PaymentLinkConfigRequest {
@@ -420,6 +422,8 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
background_image,
details_layout,
payment_button_text,
+ custom_message_for_card_terms,
+ payment_button_colour,
} = self;
api_models::admin::PaymentLinkConfigRequest {
theme,
@@ -440,6 +444,8 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
background_image: background_image
.map(|background_image| background_image.convert_back()),
payment_button_text,
+ custom_message_for_card_terms,
+ payment_button_colour,
}
}
}
diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs
index 477803c92a..ba63319aab 100644
--- a/crates/router/src/core/payment_link.rs
+++ b/crates/router/src/core/payment_link.rs
@@ -130,6 +130,8 @@ pub async fn form_payment_link_data(
details_layout: None,
branding_visibility: None,
payment_button_text: None,
+ custom_message_for_card_terms: None,
+ payment_button_colour: None,
}
};
@@ -276,6 +278,8 @@ pub async fn form_payment_link_data(
details_layout: payment_link_config.details_layout,
branding_visibility: payment_link_config.branding_visibility,
payment_button_text: payment_link_config.payment_button_text.clone(),
+ custom_message_for_card_terms: payment_link_config.custom_message_for_card_terms.clone(),
+ payment_button_colour: payment_link_config.payment_button_colour.clone(),
};
Ok((
@@ -327,6 +331,8 @@ pub async fn initiate_secure_payment_link_flow(
show_card_form_by_default: payment_link_config.show_card_form_by_default,
payment_link_details: *link_details.to_owned(),
payment_button_text: payment_link_config.payment_button_text,
+ custom_message_for_card_terms: payment_link_config.custom_message_for_card_terms,
+ payment_button_colour: payment_link_config.payment_button_colour,
};
let js_script = format!(
"window.__PAYMENT_DETAILS = {}",
@@ -625,6 +631,24 @@ pub fn get_payment_link_config_based_on_priority(
(hide_card_nickname_field, DEFAULT_HIDE_CARD_NICKNAME_FIELD),
(show_card_form_by_default, DEFAULT_SHOW_CARD_FORM)
);
+
+ let (
+ details_layout,
+ background_image,
+ payment_button_text,
+ custom_message_for_card_terms,
+ payment_button_colour,
+ ) = get_payment_link_config_value!(
+ payment_create_link_config,
+ business_theme_configs,
+ (details_layout),
+ (background_image, |background_image| background_image
+ .foreign_into()),
+ (payment_button_text),
+ (custom_message_for_card_terms),
+ (payment_button_colour),
+ );
+
let payment_link_config =
PaymentLinkConfig {
theme,
@@ -640,41 +664,11 @@ pub fn get_payment_link_config_based_on_priority(
transaction_details: payment_create_link_config.as_ref().and_then(
|payment_link_config| payment_link_config.theme_config.transaction_details.clone(),
),
- details_layout: payment_create_link_config
- .as_ref()
- .and_then(|payment_link_config| payment_link_config.theme_config.details_layout)
- .or_else(|| {
- business_theme_configs
- .as_ref()
- .and_then(|business_theme_config| business_theme_config.details_layout)
- }),
- background_image: payment_create_link_config
- .as_ref()
- .and_then(|payment_link_config| {
- payment_link_config.theme_config.background_image.clone()
- })
- .or_else(|| {
- business_theme_configs
- .as_ref()
- .and_then(|business_theme_config| {
- business_theme_config
- .background_image
- .as_ref()
- .map(|background_image| background_image.clone().foreign_into())
- })
- }),
- payment_button_text: payment_create_link_config
- .as_ref()
- .and_then(|payment_link_config| {
- payment_link_config.theme_config.payment_button_text.clone()
- })
- .or_else(|| {
- business_theme_configs
- .as_ref()
- .and_then(|business_theme_config| {
- business_theme_config.payment_button_text.clone()
- })
- }),
+ details_layout,
+ background_image,
+ payment_button_text,
+ custom_message_for_card_terms,
+ payment_button_colour,
};
Ok((payment_link_config, domain_name))
@@ -778,6 +772,8 @@ pub async fn get_payment_link_status(
details_layout: None,
branding_visibility: None,
payment_button_text: None,
+ custom_message_for_card_terms: None,
+ payment_button_colour: None,
}
};
diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.css b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.css
index b8ccdeba33..7b34730680 100644
--- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.css
+++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.css
@@ -640,7 +640,6 @@ body {
margin-top: 20px;
width: 100%;
height: 38px;
- background-color: var(--primary-color);
border: 0;
border-radius: 4px;
font-size: 18px;
diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js
index 378900ba9a..a73067a5bc 100644
--- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js
+++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js
@@ -308,6 +308,7 @@ function initializeEventListeners(paymentDetails) {
if (submitButtonNode instanceof HTMLButtonElement) {
submitButtonNode.style.color = contrastBWColor;
+ submitButtonNode.style.backgroundColor = paymentDetails.payment_button_colour || primaryColor;
}
if (hyperCheckoutCartImageNode instanceof HTMLDivElement) {
diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js b/crates/router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js
index 2d2b2c30ae..6abe5f7d5b 100644
--- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js
+++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js
@@ -64,6 +64,7 @@ function initializeSDK() {
},
showCardFormByDefault: paymentDetails.show_card_form_by_default,
hideCardNicknameField: hideCardNicknameField,
+ customMessageForCardTerms: paymentDetails.custom_message_for_card_terms,
};
// @ts-ignore
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
diff --git a/crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js b/crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js
index 9ae64ec313..a8a00e4de9 100644
--- a/crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js
+++ b/crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js
@@ -87,6 +87,7 @@ if (!isFramed) {
},
hideCardNicknameField: hideCardNicknameField,
showCardFormByDefault: paymentDetails.show_card_form_by_default,
+ customMessageForCardTerms: paymentDetails.custom_message_for_card_terms,
};
// @ts-ignore
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 7302831e50..49ff8eb35d 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -4301,6 +4301,8 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
)
}),
payment_button_text: config.payment_button_text,
+ custom_message_for_card_terms: config.custom_message_for_card_terms,
+ payment_button_colour: config.payment_button_colour,
}
}
}
@@ -4364,6 +4366,8 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
)
}),
payment_button_text: config.payment_button_text,
+ custom_message_for_card_terms: config.custom_message_for_card_terms,
+ payment_button_colour: config.payment_button_colour,
}
}
}
diff --git a/crates/router/src/macros.rs b/crates/router/src/macros.rs
index 962bdb9652..580ccb73f5 100644
--- a/crates/router/src/macros.rs
+++ b/crates/router/src/macros.rs
@@ -32,4 +32,37 @@ macro_rules! get_payment_link_config_value {
$(get_payment_link_config_value_based_on_priority!($config, $business_config, $field, $default)),*
)
};
+ ($config:expr, $business_config:expr, $(($field:ident)),*) => {
+ (
+ $(
+ $config
+ .as_ref()
+ .and_then(|pc_config| pc_config.theme_config.$field.clone())
+ .or_else(|| {
+ $business_config
+ .as_ref()
+ .and_then(|business_config| business_config.$field.clone())
+ })
+ ),*
+ )
+ };
+ ($config:expr, $business_config:expr, $(($field:ident $(, $transform:expr)?)),* $(,)?) => {
+ (
+ $(
+ $config
+ .as_ref()
+ .and_then(|pc_config| pc_config.theme_config.$field.clone())
+ .or_else(|| {
+ $business_config
+ .as_ref()
+ .and_then(|business_config| {
+ let value = business_config.$field.clone();
+ $(let value = value.map($transform);)?
+ value
+ })
+ })
+ ),*
+ )
+ };
+
}
diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs
index dd15079efe..7fa38d6cbb 100644
--- a/crates/router/src/routes/payments.rs
+++ b/crates/router/src/routes/payments.rs
@@ -2566,7 +2566,7 @@ pub async fn payments_finish_redirection(
let locking_action = payload.get_locking_input(flow.clone());
- api::server_wrap(
+ Box::pin(api::server_wrap(
flow,
state,
&req,
@@ -2588,7 +2588,7 @@ pub async fn payments_finish_redirection(
profile_id: profile_id.clone(),
},
locking_action,
- )
+ ))
.await
}
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index f8f8830fda..7ac8792b50 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -2105,6 +2105,8 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
.background_image
.map(|background_image| background_image.foreign_into()),
payment_button_text: item.payment_button_text,
+ custom_message_for_card_terms: item.custom_message_for_card_terms,
+ payment_button_colour: item.payment_button_colour,
}
}
}
@@ -2128,6 +2130,8 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
.background_image
.map(|background_image| background_image.foreign_into()),
payment_button_text: item.payment_button_text,
+ custom_message_for_card_terms: item.custom_message_for_card_terms,
+ payment_button_colour: item.payment_button_colour,
}
}
}