Skip to content

Commit 075dcce

Browse files
cookieg13hyperswitch-bot[bot]
authored andcommitted
feat(payments): [Payment links] add configs for payment link (#7340)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent c6f9c13 commit 075dcce

File tree

11 files changed

+153
-4
lines changed

11 files changed

+153
-4
lines changed

api-reference-v2/openapi_spec.json

+30
Original file line numberDiff line numberDiff line change
@@ -13862,6 +13862,21 @@
1386213862
"type": "string",
1386313863
"description": "Custom background colour for payment link's handle confirm button",
1386413864
"nullable": true
13865+
},
13866+
"skip_status_screen": {
13867+
"type": "boolean",
13868+
"description": "Skip the status screen after payment completion",
13869+
"nullable": true
13870+
},
13871+
"payment_button_text_colour": {
13872+
"type": "string",
13873+
"description": "Custom text colour for payment link's handle confirm button",
13874+
"nullable": true
13875+
},
13876+
"background_colour": {
13877+
"type": "string",
13878+
"description": "Custom background colour for the payment link",
13879+
"nullable": true
1386513880
}
1386613881
}
1386713882
},
@@ -13962,6 +13977,21 @@
1396213977
"type": "string",
1396313978
"description": "Custom background colour for payment link's handle confirm button",
1396413979
"nullable": true
13980+
},
13981+
"skip_status_screen": {
13982+
"type": "boolean",
13983+
"description": "Skip the status screen after payment completion",
13984+
"nullable": true
13985+
},
13986+
"payment_button_text_colour": {
13987+
"type": "string",
13988+
"description": "Custom text colour for payment link's handle confirm button",
13989+
"nullable": true
13990+
},
13991+
"background_colour": {
13992+
"type": "string",
13993+
"description": "Custom background colour for the payment link",
13994+
"nullable": true
1396513995
}
1396613996
}
1396713997
},

api-reference/openapi_spec.json

+30
Original file line numberDiff line numberDiff line change
@@ -16502,6 +16502,21 @@
1650216502
"type": "string",
1650316503
"description": "Custom background colour for payment link's handle confirm button",
1650416504
"nullable": true
16505+
},
16506+
"skip_status_screen": {
16507+
"type": "boolean",
16508+
"description": "Skip the status screen after payment completion",
16509+
"nullable": true
16510+
},
16511+
"payment_button_text_colour": {
16512+
"type": "string",
16513+
"description": "Custom text colour for payment link's handle confirm button",
16514+
"nullable": true
16515+
},
16516+
"background_colour": {
16517+
"type": "string",
16518+
"description": "Custom background colour for the payment link",
16519+
"nullable": true
1650516520
}
1650616521
}
1650716522
},
@@ -16602,6 +16617,21 @@
1660216617
"type": "string",
1660316618
"description": "Custom background colour for payment link's handle confirm button",
1660416619
"nullable": true
16620+
},
16621+
"skip_status_screen": {
16622+
"type": "boolean",
16623+
"description": "Skip the status screen after payment completion",
16624+
"nullable": true
16625+
},
16626+
"payment_button_text_colour": {
16627+
"type": "string",
16628+
"description": "Custom text colour for payment link's handle confirm button",
16629+
"nullable": true
16630+
},
16631+
"background_colour": {
16632+
"type": "string",
16633+
"description": "Custom background colour for the payment link",
16634+
"nullable": true
1660516635
}
1660616636
}
1660716637
},

crates/api_models/src/admin.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2786,6 +2786,12 @@ pub struct PaymentLinkConfigRequest {
27862786
pub custom_message_for_card_terms: Option<String>,
27872787
/// Custom background colour for payment link's handle confirm button
27882788
pub payment_button_colour: Option<String>,
2789+
/// Skip the status screen after payment completion
2790+
pub skip_status_screen: Option<bool>,
2791+
/// Custom text colour for payment link's handle confirm button
2792+
pub payment_button_text_colour: Option<String>,
2793+
/// Custom background colour for the payment link
2794+
pub background_colour: Option<String>,
27892795
}
27902796

