feat(payment_link): add provision for secured payment links (#5357)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
Kashif
2024-07-30 13:12:35 +05:30
committed by GitHub
parent a791391e2a
commit 043abb59b9
31 changed files with 841 additions and 318 deletions

View File

@ -1833,7 +1833,7 @@ impl BusinessGenericLinkConfig {
.map(|host_domain| link_utils::validate_strict_domain(&host_domain))
.unwrap_or(true);
if !host_domain_valid {
return Err("Invalid host domain name received");
return Err("Invalid host domain name received in payout_link_config");
}
let are_allowed_domains_valid = self
@ -1842,7 +1842,7 @@ impl BusinessGenericLinkConfig {
.iter()
.all(|allowed_domain| link_utils::validate_wildcard_domain(allowed_domain));
if !are_allowed_domains_valid {
return Err("Invalid allowed domain names received");
return Err("Invalid allowed domain names received in payout_link_config");
}
Ok(())
@ -1859,6 +1859,37 @@ pub struct BusinessPaymentLinkConfig {
pub default_config: Option<PaymentLinkConfigRequest>,
/// list of configs for multi theme setup
pub business_specific_configs: Option<HashMap<String, PaymentLinkConfigRequest>>,
/// A list of allowed domains (glob patterns) where this link can be embedded / opened from
#[schema(value_type = Option<HashSet<String>>)]
pub allowed_domains: Option<HashSet<String>>,
}
impl BusinessPaymentLinkConfig {
pub fn validate(&self) -> Result<(), &str> {
let host_domain_valid = self
.domain_name
.clone()
.map(|host_domain| link_utils::validate_strict_domain(&host_domain))
.unwrap_or(true);
if !host_domain_valid {
return Err("Invalid host domain name received in payment_link_config");
}
let are_allowed_domains_valid = self
.allowed_domains
.clone()
.map(|allowed_domains| {
allowed_domains
.iter()
.all(|allowed_domain| link_utils::validate_wildcard_domain(allowed_domain))
})
.unwrap_or(true);
if !are_allowed_domains_valid {
return Err("Invalid allowed domain names received in payment_link_config");
}
Ok(())
}
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
@ -1897,6 +1928,8 @@ pub struct PaymentLinkConfig {
pub display_sdk_only: bool,
/// Enable saved payment method option for payment link
pub enabled_saved_payment_method: bool,
/// A list of allowed domains (glob patterns) where this link can be embedded / opened from
pub allowed_domains: Option<HashSet<String>>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]

View File

@ -5337,7 +5337,11 @@ pub struct RetrievePaymentLinkRequest {
#[derive(Clone, Debug, serde::Serialize, PartialEq, ToSchema)]
pub struct PaymentLinkResponse {
/// URL for rendering the open payment link
pub link: String,
/// URL for rendering the secure payment link
pub secure_link: Option<String>,
/// Identifier for the payment link
pub payment_link_id: String,
}
@ -5348,7 +5352,7 @@ pub struct RetrievePaymentLinkResponse {
/// Identifier for Merchant
#[schema(value_type = String)]
pub merchant_id: id_type::MerchantId,
/// Payment Link
/// Open payment link (without any security checks and listing SPMs)
pub link_to_pay: String,
/// The payment amount. Amount for the payment in the lowest denomination of the currency
#[schema(value_type = i64, example = 6540)]
@ -5365,6 +5369,8 @@ pub struct RetrievePaymentLinkResponse {
pub status: PaymentLinkStatus,
#[schema(value_type = Option<Currency>)]
pub currency: Option<api_enums::Currency>,
/// Secure payment link (with security checks and listing saved payment methods)
pub secure_link: Option<String>,
}
#[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)]
@ -5376,8 +5382,8 @@ pub struct PaymentLinkInitiateRequest {
#[derive(Debug, serde::Serialize)]
#[serde(untagged)]
pub enum PaymentLinkData<'a> {
PaymentLinkDetails(&'a PaymentLinkDetails),
pub enum PaymentLinkData {
PaymentLinkDetails(PaymentLinkDetails),
PaymentLinkStatusDetails(PaymentLinkStatusDetails),
}
@ -5399,7 +5405,13 @@ pub struct PaymentLinkDetails {
pub merchant_description: Option<String>,
pub sdk_layout: String,
pub display_sdk_only: bool,
}
#[derive(Debug, serde::Serialize, Clone)]
pub struct SecurePaymentLinkDetails {
pub enabled_saved_payment_method: bool,
#[serde(flatten)]
pub payment_link_details: PaymentLinkDetails,
}
#[derive(Debug, serde::Serialize)]