Skip to content

Commit

Permalink
refactor: rename authentication data to redirect form
Browse files Browse the repository at this point in the history
also instead of using serdejson value, use a type
  • Loading branch information
Narayanbhat166 committed Nov 9, 2024
1 parent d050efb commit 301bd59
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 27 deletions.
10 changes: 10 additions & 0 deletions crates/common_utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,16 @@ impl Url {
pub fn get_string_repr(&self) -> &str {
self.0.as_str()
}

/// wrap the url::Url in Url type
pub fn wrap(url: url::Url) -> Self {
Self(url)
}

/// Get the inner url
pub fn into_inner(self) -> url::Url {
self.0
}
}

impl<DB> ToSql<sql_types::Text, DB> for Url
Expand Down
55 changes: 52 additions & 3 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub struct PaymentAttempt {
pub amount_capturable: MinorUnit,
pub updated_by: String,
pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
pub authentication_data: Option<pii::SecretSerdeValue>,
pub encoded_data: Option<masking::Secret<String>>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
Expand All @@ -89,6 +88,7 @@ pub struct PaymentAttempt {
pub external_reference_id: Option<String>,
pub tax_on_surcharge: Option<MinorUnit>,
pub payment_method_billing_address: Option<common_utils::encryption::Encryption>,
pub redirection_data: Option<RedirectForm>,
pub connector_payment_data: Option<String>,
pub id: id_type::GlobalAttemptId,
pub shipping_cost: Option<MinorUnit>,
Expand Down Expand Up @@ -255,7 +255,7 @@ pub struct PaymentAttemptNew {
pub amount_capturable: MinorUnit,
pub updated_by: String,
pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
pub authentication_data: Option<pii::SecretSerdeValue>,
pub redirection_data: Option<RedirectForm>,
pub encoded_data: Option<masking::Secret<String>>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
Expand Down Expand Up @@ -770,7 +770,7 @@ pub struct PaymentAttemptUpdateInternal {
pub updated_by: String,
pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
pub connector: Option<String>,
pub authentication_data: Option<pii::SecretSerdeValue>,
pub redirection_data: Option<RedirectForm>,
// encoded_data: Option<String>,
pub unified_code: Option<Option<String>>,
pub unified_message: Option<Option<String>>,
Expand Down Expand Up @@ -3283,6 +3283,55 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
}
}

#[derive(Eq, PartialEq, Clone, Debug, Deserialize, Serialize, diesel::AsExpression)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
pub enum RedirectForm {
Form {
endpoint: String,
method: common_utils::request::Method,
form_fields: std::collections::HashMap<String, String>,
},
Html {
html_data: String,
},
BlueSnap {
payment_fields_token: String,
},
CybersourceAuthSetup {
access_token: String,
ddc_url: String,
reference_id: String,
},
CybersourceConsumerAuth {
access_token: String,
step_up_url: String,
},
Payme,
Braintree {
client_token: String,
card_token: String,
bin: String,
},
Nmi {
amount: String,
currency: common_enums::Currency,
public_key: masking::Secret<String>,
customer_vault_id: String,
order_id: String,
},
Mifinity {
initialization_token: String,
},
WorldpayDDCForm {
endpoint: common_utils::types::Url,
method: common_utils::request::Method,
form_fields: std::collections::HashMap<String, String>,
collection_id: Option<String>,
},
}

common_utils::impl_to_sql_from_sql_json!(RedirectForm);

mod tests {

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ diesel::table! {
updated_by -> Varchar,
#[max_length = 32]
merchant_connector_id -> Nullable<Varchar>,
authentication_data -> Nullable<Json>,
encoded_data -> Nullable<Text>,
#[max_length = 255]
unified_code -> Nullable<Varchar>,
Expand Down Expand Up @@ -814,6 +813,7 @@ diesel::table! {
external_reference_id -> Nullable<Varchar>,
tax_on_surcharge -> Nullable<Int8>,
payment_method_billing_address -> Nullable<Bytea>,
redirection_data -> Nullable<Jsonb>,
#[max_length = 512]
connector_payment_data -> Nullable<Varchar>,
#[max_length = 64]
Expand Down
27 changes: 16 additions & 11 deletions crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use crate::{
router_request_types, ForeignIDRef,
};

#[cfg(feature = "v2")]
use crate::router_response_types;

#[async_trait::async_trait]
pub trait PaymentAttemptInterface {
#[cfg(feature = "v1")]
Expand Down Expand Up @@ -261,7 +264,7 @@ pub struct PaymentAttempt {
/// Whether the payment was updated by postgres or redis
pub updated_by: String,
/// The authentication data which is used for external authentication
pub authentication_data: Option<pii::SecretSerdeValue>,
pub redirection_data: Option<router_response_types::RedirectForm>,
pub encoded_data: Option<Secret<String>>,
pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
/// Whether external 3DS authentication was attempted for this payment.
Expand Down Expand Up @@ -383,7 +386,7 @@ impl PaymentAttempt {
multiple_capture_count: None,
connector_response_reference_id: None,
updated_by: storage_scheme.to_string(),
authentication_data: None,
redirection_data: None,
encoded_data: None,
merchant_connector_id: None,
external_three_ds_authentication_attempted: None,
Expand Down Expand Up @@ -1295,7 +1298,7 @@ pub enum PaymentAttemptUpdate {
status: storage_enums::AttemptStatus,
connector_payment_id: Option<String>,
updated_by: String,
authentication_data: Option<pii::SecretSerdeValue>,
redirection_data: Option<router_response_types::RedirectForm>,
},
/// Update the payment attempt after force syncing with the connector
SyncUpdate {
Expand Down Expand Up @@ -1619,7 +1622,7 @@ impl behaviour::Conversion for PaymentAttempt {
multiple_capture_count,
connector_response_reference_id,
updated_by,
authentication_data,
redirection_data,
encoded_data,
merchant_connector_id,
external_three_ds_authentication_attempted,
Expand Down Expand Up @@ -1688,7 +1691,7 @@ impl behaviour::Conversion for PaymentAttempt {
amount_capturable,
updated_by,
merchant_connector_id,
authentication_data,
redirection_data: redirection_data.map(From::from),
encoded_data,
unified_code: error
.as_ref()
Expand Down Expand Up @@ -1796,7 +1799,7 @@ impl behaviour::Conversion for PaymentAttempt {
multiple_capture_count: storage_model.multiple_capture_count,
connector_response_reference_id: storage_model.connector_response_reference_id,
updated_by: storage_model.updated_by,
authentication_data: storage_model.authentication_data,
redirection_data: storage_model.redirection_data.map(From::from),
encoded_data: storage_model.encoded_data,
merchant_connector_id: storage_model.merchant_connector_id,
external_three_ds_authentication_attempted: storage_model
Expand Down Expand Up @@ -1872,7 +1875,7 @@ impl behaviour::Conversion for PaymentAttempt {
amount_capturable: self.amount_details.amount_capturable,
updated_by: self.updated_by,
merchant_connector_id: self.merchant_connector_id,
authentication_data: self.authentication_data,
redirection_data: self.redirection_data.map(From::from),
encoded_data: self.encoded_data,
unified_code: error_details
.as_ref()
Expand Down Expand Up @@ -1929,7 +1932,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
unified_message: None,
connector_payment_id: None,
connector: Some(connector),
authentication_data: None,
redirection_data: None,
},
PaymentAttemptUpdate::ErrorUpdate {
status,
Expand All @@ -1949,13 +1952,13 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
unified_message: None,
connector_payment_id,
connector: None,
authentication_data: None,
redirection_data: None,
},
PaymentAttemptUpdate::ConfirmIntentResponse {
status,
connector_payment_id,
updated_by,
authentication_data,
redirection_data,
} => Self {
status: Some(status),
error_message: None,
Expand All @@ -1969,7 +1972,8 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
unified_message: None,
connector_payment_id,
connector: None,
authentication_data,
redirection_data: redirection_data
.map(diesel_models::payment_attempt::RedirectForm::from),
},
PaymentAttemptUpdate::SyncUpdate { status, updated_by } => Self {
status: Some(status),
Expand All @@ -1984,6 +1988,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
unified_message: None,
connector_payment_id: None,
connector: None,
redirection_data: None,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/hyperswitch_domain_models/src/router_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ impl
status: attempt_status,
connector_payment_id,
updated_by: storage_scheme.to_string(),
redirection_data: *redirection_data.clone(),
}
}
router_response_types::PaymentsResponseData::MultipleCaptureResponse { .. } => {
Expand Down
Loading

0 comments on commit 301bd59

Please sign in to comment.