Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(payments): [Payment links] add configs for payment link #7340

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13384,6 +13384,11 @@
"type": "string",
"description": "Custom background colour for payment link's handle confirm button",
"nullable": true
},
"display_status_screen": {
"type": "boolean",
"description": "Display the status screen after payment completion",
"nullable": true
}
}
},
Expand Down Expand Up @@ -13484,6 +13489,11 @@
"type": "string",
"description": "Custom background colour for payment link's handle confirm button",
"nullable": true
},
"display_status_screen": {
"type": "boolean",
"description": "Display the status screen after payment completion",
"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 @@ -16440,6 +16440,11 @@
"type": "string",
"description": "Custom background colour for payment link's handle confirm button",
"nullable": true
},
"display_status_screen": {
"type": "boolean",
"description": "Display the status screen after payment completion",
"nullable": true
}
}
},
Expand Down Expand Up @@ -16540,6 +16545,11 @@
"type": "string",
"description": "Custom background colour for payment link's handle confirm button",
"nullable": true
},
"display_status_screen": {
"type": "boolean",
"description": "Display the status screen after payment completion",
"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 @@ -2723,6 +2723,8 @@ pub struct PaymentLinkConfigRequest {
pub custom_message_for_card_terms: Option<String>,
/// Custom background colour for payment link's handle confirm button
pub payment_button_colour: Option<String>,
/// Display the status screen after payment completion
pub display_status_screen: Option<bool>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
Expand Down Expand Up @@ -2798,6 +2800,8 @@ pub struct PaymentLinkConfig {
pub custom_message_for_card_terms: Option<String>,
/// Custom background colour for payment link's handle confirm button
pub payment_button_colour: Option<String>,
/// Display the status screen after payment completion
pub display_status_screen: Option<bool>,
}

#[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 @@ -7561,6 +7561,7 @@ pub struct PaymentLinkDetails {
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
pub branding_visibility: Option<bool>,
pub payment_button_text: Option<String>,
pub display_status_screen: Option<bool>,
pub custom_message_for_card_terms: Option<String>,
pub payment_button_colour: Option<String>,
}
Expand All @@ -7573,6 +7574,7 @@ pub struct SecurePaymentLinkDetails {
#[serde(flatten)]
pub payment_link_details: PaymentLinkDetails,
pub payment_button_text: Option<String>,
pub display_status_screen: Option<bool>,
pub custom_message_for_card_terms: Option<String>,
pub payment_button_colour: Option<String>,
}
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 @@ -593,6 +593,7 @@ pub struct PaymentLinkConfigRequest {
pub payment_button_text: Option<String>,
pub custom_message_for_card_terms: Option<String>,
pub payment_button_colour: Option<String>,
pub display_status_screen: Option<bool>,
}

#[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 @@ -177,6 +177,8 @@ pub struct PaymentLinkConfigRequestForPayments {
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
/// Text for payment link's handle confirm button
pub payment_button_text: Option<String>,
/// Display the status screen after payment completion
pub display_status_screen: Option<bool>,
/// Text for customizing message for card terms
pub custom_message_for_card_terms: Option<String>,
/// Custom background colour for payment link's handle confirm button
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 @@ -406,6 +406,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
payment_button_text: item.payment_button_text,
custom_message_for_card_terms: item.custom_message_for_card_terms,
payment_button_colour: item.payment_button_colour,
display_status_screen: item.display_status_screen,
}
}
fn convert_back(self) -> api_models::admin::PaymentLinkConfigRequest {
Expand All @@ -424,6 +425,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
payment_button_text,
custom_message_for_card_terms,
payment_button_colour,
display_status_screen,
} = self;
api_models::admin::PaymentLinkConfigRequest {
theme,
Expand All @@ -446,6 +448,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
payment_button_text,
custom_message_for_card_terms,
payment_button_colour,
display_status_screen,
}
}
}
Expand Down
7 changes: 7 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(
payment_button_text: None,
custom_message_for_card_terms: None,
payment_button_colour: None,
display_status_screen: None,
}
};

