Skip to content

Commit 46aad50

Browse files
feat(payments): [Payment links] Add config for changing button text for payment links (#6860)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 092c79e commit 46aad50

File tree

11 files changed

+53
-1
lines changed

11 files changed

+53
-1
lines changed

api-reference-v2/openapi_spec.json

+10
Original file line numberDiff line numberDiff line change
@@ -12781,6 +12781,11 @@
1278112781
"type": "boolean",
1278212782
"description": "Toggle for HyperSwitch branding visibility",
1278312783
"nullable": true
12784+
},
12785+
"payment_button_text": {
12786+
"type": "string",
12787+
"description": "Text for payment link's handle confirm button",
12788+
"nullable": true
1278412789
}
1278512790
}
1278612791
},
@@ -12866,6 +12871,11 @@
1286612871
}
1286712872
],
1286812873
"nullable": true
12874+
},
12875+
"payment_button_text": {
12876+
"type": "string",
12877+
"description": "Text for payment link's handle confirm button",
12878+
"nullable": true
1286912879
}
1287012880
}
1287112881
},

api-reference/openapi_spec.json

+10
Original file line numberDiff line numberDiff line change
@@ -15652,6 +15652,11 @@
1565215652
"type": "boolean",
1565315653
"description": "Toggle for HyperSwitch branding visibility",
1565415654
"nullable": true
15655+
},
15656+
"payment_button_text": {
15657+
"type": "string",
15658+
"description": "Text for payment link's handle confirm button",
15659+
"nullable": true
1565515660
}
1565615661
}
1565715662
},
@@ -15737,6 +15742,11 @@
1573715742
}
1573815743
],
1573915744
"nullable": true
15745+
},
15746+
"payment_button_text": {
15747+
"type": "string",
15748+
"description": "Text for payment link's handle confirm button",
15749+
"nullable": true
1574015750
}
1574115751
}
1574215752
},

crates/api_models/src/admin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2769,6 +2769,8 @@ pub struct PaymentLinkConfigRequest {
27692769
/// Custom layout for details section
27702770
#[schema(value_type = Option<PaymentLinkDetailsLayout>, example = "layout1")]
27712771
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
2772+
/// Text for payment link's handle confirm button
2773+
pub payment_button_text: Option<String>,
27722774
}
27732775

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

28432847
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]

crates/api_models/src/payments.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6853,6 +6853,7 @@ pub struct PaymentLinkDetails {
68536853
pub background_image: Option<admin::PaymentLinkBackgroundImageConfig>,
68546854
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
68556855
pub branding_visibility: Option<bool>,
6856+
pub payment_button_text: Option<String>,
68566857
}
68576858

68586859
#[derive(Debug, serde::Serialize, Clone)]
@@ -6862,6 +6863,7 @@ pub struct SecurePaymentLinkDetails {
68626863
pub show_card_form_by_default: bool,
68636864
#[serde(flatten)]
68646865
pub payment_link_details: PaymentLinkDetails,
6866+
pub payment_button_text: Option<String>,
68656867
}
68666868

68676869
#[derive(Debug, serde::Serialize)]

crates/diesel_models/src/business_profile.rs

+1
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ pub struct PaymentLinkConfigRequest {
571571
pub show_card_form_by_default: Option<bool>,
572572
pub background_image: Option<PaymentLinkBackgroundImageConfig>,
573573
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
574+
pub payment_button_text: Option<String>,
574575
}
575576

576577
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq)]

crates/diesel_models/src/payment_intent.rs

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ pub struct PaymentLinkConfigRequestForPayments {
167167
pub background_image: Option<PaymentLinkBackgroundImageConfig>,
168168
/// Custom layout for details section
169169
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
170+
/// Text for payment link's handle confirm button
171+
pub payment_button_text: Option<String>,
170172
}
171173

172174
common_utils::impl_to_sql_from_sql_json!(PaymentLinkConfigRequestForPayments);