27912797
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
@@ -2861,6 +2867,12 @@ pub struct PaymentLinkConfig {
28612867
pub custom_message_for_card_terms: Option<String>,
28622868
/// Custom background colour for payment link's handle confirm button
28632869
pub payment_button_colour: Option<String>,
2870+
/// Skip the status screen after payment completion
2871+
pub skip_status_screen: Option<bool>,
2872+
/// Custom text colour for payment link's handle confirm button
2873+
pub payment_button_text_colour: Option<String>,
2874+
/// Custom background colour for the payment link
2875+
pub background_colour: Option<String>,
28642876
}
28652877

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

crates/api_models/src/payments.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7894,8 +7894,11 @@ pub struct PaymentLinkDetails {
78947894
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
78957895
pub branding_visibility: Option<bool>,
78967896
pub payment_button_text: Option<String>,
7897+
pub skip_status_screen: Option<bool>,
78977898
pub custom_message_for_card_terms: Option<String>,
78987899
pub payment_button_colour: Option<String>,
7900+
pub payment_button_text_colour: Option<String>,
7901+
pub background_colour: Option<String>,
78997902
}
79007903

79017904
#[derive(Debug, serde::Serialize, Clone)]
@@ -7906,8 +7909,11 @@ pub struct SecurePaymentLinkDetails {
79067909
#[serde(flatten)]
79077910
pub payment_link_details: PaymentLinkDetails,
79087911
pub payment_button_text: Option<String>,
7912+
pub skip_status_screen: Option<bool>,
79097913
pub custom_message_for_card_terms: Option<String>,
79107914
pub payment_button_colour: Option<String>,
7915+
pub payment_button_text_colour: Option<String>,
7916+
pub background_colour: Option<String>,
79117917
}
79127918

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

crates/diesel_models/src/business_profile.rs

+3
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ pub struct PaymentLinkConfigRequest {
629629
pub payment_button_text: Option<String>,
630630
pub custom_message_for_card_terms: Option<String>,
631631
pub payment_button_colour: Option<String>,
632+
pub skip_status_screen: Option<bool>,
633+
pub payment_button_text_colour: Option<String>,
634+
pub background_colour: Option<String>,
632635
}
633636

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

crates/diesel_models/src/payment_intent.rs

+6
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,16 @@ pub struct PaymentLinkConfigRequestForPayments {
177177
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
178178
/// Text for payment link's handle confirm button
179179
pub payment_button_text: Option<String>,
180+
/// Skip the status screen after payment completion
181+
pub skip_status_screen: Option<bool>,
180182
/// Text for customizing message for card terms
181183
pub custom_message_for_card_terms: Option<String>,
182184
/// Custom background colour for payment link's handle confirm button
183185
pub payment_button_colour: Option<String>,
186+
/// Custom text colour for payment link's handle confirm button
187+
pub payment_button_text_colour: Option<String>,
188+
/// Custom background colour for the payment link
189+
pub background_colour: Option<String>,
184190
}
185191

186192
common_utils::impl_to_sql_from_sql_json!(PaymentLinkConfigRequestForPayments);

crates/hyperswitch_domain_models/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
409409
payment_button_text: item.payment_button_text,
410410
custom_message_for_card_terms: item.custom_message_for_card_terms,
411411
payment_button_colour: item.payment_button_colour,
412+
skip_status_screen: item.skip_status_screen,
413+
background_colour: item.background_colour,
414+
payment_button_text_colour: item.payment_button_text_colour,
412415
}
413416
}
414417
fn convert_back(self) -> api_models::admin::PaymentLinkConfigRequest {
@@ -427,6 +430,9 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
427430
payment_button_text,
428431
custom_message_for_card_terms,
429432
payment_button_colour,
433+
skip_status_screen,
434+
background_colour,
435+
payment_button_text_colour,
430436
} = self;
431437
api_models::admin::PaymentLinkConfigRequest {
432438
theme,
@@ -449,6 +455,9 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
449455
payment_button_text,
450456
custom_message_for_card_terms,
451457
payment_button_colour,
458+
skip_status_screen,
459+
background_colour,
460+
payment_button_text_colour,
452461
}
453462
}
454463
}

