Skip to content

Commit

Permalink
refactor(FRM): refactor frm configs (#4581)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
srujanchikke and hyperswitch-bot[bot] authored May 17, 2024
1 parent a62f69d commit 853f3b4
Show file tree
Hide file tree
Showing 32 changed files with 137 additions and 148 deletions.
9 changes: 6 additions & 3 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,11 @@ pub struct FrmPaymentMethod {
///payment methods(card, wallet, etc) that can be used in the payment
#[schema(value_type = PaymentMethod,example = "card")]
pub payment_method: Option<common_enums::PaymentMethod>,
///payment method types(credit, debit) that can be used in the payment
pub payment_method_types: Vec<FrmPaymentMethodType>,
///payment method types(credit, debit) that can be used in the payment. This field is deprecated. It has not been removed to provide backward compatibility.
pub payment_method_types: Option<Vec<FrmPaymentMethodType>>,
///frm flow type to be used, can be pre/post
#[schema(value_type = Option<FrmPreferredFlowTypes>)]
pub flow: Option<api_enums::FrmPreferredFlowTypes>,
}

///Details of FrmPaymentMethodType are mentioned here... it should be passed in payment connector create api call, and stored in merchant_connector_table
Expand All @@ -743,7 +746,7 @@ pub struct FrmPaymentMethodType {
///card networks(like visa mastercard) types that can be used in the payment
#[schema(value_type = CardNetwork)]
pub card_networks: Option<Vec<common_enums::CardNetwork>>,
///frm flow type to be used...can be pre/post
///frm flow type to be used, can be pre/post
#[schema(value_type = FrmPreferredFlowTypes)]
pub flow: api_enums::FrmPreferredFlowTypes,
///action that the frm would take, in case fraud is detected
Expand Down
7 changes: 6 additions & 1 deletion crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ pub struct PaymentsRequest {
pub session_expiry: Option<u32>,

/// additional data related to some frm connectors
pub frm_metadata: Option<serde_json::Value>,
#[schema(value_type = Option<Object>, example = r#"{ "coverage_request" : "fraud", "fulfillment_method" : "delivery" }"#)]
pub frm_metadata: Option<pii::SecretSerdeValue>,

/// Whether to perform external authentication (if applicable)
#[schema(example = true)]
Expand Down Expand Up @@ -3410,6 +3411,10 @@ pub struct PaymentsResponse {
#[schema(example = "2022-09-10T10:11:12Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub updated: Option<PrimitiveDateTime>,

/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. FRM Metadata is useful for storing additional, structured information on an object related to FRM.
#[schema(value_type = Option<Object>, example = r#"{ "fulfillment_method" : "deliver", "coverage_request" : "fraud" }"#)]
pub frm_metadata: Option<pii::SecretSerdeValue>,
}

#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
Expand Down
12 changes: 11 additions & 1 deletion crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct PaymentIntent {
pub session_expiry: Option<PrimitiveDateTime>,
pub fingerprint_id: Option<String>,
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
}

#[derive(
Expand Down Expand Up @@ -111,6 +112,7 @@ pub struct PaymentIntentNew {
pub session_expiry: Option<PrimitiveDateTime>,
pub fingerprint_id: Option<String>,
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -167,6 +169,7 @@ pub enum PaymentIntentUpdate {
session_expiry: Option<PrimitiveDateTime>,
fingerprint_id: Option<String>,
request_external_three_ds_authentication: Option<bool>,
frm_metadata: Option<pii::SecretSerdeValue>,
},
PaymentAttemptAndAttemptCountUpdate {
active_attempt_id: String,
Expand Down Expand Up @@ -236,6 +239,7 @@ pub struct PaymentIntentUpdateInternal {
pub session_expiry: Option<PrimitiveDateTime>,
pub fingerprint_id: Option<String>,
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
}

impl PaymentIntentUpdate {
Expand Down Expand Up @@ -271,6 +275,7 @@ impl PaymentIntentUpdate {
session_expiry,
fingerprint_id,
request_external_three_ds_authentication,
frm_metadata,
} = self.into();
PaymentIntent {
amount: amount.unwrap_or(source.amount),
Expand Down Expand Up @@ -308,6 +313,8 @@ impl PaymentIntentUpdate {
session_expiry: session_expiry.or(source.session_expiry),
request_external_three_ds_authentication: request_external_three_ds_authentication
.or(source.request_external_three_ds_authentication),

frm_metadata: frm_metadata.or(source.frm_metadata),
..source
}
}
Expand Down Expand Up @@ -337,6 +344,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
session_expiry,
fingerprint_id,
request_external_three_ds_authentication,
frm_metadata,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand All @@ -359,6 +367,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
session_expiry,
fingerprint_id,
request_external_three_ds_authentication,
frm_metadata,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate {
Expand Down Expand Up @@ -542,7 +551,8 @@ mod tests {
"incremental_authorization_allowed": null,
"authorization_count": null,
"session_expiry": null,
"fingerprint_id": null
"fingerprint_id": null,
"frm_metadata": null
}"#;
let deserialized_payment_intent =
serde_json::from_str::<super::PaymentIntent>(serialized_payment_intent);
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 @@ -846,6 +846,7 @@ diesel::table! {
#[max_length = 64]
fingerprint_id -> Nullable<Varchar>,
request_external_three_ds_authentication -> Nullable<Bool>,
frm_metadata -> Nullable<Jsonb>,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/hyperswitch_domain_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ pub struct PaymentIntent {
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub session_expiry: Option<PrimitiveDateTime>,
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct PaymentIntentNew {
pub description: Option<String>,
pub return_url: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub connector_id: Option<String>,
pub shipping_address_id: Option<String>,
pub billing_address_id: Option<String>,
Expand Down Expand Up @@ -164,6 +165,7 @@ pub enum PaymentIntentUpdate {
statement_descriptor_suffix: Option<String>,
order_details: Option<Vec<pii::SecretSerdeValue>>,
metadata: Option<pii::SecretSerdeValue>,
frm_metadata: Option<pii::SecretSerdeValue>,
payment_confirm_source: Option<storage_enums::PaymentSource>,
updated_by: String,
fingerprint_id: Option<String>,
Expand Down Expand Up @@ -237,6 +239,7 @@ pub struct PaymentIntentUpdateInternal {
pub fingerprint_id: Option<String>,
pub session_expiry: Option<PrimitiveDateTime>,
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
}

impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
Expand All @@ -263,6 +266,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
fingerprint_id,
session_expiry,
request_external_three_ds_authentication,
frm_metadata,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand All @@ -285,6 +289,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
fingerprint_id,
session_expiry,
request_external_three_ds_authentication,
frm_metadata,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate {
Expand Down
2 changes: 1 addition & 1 deletion crates/hyperswitch_domain_models/src/router_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct RouterData<Flow, Request, Response> {
/// Contains apple pay flow type simplified or manual
pub apple_pay_flow: Option<common_enums::enums::ApplePayFlow>,

pub frm_metadata: Option<serde_json::Value>,
pub frm_metadata: Option<common_utils::pii::SecretSerdeValue>,

pub dispute_id: Option<String>,
pub refund_id: Option<String>,
Expand Down
4 changes: 3 additions & 1 deletion crates/router/src/connector/signifyd/transformers/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ impl TryFrom<&frm_types::FrmSaleRouterData> for SignifydPaymentsSaleRequest {
field_name: "frm_metadata",
})?
.parse_value("Signifyd Frm Metadata")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
.change_context(errors::ConnectorError::InvalidDataFormat {
field_name: "frm_metadata",
})?;
let ship_address = item.get_shipping_address()?;
let billing_address = item.get_billing()?;
let street_addr = ship_address.get_line1()?;
Expand Down
Loading

0 comments on commit 853f3b4

Please sign in to comment.