Expand Down Expand Up @@ -280,6 +281,7 @@ pub async fn form_payment_link_data(
payment_button_text: payment_link_config.payment_button_text.clone(),
custom_message_for_card_terms: payment_link_config.custom_message_for_card_terms.clone(),
payment_button_colour: payment_link_config.payment_button_colour.clone(),
display_status_screen: payment_link_config.display_status_screen,
};

Ok((
Expand Down Expand Up @@ -333,6 +335,7 @@ pub async fn initiate_secure_payment_link_flow(
payment_button_text: payment_link_config.payment_button_text,
custom_message_for_card_terms: payment_link_config.custom_message_for_card_terms,
payment_button_colour: payment_link_config.payment_button_colour,
display_status_screen: payment_link_config.display_status_screen,
};
let js_script = format!(
"window.__PAYMENT_DETAILS = {}",
Expand Down Expand Up @@ -638,6 +641,7 @@ pub fn get_payment_link_config_based_on_priority(
payment_button_text,
custom_message_for_card_terms,
payment_button_colour,
display_status_screen,
) = get_payment_link_config_value!(
payment_create_link_config,
business_theme_configs,
Expand All @@ -647,6 +651,7 @@ pub fn get_payment_link_config_based_on_priority(
(payment_button_text),
(custom_message_for_card_terms),
(payment_button_colour),
(display_status_screen)
);

let payment_link_config =
Expand All @@ -661,6 +666,7 @@ pub fn get_payment_link_config_based_on_priority(
show_card_form_by_default,
allowed_domains,
branding_visibility,
display_status_screen,
transaction_details: payment_create_link_config.as_ref().and_then(
|payment_link_config| payment_link_config.theme_config.transaction_details.clone(),
),
Expand Down Expand Up @@ -774,6 +780,7 @@ pub async fn get_payment_link_status(
payment_button_text: None,
custom_message_for_card_terms: None,
payment_button_colour: None,
display_status_screen: None,
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,25 @@ function handleSubmit(e) {
} else {
showMessage(translations.unexpectedError);
}
} else {
} else if (paymentDetails.display_status_screen) {
redirectToStatus();
}
} else {
// Form query params
var queryParams = {
payment_id: paymentDetails.payment_id,
status: paymentDetails.status,
};
var url = new URL(paymentDetails.return_url);
var params = new URLSearchParams(url.search);
// Attach query params to return_url
for (var key in queryParams) {
if (queryParams.hasOwnProperty(key)) {
params.set(key, queryParams[key]);
}
}
url.search = params.toString();
window.top.location.href = url.toString();
}
})
.catch(function (error) {
console.error("Error confirming payment_intent", error);
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 @@ -4307,6 +4307,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
payment_button_text: config.payment_button_text,
custom_message_for_card_terms: config.custom_message_for_card_terms,
payment_button_colour: config.payment_button_colour,
display_status_screen: config.display_status_screen,
}
}
}
Expand Down Expand Up @@ -4372,6 +4373,7 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
payment_button_text: config.payment_button_text,
custom_message_for_card_terms: config.custom_message_for_card_terms,
payment_button_colour: config.payment_button_colour,
display_status_screen: config.display_status_screen,
}
}
}
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 @@ -2105,6 +2105,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
.background_image
.map(|background_image| background_image.foreign_into()),
payment_button_text: item.payment_button_text,
display_status_screen: item.display_status_screen,
custom_message_for_card_terms: item.custom_message_for_card_terms,
payment_button_colour: item.payment_button_colour,
}
Expand All @@ -2130,6 +2131,7 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
.background_image
.map(|background_image| background_image.foreign_into()),
payment_button_text: item.payment_button_text,
display_status_screen: item.display_status_screen,
custom_message_for_card_terms: item.custom_message_for_card_terms,
payment_button_colour: item.payment_button_colour,
}
Expand Down
Loading