crates/router/src/core/payment_link.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ pub async fn form_payment_link_data(
132132
payment_button_text: None,
133133
custom_message_for_card_terms: None,
134134
payment_button_colour: None,
135+
skip_status_screen: None,
136+
background_colour: None,
137+
payment_button_text_colour: None,
135138
}
136139
};
137140

@@ -280,6 +283,9 @@ pub async fn form_payment_link_data(
280283
payment_button_text: payment_link_config.payment_button_text.clone(),
281284
custom_message_for_card_terms: payment_link_config.custom_message_for_card_terms.clone(),
282285
payment_button_colour: payment_link_config.payment_button_colour.clone(),
286+
skip_status_screen: payment_link_config.skip_status_screen,
287+
background_colour: payment_link_config.background_colour.clone(),
288+
payment_button_text_colour: payment_link_config.payment_button_text_colour.clone(),
283289
};
284290

285291
Ok((
@@ -333,6 +339,9 @@ pub async fn initiate_secure_payment_link_flow(
333339
payment_button_text: payment_link_config.payment_button_text,
334340
custom_message_for_card_terms: payment_link_config.custom_message_for_card_terms,
335341
payment_button_colour: payment_link_config.payment_button_colour,
342+
skip_status_screen: payment_link_config.skip_status_screen,
343+
background_colour: payment_link_config.background_colour,
344+
payment_button_text_colour: payment_link_config.payment_button_text_colour,
336345
};
337346
let js_script = format!(
338347
"window.__PAYMENT_DETAILS = {}",
@@ -444,7 +453,10 @@ fn get_js_script(payment_details: &PaymentLinkData) -> RouterResult<String> {
444453
}
445454

446455
fn get_color_scheme_css(payment_link_config: &PaymentLinkConfig) -> String {
447-
let background_primary_color = payment_link_config.theme.clone();
456+
let background_primary_color = payment_link_config
457+
.background_colour
458+
.clone()
459+
.unwrap_or(payment_link_config.theme.clone());
448460
format!(
449461
":root {{
450462
--primary-color: {background_primary_color};
@@ -638,6 +650,9 @@ pub fn get_payment_link_config_based_on_priority(
638650
payment_button_text,
639651
custom_message_for_card_terms,
640652
payment_button_colour,
653+
skip_status_screen,
654+
background_colour,
655+
payment_button_text_colour,
641656
) = get_payment_link_config_value!(
642657
payment_create_link_config,
643658
business_theme_configs,
@@ -647,6 +662,9 @@ pub fn get_payment_link_config_based_on_priority(
647662
(payment_button_text),
648663
(custom_message_for_card_terms),
649664
(payment_button_colour),
665+
(skip_status_screen),
666+
(background_colour),
667+
(payment_button_text_colour)
650668
);
651669

652670
let payment_link_config =
@@ -661,6 +679,7 @@ pub fn get_payment_link_config_based_on_priority(
661679
show_card_form_by_default,
662680
allowed_domains,
663681
branding_visibility,
682+
skip_status_screen,
664683
transaction_details: payment_create_link_config.as_ref().and_then(
665684
|payment_link_config| payment_link_config.theme_config.transaction_details.clone(),
666685
),
@@ -669,6 +688,8 @@ pub fn get_payment_link_config_based_on_priority(
669688
payment_button_text,
670689
custom_message_for_card_terms,
671690
payment_button_colour,
691+
background_colour,
692+
payment_button_text_colour,
672693
};
673694

674695
Ok((payment_link_config, domain_name))
@@ -774,6 +795,9 @@ pub async fn get_payment_link_status(
774795
payment_button_text: None,
775796
custom_message_for_card_terms: None,
776797
payment_button_colour: None,
798+
skip_status_screen: None,
799+
background_colour: None,
800+
payment_button_text_colour: None,
777801
}
778802
};
779803

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

+20-3
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ function initializeEventListeners(paymentDetails) {
307307
}
308308

309309
if (submitButtonNode instanceof HTMLButtonElement) {
310-
submitButtonNode.style.color = contrastBWColor;
311-
submitButtonNode.style.backgroundColor = paymentDetails.payment_button_colour || primaryColor;
310+
var chosenColor = paymentDetails.payment_button_colour || primaryColor;
311+
submitButtonNode.style.color = paymentDetails.payment_button_text_colour || invert(chosenColor, true);
312+
submitButtonNode.style.backgroundColor = chosenColor;
312313
}
313314

314315
if (hyperCheckoutCartImageNode instanceof HTMLDivElement) {
@@ -442,9 +443,25 @@ function handleSubmit(e) {
442443
} else {
443444
showMessage(translations.unexpectedError);
444445
}
446+
} else if (paymentDetails.skip_status_screen) {
447+
// Form query params
448+
var queryParams = {
449+
payment_id: paymentDetails.payment_id,
450+
status: result.status
451+
};
452+
var url = new URL(paymentDetails.return_url);
453+
var params = new URLSearchParams(url.search);
454+
// Attach query params to return_url
455+
for (var key in queryParams) {
456+
if (queryParams.hasOwnProperty(key)) {
457+
params.set(key, queryParams[key]);
458+
}
459+
}
460+
url.search = params.toString();
461+
window.top.location.href = url.toString();
445462
} else {
446463
redirectToStatus();
447-
}
464+
}
448465
})
449466
.catch(function (error) {
450467
console.error("Error confirming payment_intent", error);

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

+6
Original file line numberDiff line numberDiff line change
@@ -4376,6 +4376,9 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
43764376
payment_button_text: config.payment_button_text,
43774377
custom_message_for_card_terms: config.custom_message_for_card_terms,
43784378
payment_button_colour: config.payment_button_colour,
4379+
skip_status_screen: config.skip_status_screen,
4380+
background_colour: config.background_colour,
4381+
payment_button_text_colour: config.payment_button_text_colour,
43794382
}
43804383
}
43814384
}
@@ -4441,6 +4444,9 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
44414444
payment_button_text: config.payment_button_text,
44424445
custom_message_for_card_terms: config.custom_message_for_card_terms,
44434446
payment_button_colour: config.payment_button_colour,
4447+
skip_status_screen: config.skip_status_screen,
4448+
background_colour: config.background_colour,
4449+
payment_button_text_colour: config.payment_button_text_colour,
44444450
}
44454451
}
44464452
}

crates/router/src/types/transformers.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2155,8 +2155,11 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
21552155
.background_image
21562156
.map(|background_image| background_image.foreign_into()),
21572157
payment_button_text: item.payment_button_text,
2158+
skip_status_screen: item.skip_status_screen,
21582159
custom_message_for_card_terms: item.custom_message_for_card_terms,
21592160
payment_button_colour: item.payment_button_colour,
2161+
background_colour: item.background_colour,
2162+
payment_button_text_colour: item.payment_button_text_colour,
21602163
}
21612164
}
21622165
}
@@ -2180,8 +2183,11 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
21802183
.background_image
21812184
.map(|background_image| background_image.foreign_into()),
21822185
payment_button_text: item.payment_button_text,
2186+
skip_status_screen: item.skip_status_screen,
21832187
custom_message_for_card_terms: item.custom_message_for_card_terms,
21842188
payment_button_colour: item.payment_button_colour,
2189+
background_colour: item.background_colour,
2190+
payment_button_text_colour: item.payment_button_text_colour,
21852191
}
21862192
}
21872193
}

0 commit comments

Comments
 (0)