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: add support for merchant to pass public key and ttl for encrypting payload #4456

Merged
merged 4 commits into from
May 1, 2024
Merged
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
9 changes: 9 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,9 @@ pub struct BusinessProfileUpdate {

/// External 3DS authentication details
pub authentication_connector_details: Option<AuthenticationConnectorDetails>,

/// Merchant's config to support extended card info feature
pub extended_card_info_config: Option<ExtendedCardInfoConfig>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
Expand Down Expand Up @@ -1095,3 +1098,9 @@ pub struct ExtendedCardInfoChoice {
}

impl common_utils::events::ApiEventMetric for ExtendedCardInfoChoice {}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ExtendedCardInfoConfig {
pub public_key: Secret<String>,
pub ttl_in_secs: u16,
}
9 changes: 9 additions & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct BusinessProfile {
pub session_expiry: Option<i64>,
pub authentication_connector_details: Option<serde_json::Value>,
pub is_extended_card_info_enabled: Option<bool>,
pub extended_card_info_config: Option<pii::SecretSerdeValue>,
}

#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
Expand Down Expand Up @@ -63,6 +64,7 @@ pub struct BusinessProfileNew {
pub session_expiry: Option<i64>,
pub authentication_connector_details: Option<serde_json::Value>,
pub is_extended_card_info_enabled: Option<bool>,
pub extended_card_info_config: Option<pii::SecretSerdeValue>,
}

#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
Expand All @@ -87,6 +89,7 @@ pub struct BusinessProfileUpdateInternal {
pub session_expiry: Option<i64>,
pub authentication_connector_details: Option<serde_json::Value>,
pub is_extended_card_info_enabled: Option<bool>,
pub extended_card_info_config: Option<pii::SecretSerdeValue>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
Expand All @@ -109,6 +112,7 @@ pub enum BusinessProfileUpdate {
payment_link_config: Option<serde_json::Value>,
session_expiry: Option<i64>,
authentication_connector_details: Option<serde_json::Value>,
extended_card_info_config: Option<pii::SecretSerdeValue>,
},
ExtendedCardInfoUpdate {
is_extended_card_info_enabled: Option<bool>,
Expand Down Expand Up @@ -136,6 +140,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
payment_link_config,
session_expiry,
authentication_connector_details,
extended_card_info_config,
} => Self {
profile_name,
modified_at,
Expand All @@ -154,6 +159,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
payment_link_config,
session_expiry,
authentication_connector_details,
extended_card_info_config,
..Default::default()
},
BusinessProfileUpdate::ExtendedCardInfoUpdate {
Expand Down Expand Up @@ -190,6 +196,7 @@ impl From<BusinessProfileNew> for BusinessProfile {
session_expiry: new.session_expiry,
authentication_connector_details: new.authentication_connector_details,
is_extended_card_info_enabled: new.is_extended_card_info_enabled,
extended_card_info_config: new.extended_card_info_config,
}
}
}
Expand All @@ -215,6 +222,7 @@ impl BusinessProfileUpdate {
session_expiry,
authentication_connector_details,
is_extended_card_info_enabled,
extended_card_info_config,
} = self.into();
BusinessProfile {
profile_name: profile_name.unwrap_or(source.profile_name),
Expand All @@ -237,6 +245,7 @@ impl BusinessProfileUpdate {
session_expiry,
authentication_connector_details,
is_extended_card_info_enabled,
extended_card_info_config,
..source
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ diesel::table! {
session_expiry -> Nullable<Int8>,
authentication_connector_details -> Nullable<Jsonb>,
is_extended_card_info_enabled -> Nullable<Bool>,
extended_card_info_config -> Nullable<Jsonb>,
}
}

Expand Down
15 changes: 15 additions & 0 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ pub async fn update_business_profile_cascade(
payment_link_config: None,
session_expiry: None,
authentication_connector_details: None,
extended_card_info_config: None,
};

let update_futures = business_profiles.iter().map(|business_profile| async {
Expand Down Expand Up @@ -1648,6 +1649,19 @@ pub async fn update_business_profile(
})
.transpose()?;

let extended_card_info_config = request
.extended_card_info_config
.as_ref()
.map(|config| {
config
.encode_to_value()
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "extended_card_info_config",
})
})
.transpose()?
.map(Secret::new);

let business_profile_update = storage::business_profile::BusinessProfileUpdate::Update {
profile_name: request.profile_name,
modified_at: Some(date_time::now()),
Expand Down Expand Up @@ -1676,6 +1690,7 @@ pub async fn update_business_profile(
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "authentication_connector_details",
})?,
extended_card_info_config,
};

let updated_business_profile = db
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/routing/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ pub async fn update_business_profile_active_algorithm_ref(
payment_link_config: None,
session_expiry: None,
authentication_connector_details: None,
extended_card_info_config: None,
};
db.update_business_profile_by_profile_id(current_business_profile, business_profile_update)
.await
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/types/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl ForeignTryFrom<(domain::MerchantAccount, BusinessProfileCreate)>
field_name: "authentication_connector_details",
})?,
is_extended_card_info_enabled: None,
extended_card_info_config: None,
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`

ALTER TABLE business_profile DROP COLUMN IF EXISTS extended_card_info_config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Your SQL goes here

ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS extended_card_info_config JSONB DEFAULT NULL;
Loading