Skip to content

Commit

Permalink
feat(payments): [Payment links] add showCardFormByDefault config for …
Browse files Browse the repository at this point in the history
…payment links (#6663)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
cookieg13 and hyperswitch-bot[bot] authored Nov 29, 2024
1 parent 19cbcdd commit b1d1073
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 4 deletions.
14 changes: 13 additions & 1 deletion api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -11993,7 +11993,8 @@
"sdk_layout",
"display_sdk_only",
"enabled_saved_payment_method",
"hide_card_nickname_field"
"hide_card_nickname_field",
"show_card_form_by_default"
],
"properties": {
"theme": {
Expand Down Expand Up @@ -12024,6 +12025,10 @@
"type": "boolean",
"description": "Hide card nickname field option for payment link"
},
"show_card_form_by_default": {
"type": "boolean",
"description": "Show card form by default for payment link"
},
"allowed_domains": {
"type": "array",
"items": {
Expand Down Expand Up @@ -12095,6 +12100,13 @@
"example": true,
"nullable": true
},
"show_card_form_by_default": {
"type": "boolean",
"description": "Show card form by default for payment link",
"default": true,
"example": true,
"nullable": true
},
"transaction_details": {
"type": "array",
"items": {
Expand Down
14 changes: 13 additions & 1 deletion api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15170,7 +15170,8 @@
"sdk_layout",
"display_sdk_only",
"enabled_saved_payment_method",
"hide_card_nickname_field"
"hide_card_nickname_field",
"show_card_form_by_default"
],
"properties": {
"theme": {
Expand Down Expand Up @@ -15201,6 +15202,10 @@
"type": "boolean",
"description": "Hide card nickname field option for payment link"
},
"show_card_form_by_default": {
"type": "boolean",
"description": "Show card form by default for payment link"
},
"allowed_domains": {
"type": "array",
"items": {
Expand Down Expand Up @@ -15272,6 +15277,13 @@
"example": true,
"nullable": true
},
"show_card_form_by_default": {
"type": "boolean",
"description": "Show card form by default for payment link",
"default": true,
"example": true,
"nullable": true
},
"transaction_details": {
"type": "array",
"items": {
Expand Down
5 changes: 5 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2673,6 +2673,9 @@ pub struct PaymentLinkConfigRequest {
/// Hide card nickname field option for payment link
#[schema(default = false, example = true)]
pub hide_card_nickname_field: Option<bool>,
/// Show card form by default for payment link
#[schema(default = true, example = true)]
pub show_card_form_by_default: Option<bool>,
/// Dynamic details related to merchant to be rendered in payment link
pub transaction_details: Option<Vec<PaymentLinkTransactionDetails>>,
}
Expand Down Expand Up @@ -2718,6 +2721,8 @@ pub struct PaymentLinkConfig {
pub enabled_saved_payment_method: bool,
/// Hide card nickname field option for payment link
pub hide_card_nickname_field: bool,
/// Show card form by default for payment link
pub show_card_form_by_default: bool,
/// A list of allowed domains (glob patterns) where this link can be embedded / opened from
pub allowed_domains: Option<HashSet<String>>,
/// Dynamic details related to merchant to be rendered in payment link
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6670,6 +6670,7 @@ pub struct PaymentLinkDetails {
pub sdk_layout: String,
pub display_sdk_only: bool,
pub hide_card_nickname_field: bool,
pub show_card_form_by_default: bool,
pub locale: Option<String>,
pub transaction_details: Option<Vec<admin::PaymentLinkTransactionDetails>>,
}
Expand All @@ -6678,6 +6679,7 @@ pub struct PaymentLinkDetails {
pub struct SecurePaymentLinkDetails {
pub enabled_saved_payment_method: bool,
pub hide_card_nickname_field: bool,
pub show_card_form_by_default: bool,
#[serde(flatten)]
pub payment_link_details: PaymentLinkDetails,
}
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ pub struct PaymentLinkConfigRequest {
pub display_sdk_only: Option<bool>,
pub enabled_saved_payment_method: Option<bool>,
pub hide_card_nickname_field: Option<bool>,
pub show_card_form_by_default: Option<bool>,
}

common_utils::impl_to_sql_from_sql_json!(BusinessPaymentLinkConfig);
Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ pub struct PaymentLinkConfigRequestForPayments {
pub enabled_saved_payment_method: Option<bool>,
/// Hide card nickname field option for payment link
pub hide_card_nickname_field: Option<bool>,
/// Show card form by default for payment link
pub show_card_form_by_default: Option<bool>,
/// Dynamic details related to merchant to be rendered in payment link
pub transaction_details: Option<Vec<PaymentLinkTransactionDetails>>,
}
Expand Down
3 changes: 3 additions & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
display_sdk_only: item.display_sdk_only,
enabled_saved_payment_method: item.enabled_saved_payment_method,
hide_card_nickname_field: item.hide_card_nickname_field,
show_card_form_by_default: item.show_card_form_by_default,
transaction_details: item.transaction_details.map(|transaction_details| {
transaction_details
.into_iter()
Expand All @@ -213,6 +214,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
display_sdk_only,
enabled_saved_payment_method,
hide_card_nickname_field,
show_card_form_by_default,
transaction_details,
} = self;
api_models::admin::PaymentLinkConfigRequest {
Expand All @@ -223,6 +225,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
display_sdk_only,
enabled_saved_payment_method,
hide_card_nickname_field,
show_card_form_by_default,
transaction_details: transaction_details.map(|transaction_details| {
transaction_details
.into_iter()
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ pub const DEFAULT_ALLOWED_DOMAINS: Option<HashSet<String>> = None;
/// Default hide card nickname field
pub const DEFAULT_HIDE_CARD_NICKNAME_FIELD: bool = false;

/// Show card form by default for payment links
pub const DEFAULT_SHOW_CARD_FORM: bool = true;

/// Default bool for Display sdk only
pub const DEFAULT_DISPLAY_SDK_ONLY: bool = false;

Expand Down
11 changes: 9 additions & 2 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
consts::{
self, DEFAULT_ALLOWED_DOMAINS, DEFAULT_BACKGROUND_COLOR, DEFAULT_DISPLAY_SDK_ONLY,
DEFAULT_ENABLE_SAVED_PAYMENT_METHOD, DEFAULT_HIDE_CARD_NICKNAME_FIELD,
DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT,
DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT, DEFAULT_SHOW_CARD_FORM,
},
errors::RouterResponse,
get_payment_link_config_value, get_payment_link_config_value_based_on_priority,
Expand Down Expand Up @@ -126,6 +126,7 @@ pub async fn form_payment_link_data(
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
enabled_saved_payment_method: DEFAULT_ENABLE_SAVED_PAYMENT_METHOD,
hide_card_nickname_field: DEFAULT_HIDE_CARD_NICKNAME_FIELD,
show_card_form_by_default: DEFAULT_SHOW_CARD_FORM,
allowed_domains: DEFAULT_ALLOWED_DOMAINS,
transaction_details: None,
}
Expand Down Expand Up @@ -267,6 +268,7 @@ pub async fn form_payment_link_data(
sdk_layout: payment_link_config.sdk_layout.clone(),
display_sdk_only: payment_link_config.display_sdk_only,
hide_card_nickname_field: payment_link_config.hide_card_nickname_field,
show_card_form_by_default: payment_link_config.show_card_form_by_default,
locale,
transaction_details: payment_link_config.transaction_details.clone(),
};
Expand Down Expand Up @@ -325,6 +327,7 @@ pub async fn initiate_secure_payment_link_flow(
let secure_payment_link_details = api_models::payments::SecurePaymentLinkDetails {
enabled_saved_payment_method: payment_link_config.enabled_saved_payment_method,
hide_card_nickname_field: payment_link_config.hide_card_nickname_field,
show_card_form_by_default: payment_link_config.show_card_form_by_default,
payment_link_details: *link_details.to_owned(),
};
let js_script = format!(
Expand Down Expand Up @@ -618,6 +621,7 @@ pub fn get_payment_link_config_based_on_priority(
display_sdk_only,
enabled_saved_payment_method,
hide_card_nickname_field,
show_card_form_by_default,
) = get_payment_link_config_value!(
payment_create_link_config,
business_theme_configs,
Expand All @@ -630,7 +634,8 @@ pub fn get_payment_link_config_based_on_priority(
enabled_saved_payment_method,
DEFAULT_ENABLE_SAVED_PAYMENT_METHOD
),
(hide_card_nickname_field, DEFAULT_HIDE_CARD_NICKNAME_FIELD)
(hide_card_nickname_field, DEFAULT_HIDE_CARD_NICKNAME_FIELD),
(show_card_form_by_default, DEFAULT_SHOW_CARD_FORM)
);
let payment_link_config = PaymentLinkConfig {
theme,
Expand All @@ -640,6 +645,7 @@ pub fn get_payment_link_config_based_on_priority(
display_sdk_only,
enabled_saved_payment_method,
hide_card_nickname_field,
show_card_form_by_default,
allowed_domains,
transaction_details: payment_create_link_config
.and_then(|payment_link_config| payment_link_config.theme_config.transaction_details),
Expand Down Expand Up @@ -743,6 +749,7 @@ pub async fn get_payment_link_status(
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
enabled_saved_payment_method: DEFAULT_ENABLE_SAVED_PAYMENT_METHOD,
hide_card_nickname_field: DEFAULT_HIDE_CARD_NICKNAME_FIELD,
show_card_form_by_default: DEFAULT_SHOW_CARD_FORM,
allowed_domains: DEFAULT_ALLOWED_DOMAINS,
transaction_details: None,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function initializeSDK() {
height: 55,
},
},
showCardFormByDefault: paymentDetails.show_card_form_by_default,
hideCardNicknameField: false,
};
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ if (!isFramed) {
},
},
hideCardNicknameField: hideCardNicknameField,
showCardFormByDefault: paymentDetails.show_card_form_by_default,
};
// @ts-ignore
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3699,6 +3699,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
display_sdk_only: config.display_sdk_only,
enabled_saved_payment_method: config.enabled_saved_payment_method,
hide_card_nickname_field: config.hide_card_nickname_field,
show_card_form_by_default: config.show_card_form_by_default,
transaction_details: config.transaction_details.map(|transaction_details| {
transaction_details
.iter()
Expand Down Expand Up @@ -3752,6 +3753,7 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
display_sdk_only: config.display_sdk_only,
enabled_saved_payment_method: config.enabled_saved_payment_method,
hide_card_nickname_field: config.hide_card_nickname_field,
show_card_form_by_default: config.show_card_form_by_default,
transaction_details: config.transaction_details.map(|transaction_details| {
transaction_details
.iter()
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
display_sdk_only: item.display_sdk_only,
enabled_saved_payment_method: item.enabled_saved_payment_method,
hide_card_nickname_field: item.hide_card_nickname_field,
show_card_form_by_default: item.show_card_form_by_default,
}
}
}
Expand All @@ -1961,6 +1962,7 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
display_sdk_only: item.display_sdk_only,
enabled_saved_payment_method: item.enabled_saved_payment_method,
hide_card_nickname_field: item.hide_card_nickname_field,
show_card_form_by_default: item.show_card_form_by_default,
transaction_details: None,
}
}
Expand Down

0 comments on commit b1d1073

Please sign in to comment.