Skip to content
New issue

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

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

Already on GitHub? # to your account

refactor(business_profile): use concrete types for JSON fields #5531

Merged
merged 11 commits into from
Aug 7, 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
6 changes: 5 additions & 1 deletion api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -7265,7 +7265,11 @@
"nullable": true
},
"payment_link_config": {
"description": "Default Payment Link config for all payment links created under this business profile",
"allOf": [
{
"$ref": "#/components/schemas/BusinessPaymentLinkConfig"
}
],
"nullable": true
},
"authentication_connector_details": {
Expand Down
20 changes: 5 additions & 15 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,6 @@ impl MerchantAccountCreate {
.transpose()
}

pub fn get_webhook_details_as_value(
&self,
) -> CustomResult<Option<serde_json::Value>, errors::ParsingError> {
self.webhook_details
.as_ref()
.map(|webhook_details| webhook_details.encode_to_value())
.transpose()
}

pub fn parse_routing_algorithm(&self) -> CustomResult<(), errors::ParsingError> {
match self.routing_algorithm {
Some(ref routing_algorithm) => {
Expand Down Expand Up @@ -248,7 +239,7 @@ impl MerchantAccountCreate {
pub struct AuthenticationConnectorDetails {
/// List of authentication connectors
#[schema(value_type = Vec<AuthenticationConnectors>)]
pub authentication_connectors: Vec<api_enums::AuthenticationConnectors>,
pub authentication_connectors: Vec<common_enums::AuthenticationConnectors>,
/// URL of the (customer service) website that will be shown to the shopper in case of technical errors during the 3D Secure 2 process.
pub three_ds_requestor_url: String,
}
Expand Down Expand Up @@ -483,8 +474,7 @@ pub struct MerchantAccountResponse {
pub merchant_details: Option<Encryptable<pii::SecretSerdeValue>>,

/// Webhook related details
#[schema(value_type = Option<WebhookDetails>)]
pub webhook_details: Option<serde_json::Value>,
pub webhook_details: Option<WebhookDetails>,

/// The routing algorithm to be used to process the incoming request from merchant to outgoing payment processor or payment method. The default is 'Custom'
#[serde(skip)]
Expand Down Expand Up @@ -1948,8 +1938,7 @@ pub struct BusinessProfileResponse {
pub redirect_to_merchant_with_http_post: bool,

/// Webhook related details
#[schema(value_type = Option<WebhookDetails>)]
pub webhook_details: Option<pii::SecretSerdeValue>,
pub webhook_details: Option<WebhookDetails>,

/// Metadata is useful for storing additional, unstructured information on an object.
#[schema(value_type = Option<Object>, example = r#"{ "city": "NY", "unit": "245" }"#)]
Expand Down Expand Up @@ -1980,7 +1969,8 @@ pub struct BusinessProfileResponse {
pub session_expiry: Option<i64>,

/// Default Payment Link config for all payment links created under this business profile
pub payment_link_config: Option<serde_json::Value>,
#[schema(value_type = Option<BusinessPaymentLinkConfig>)]
pub payment_link_config: Option<BusinessPaymentLinkConfig>,

/// External 3DS authentication details
pub authentication_connector_details: Option<AuthenticationConnectorDetails>,
Expand Down
30 changes: 0 additions & 30 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,36 +303,6 @@ impl Connector {
}
}

#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AuthenticationConnectors {
Threedsecureio,
Netcetera,
Gpayments,
}

impl AuthenticationConnectors {
pub fn is_separate_version_call_required(&self) -> bool {
match self {
Self::Threedsecureio | Self::Netcetera => false,
Self::Gpayments => true,
}
}
}

#[cfg(feature = "payouts")]
#[derive(
Clone,
Expand Down
30 changes: 30 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2517,6 +2517,36 @@ pub enum ReconStatus {
Disabled,
}

#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AuthenticationConnectors {
Threedsecureio,
Netcetera,
Gpayments,
}

impl AuthenticationConnectors {
pub fn is_separate_version_call_required(&self) -> bool {
match self {
Self::Threedsecureio | Self::Netcetera => false,
Self::Gpayments => true,
}
}
}

#[derive(
Clone,
Debug,
Expand Down
3 changes: 2 additions & 1 deletion crates/common_enums/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod enums;
pub use enums::*;
pub mod transformers;

pub use enums::*;
pub use transformers::*;
Loading
Loading