crates/hyperswitch_domain_models/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
217217
background_image,
218218
)
219219
}),
220+
payment_button_text: item.payment_button_text,
220221
}
221222
}
222223
fn convert_back(self) -> api_models::admin::PaymentLinkConfigRequest {
@@ -232,6 +233,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
232233
transaction_details,
233234
background_image,
234235
details_layout,
236+
payment_button_text,
235237
} = self;
236238
api_models::admin::PaymentLinkConfigRequest {
237239
theme,
@@ -251,6 +253,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
251253
}),
252254
background_image: background_image
253255
.map(|background_image| background_image.convert_back()),
256+
payment_button_text,
254257
}
255258
}
256259
}

crates/router/src/core/payment_link.rs

+16
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub async fn form_payment_link_data(
132132
background_image: None,
133133
details_layout: None,
134134
branding_visibility: None,
135+
payment_button_text: None,
135136
}
136137
};
137138

@@ -277,6 +278,7 @@ pub async fn form_payment_link_data(
277278
background_image: payment_link_config.background_image.clone(),
278279
details_layout: payment_link_config.details_layout,
279280
branding_visibility: payment_link_config.branding_visibility,
281+
payment_button_text: payment_link_config.payment_button_text.clone(),
280282
};
281283

282284
Ok((
@@ -335,6 +337,7 @@ pub async fn initiate_secure_payment_link_flow(
335337
hide_card_nickname_field: payment_link_config.hide_card_nickname_field,
336338
show_card_form_by_default: payment_link_config.show_card_form_by_default,
337339
payment_link_details: *link_details.to_owned(),
340+
payment_button_text: payment_link_config.payment_button_text,
338341
};
339342
let js_script = format!(
340343
"window.__PAYMENT_DETAILS = {}",
@@ -680,6 +683,18 @@ pub fn get_payment_link_config_based_on_priority(
680683
.map(|background_image| background_image.clone().foreign_into())
681684
})
682685
}),
686+
payment_button_text: payment_create_link_config
687+
.as_ref()
688+
.and_then(|payment_link_config| {
689+
payment_link_config.theme_config.payment_button_text.clone()
690+
})
691+
.or_else(|| {
692+
business_theme_configs
693+
.as_ref()
694+
.and_then(|business_theme_config| {
695+
business_theme_config.payment_button_text.clone()
696+
})
697+
}),
683698
};
684699

685700
Ok((payment_link_config, domain_name))
@@ -786,6 +801,7 @@ pub async fn get_payment_link_status(
786801
background_image: None,
787802
details_layout: None,
788803
branding_visibility: None,
804+
payment_button_text: None,
789805
}
790806
};
791807

crates/router/src/core/payment_link/payment_link_initiate/payment_link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function initializeEventListeners(paymentDetails) {
303303
var payNowButtonText = document.createElement("div");
304304
var payNowButtonText = document.getElementById('submit-button-text');
305305
if (payNowButtonText) {
306-
payNowButtonText.textContent = translations.payNow;
306+
payNowButtonText.textContent = paymentDetails.payment_button_text || translations.payNow;
307307
}
308308

309309
if (submitButtonNode instanceof HTMLButtonElement) {

crates/router/src/core/payments/transformers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
36303630
background_image.clone(),
36313631
)
36323632
}),
3633+
payment_button_text: config.payment_button_text,
36333634
}
36343635
}
36353636
}
@@ -3692,6 +3693,7 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
36923693
background_image.clone(),
36933694
)
36943695
}),
3696+
payment_button_text: config.payment_button_text,
36953697
}
36963698
}
36973699
}

crates/router/src/types/transformers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
19671967
background_image: item
19681968
.background_image
19691969
.map(|background_image| background_image.foreign_into()),
1970+
payment_button_text: item.payment_button_text,
19701971
}
19711972
}
19721973
}
@@ -1989,6 +1990,7 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
19891990
background_image: item
19901991
.background_image
19911992
.map(|background_image| background_image.foreign_into()),
1993+
payment_button_text: item.payment_button_text,
19921994
}
19931995
}
19941996
}

0 commit comments

Comments
 (0)