feat(payment_link): expose configurations for payment links (#7742)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Kashif
2025-04-09 12:46:15 +05:30
committed by GitHub
parent 0a5d249543
commit b475171dd2
16 changed files with 274 additions and 10 deletions

View File

@ -139,6 +139,9 @@ pub async fn form_payment_link_data(
sdk_ui_rules: None,
payment_link_ui_rules: None,
enable_button_only_on_form_ready: DEFAULT_ENABLE_BUTTON_ONLY_ON_FORM_READY,
payment_form_header_text: None,
payment_form_label_type: None,
show_card_terms: None,
}
};
@ -296,6 +299,9 @@ pub async fn form_payment_link_data(
payment_link_ui_rules: payment_link_config.payment_link_ui_rules.clone(),
status: payment_intent.status,
enable_button_only_on_form_ready: payment_link_config.enable_button_only_on_form_ready,
payment_form_header_text: payment_link_config.payment_form_header_text.clone(),
payment_form_label_type: payment_link_config.payment_form_label_type,
show_card_terms: payment_link_config.show_card_terms,
};
Ok((
@ -356,6 +362,9 @@ pub async fn initiate_secure_payment_link_flow(
payment_link_ui_rules: payment_link_config.payment_link_ui_rules,
enable_button_only_on_form_ready: payment_link_config
.enable_button_only_on_form_ready,
payment_form_header_text: payment_link_config.payment_form_header_text,
payment_form_label_type: payment_link_config.payment_form_label_type,
show_card_terms: payment_link_config.show_card_terms,
};
let js_script = format!(
"window.__PAYMENT_DETAILS = {}",
@ -674,6 +683,9 @@ pub fn get_payment_link_config_based_on_priority(
payment_button_text_colour,
sdk_ui_rules,
payment_link_ui_rules,
payment_form_header_text,
payment_form_label_type,
show_card_terms,
) = get_payment_link_config_value!(
payment_create_link_config,
business_theme_configs,
@ -688,6 +700,9 @@ pub fn get_payment_link_config_based_on_priority(
(payment_button_text_colour),
(sdk_ui_rules),
(payment_link_ui_rules),
(payment_form_header_text),
(payment_form_label_type),
(show_card_terms),
);
let payment_link_config =
@ -716,6 +731,9 @@ pub fn get_payment_link_config_based_on_priority(
sdk_ui_rules,
payment_link_ui_rules,
enable_button_only_on_form_ready,
payment_form_header_text,
payment_form_label_type,
show_card_terms,
};
Ok((payment_link_config, domain_name))
@ -827,6 +845,9 @@ pub async fn get_payment_link_status(
sdk_ui_rules: None,
payment_link_ui_rules: None,
enable_button_only_on_form_ready: DEFAULT_ENABLE_BUTTON_ONLY_ON_FORM_READY,
payment_form_header_text: None,
payment_form_label_type: None,
show_card_terms: None,
}
};

View File

@ -12,6 +12,7 @@ function initializeSDK() {
var paymentDetails = window.__PAYMENT_DETAILS;
var clientSecret = paymentDetails.client_secret;
var sdkUiRules = paymentDetails.sdk_ui_rules;
var labelType = paymentDetails.payment_form_label_type;
var appearance = {
variables: {
colorPrimary: paymentDetails.theme || "rgb(0, 109, 249)",
@ -25,9 +26,12 @@ function initializeSDK() {
colorBackground: "rgb(255, 255, 255)",
},
};
if (sdkUiRules !== null && typeof sdkUiRules === "object" && Object.getPrototypeOf(sdkUiRules) === Object.prototype) {
if (isObject(sdkUiRules)) {
appearance.rules = sdkUiRules;
}
if (labelType !== null && typeof labelType === "string") {
appearance.labels = labelType;
}
// @ts-ignore
hyper = window.Hyper(pub_key, {
isPreloadEnabled: false,
@ -70,11 +74,18 @@ function initializeSDK() {
hideCardNicknameField: hideCardNicknameField,
customMessageForCardTerms: paymentDetails.custom_message_for_card_terms,
};
// @ts-ignore
var showCardTerms = paymentDetails.show_card_terms;
if (showCardTerms !== null && typeof showCardTerms === "string") {
unifiedCheckoutOptions.terms = {
card: showCardTerms
};
}
var paymentMethodsHeaderText = paymentDetails.payment_form_header_text;
if (paymentMethodsHeaderText !== null && typeof paymentMethodsHeaderText === "string") {
unifiedCheckoutOptions.paymentMethodsHeaderText = paymentMethodsHeaderText;
}
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
// @ts-ignore
mountUnifiedCheckout("#unified-checkout");
// @ts-ignore
showSDK(paymentDetails.display_sdk_only, paymentDetails.enable_button_only_on_form_ready);
let shimmer = document.getElementById("payment-details-shimmer");

View File

@ -33,6 +33,7 @@ if (!isFramed) {
var paymentDetails = window.__PAYMENT_DETAILS;
var clientSecret = paymentDetails.client_secret;
var sdkUiRules = paymentDetails.sdk_ui_rules;
var labelType = paymentDetails.payment_form_label_type;
var appearance = {
variables: {
colorPrimary: paymentDetails.theme || "rgb(0, 109, 249)",
@ -46,9 +47,12 @@ if (!isFramed) {
colorBackground: "rgb(255, 255, 255)",
},
};
if (sdkUiRules !== null && typeof sdkUiRules === "object" && Object.getPrototypeOf(sdkUiRules) === Object.prototype) {
if (isObject(sdkUiRules)) {
appearance.rules = sdkUiRules;
}
if (labelType !== null && typeof labelType === "string") {
appearance.labels = labelType;
}
// @ts-ignore
hyper = window.Hyper(pub_key, {
isPreloadEnabled: false,
@ -93,11 +97,19 @@ if (!isFramed) {
showCardFormByDefault: paymentDetails.show_card_form_by_default,
customMessageForCardTerms: paymentDetails.custom_message_for_card_terms,
};
// @ts-ignore
var showCardTerms = paymentDetails.show_card_terms;
if (showCardTerms !== null && typeof showCardTerms === "string") {
unifiedCheckoutOptions.terms = {
card: showCardTerms
};
}
var paymentMethodsHeaderText = paymentDetails.payment_form_header_text;
if (paymentMethodsHeaderText !== null && typeof paymentMethodsHeaderText === "string") {
unifiedCheckoutOptions.paymentMethodsHeaderText = paymentMethodsHeaderText;
}
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
// @ts-ignore
mountUnifiedCheckout("#unified-checkout");
// @ts-ignore
showSDK(paymentDetails.display_sdk_only, paymentDetails.enable_button_only_on_form_ready);
let shimmer = document.getElementById("payment-details-shimmer");

View File

@ -4529,6 +4529,9 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
sdk_ui_rules: config.sdk_ui_rules,
payment_link_ui_rules: config.payment_link_ui_rules,
enable_button_only_on_form_ready: config.enable_button_only_on_form_ready,
payment_form_header_text: config.payment_form_header_text,
payment_form_label_type: config.payment_form_label_type,
show_card_terms: config.show_card_terms,
}
}
}
@ -4600,6 +4603,9 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
sdk_ui_rules: config.sdk_ui_rules,
payment_link_ui_rules: config.payment_link_ui_rules,
enable_button_only_on_form_ready: config.enable_button_only_on_form_ready,
payment_form_header_text: config.payment_form_header_text,
payment_form_label_type: config.payment_form_label_type,
show_card_terms: config.show_card_terms,
}
}
}

View File

@ -152,7 +152,7 @@ pub async fn customers_list(
let flow = Flow::CustomersList;
let payload = query.into_inner();
api::server_wrap(
Box::pin(api::server_wrap(
flow,
state,
&req,
@ -174,7 +174,7 @@ pub async fn customers_list(
req.headers(),
),
api_locking::LockAction::NotApplicable,
)
))
.await
}
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]

View File

@ -2188,6 +2188,9 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
sdk_ui_rules: item.sdk_ui_rules,
payment_link_ui_rules: item.payment_link_ui_rules,
enable_button_only_on_form_ready: item.enable_button_only_on_form_ready,
payment_form_header_text: item.payment_form_header_text,
payment_form_label_type: item.payment_form_label_type,
show_card_terms: item.show_card_terms,
}
}
}
@ -2219,6 +2222,9 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
sdk_ui_rules: item.sdk_ui_rules,
payment_link_ui_rules: item.payment_link_ui_rules,
enable_button_only_on_form_ready: item.enable_button_only_on_form_ready,
payment_form_header_text: item.payment_form_header_text,
payment_form_label_type: item.payment_form_label_type,
show_card_terms: item.show_card_terms,
}
}
}