Skip to content

Commit

Permalink
feat(payments): [Payment links] Add config for changing button text f…
Browse files Browse the repository at this point in the history
…or payment links (#6860)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
cookieg13 and hyperswitch-bot[bot] authored Dec 19, 2024
1 parent 092c79e commit 46aad50
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 1 deletion.
10 changes: 10 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -12781,6 +12781,11 @@
"type": "boolean",
"description": "Toggle for HyperSwitch branding visibility",
"nullable": true
},
"payment_button_text": {
"type": "string",
"description": "Text for payment link's handle confirm button",
"nullable": true
}
}
},
Expand Down Expand Up @@ -12866,6 +12871,11 @@
}
],
"nullable": true
},
"payment_button_text": {
"type": "string",
"description": "Text for payment link's handle confirm button",
"nullable": true
}
}
},
Expand Down
10 changes: 10 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15652,6 +15652,11 @@
"type": "boolean",
"description": "Toggle for HyperSwitch branding visibility",
"nullable": true
},
"payment_button_text": {
"type": "string",
"description": "Text for payment link's handle confirm button",
"nullable": true
}
}
},
Expand Down Expand Up @@ -15737,6 +15742,11 @@
}
],
"nullable": true
},
"payment_button_text": {
"type": "string",
"description": "Text for payment link's handle confirm button",
"nullable": true
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,8 @@ pub struct PaymentLinkConfigRequest {
/// Custom layout for details section
#[schema(value_type = Option<PaymentLinkDetailsLayout>, example = "layout1")]
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
/// Text for payment link's handle confirm button
pub payment_button_text: Option<String>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
Expand Down Expand Up @@ -2838,6 +2840,8 @@ pub struct PaymentLinkConfig {
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
/// Toggle for HyperSwitch branding visibility
pub branding_visibility: Option<bool>,
/// Text for payment link's handle confirm button
pub payment_button_text: Option<String>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
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 @@ -6853,6 +6853,7 @@ pub struct PaymentLinkDetails {
pub background_image: Option<admin::PaymentLinkBackgroundImageConfig>,
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
pub branding_visibility: Option<bool>,
pub payment_button_text: Option<String>,
}

#[derive(Debug, serde::Serialize, Clone)]
Expand All @@ -6862,6 +6863,7 @@ pub struct SecurePaymentLinkDetails {
pub show_card_form_by_default: bool,
#[serde(flatten)]
pub payment_link_details: PaymentLinkDetails,
pub payment_button_text: Option<String>,
}

#[derive(Debug, serde::Serialize)]
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 @@ -571,6 +571,7 @@ pub struct PaymentLinkConfigRequest {
pub show_card_form_by_default: Option<bool>,
pub background_image: Option<PaymentLinkBackgroundImageConfig>,
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
pub payment_button_text: Option<String>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
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 @@ -167,6 +167,8 @@ pub struct PaymentLinkConfigRequestForPayments {
pub background_image: Option<PaymentLinkBackgroundImageConfig>,
/// Custom layout for details section
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
/// Text for payment link's handle confirm button
pub payment_button_text: Option<String>,
}

common_utils::impl_to_sql_from_sql_json!(PaymentLinkConfigRequestForPayments);
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 @@ -217,6 +217,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
background_image,
)
}),
payment_button_text: item.payment_button_text,
}
}
fn convert_back(self) -> api_models::admin::PaymentLinkConfigRequest {
Expand All @@ -232,6 +233,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
transaction_details,
background_image,
details_layout,
payment_button_text,
} = self;
api_models::admin::PaymentLinkConfigRequest {
theme,
Expand All @@ -251,6 +253,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
}),
background_image: background_image
.map(|background_image| background_image.convert_back()),
payment_button_text,
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub async fn form_payment_link_data(
background_image: None,
details_layout: None,
branding_visibility: None,
payment_button_text: None,
}
};

Expand Down Expand Up @@ -277,6 +278,7 @@ pub async fn form_payment_link_data(
background_image: payment_link_config.background_image.clone(),
details_layout: payment_link_config.details_layout,
branding_visibility: payment_link_config.branding_visibility,
payment_button_text: payment_link_config.payment_button_text.clone(),
};

Ok((
Expand Down Expand Up @@ -335,6 +337,7 @@ pub async fn initiate_secure_payment_link_flow(
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(),
payment_button_text: payment_link_config.payment_button_text,
};
let js_script = format!(
"window.__PAYMENT_DETAILS = {}",
Expand Down Expand Up @@ -680,6 +683,18 @@ pub fn get_payment_link_config_based_on_priority(
.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()
})
}),
};

Ok((payment_link_config, domain_name))
Expand Down Expand Up @@ -786,6 +801,7 @@ pub async fn get_payment_link_status(
background_image: None,
details_layout: None,
branding_visibility: None,
payment_button_text: None,
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function initializeEventListeners(paymentDetails) {
var payNowButtonText = document.createElement("div");
var payNowButtonText = document.getElementById('submit-button-text');
if (payNowButtonText) {
payNowButtonText.textContent = translations.payNow;
payNowButtonText.textContent = paymentDetails.payment_button_text || translations.payNow;
}

if (submitButtonNode instanceof HTMLButtonElement) {
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 @@ -3630,6 +3630,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
background_image.clone(),
)
}),
payment_button_text: config.payment_button_text,
}
}
}
Expand Down Expand Up @@ -3692,6 +3693,7 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
background_image.clone(),
)
}),
payment_button_text: config.payment_button_text,
}
}
}
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 @@ -1967,6 +1967,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
background_image: item
.background_image
.map(|background_image| background_image.foreign_into()),
payment_button_text: item.payment_button_text,
}
}
}
Expand All @@ -1989,6 +1990,7 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
background_image: item
.background_image
.map(|background_image| background_image.foreign_into()),
payment_button_text: item.payment_button_text,
}
}
}
Expand Down

0 comments on commit 46aad50

Please sign in to comment.