mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 21:37:41 +08:00
refactor(core): move router data response and request models to hyperswitch domain models crate (#4789)
This commit is contained in:
@ -1,43 +1,13 @@
|
||||
use cards::CardNumber;
|
||||
use error_stack::{Report, ResultExt};
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub use hyperswitch_domain_models::router_request_types::authentication::{
|
||||
AcquirerDetails, ExternalThreeDSConnectorMetadata, PreAuthenticationData, ThreeDsMethodData,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
core::{errors, payments},
|
||||
core::errors,
|
||||
types::{storage, transformers::ForeignTryFrom},
|
||||
utils::OptionExt,
|
||||
};
|
||||
pub enum PreAuthenthenticationFlowInput<'a, F: Clone> {
|
||||
PaymentAuthNFlow {
|
||||
payment_data: &'a mut payments::PaymentData<F>,
|
||||
should_continue_confirm_transaction: &'a mut bool,
|
||||
card_number: CardNumber,
|
||||
},
|
||||
PaymentMethodAuthNFlow {
|
||||
card_number: CardNumber,
|
||||
other_fields: String, //should be expanded when implementation begins
|
||||
},
|
||||
}
|
||||
|
||||
pub enum PostAuthenthenticationFlowInput<'a, F: Clone> {
|
||||
PaymentAuthNFlow {
|
||||
payment_data: &'a mut payments::PaymentData<F>,
|
||||
authentication: storage::Authentication,
|
||||
should_continue_confirm_transaction: &'a mut bool,
|
||||
},
|
||||
PaymentMethodAuthNFlow {
|
||||
other_fields: String, //should be expanded when implementation begins
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PreAuthenticationData {
|
||||
pub threeds_server_transaction_id: String,
|
||||
pub message_version: common_utils::types::SemanticVersion,
|
||||
pub acquirer_bin: Option<String>,
|
||||
pub acquirer_merchant_id: Option<String>,
|
||||
pub connector_metadata: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl ForeignTryFrom<&storage::Authentication> for PreAuthenticationData {
|
||||
type Error = Report<errors::ApiErrorResponse>;
|
||||
@ -62,20 +32,3 @@ impl ForeignTryFrom<&storage::Authentication> for PreAuthenticationData {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct ThreeDsMethodData {
|
||||
pub three_ds_method_data_submission: bool,
|
||||
pub three_ds_method_data: String,
|
||||
pub three_ds_method_url: Option<String>,
|
||||
}
|
||||
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct AcquirerDetails {
|
||||
pub acquirer_bin: String,
|
||||
pub acquirer_merchant_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct ExternalThreeDSConnectorMetadata {
|
||||
pub pull_mechanism_for_external_3ds_enabled: Option<bool>,
|
||||
}
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
use async_trait::async_trait;
|
||||
use error_stack;
|
||||
|
||||
// use router_env::tracing::Instrument;
|
||||
use super::{ConstructFlowSpecificData, Feature};
|
||||
use crate::{
|
||||
core::{
|
||||
errors::{self, ConnectorErrorExt, RouterResult},
|
||||
errors::{ConnectorErrorExt, RouterResult},
|
||||
mandate,
|
||||
payments::{
|
||||
self, access_token, customers, helpers, tokenization, transformers, PaymentData,
|
||||
@ -335,83 +334,3 @@ pub async fn authorize_preprocessing_steps<F: Clone>(
|
||||
Ok(router_data.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> TryFrom<&types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>>
|
||||
for types::ConnectorCustomerData
|
||||
{
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
|
||||
fn try_from(
|
||||
data: &types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
email: data.request.email.clone(),
|
||||
payment_method_data: data.request.payment_method_data.clone(),
|
||||
description: None,
|
||||
phone: None,
|
||||
name: data.request.customer_name.clone(),
|
||||
preprocessing_id: data.preprocessing_id.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::PaymentsAuthorizeData> for types::PaymentMethodTokenizationData {
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
|
||||
fn try_from(data: types::PaymentsAuthorizeData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
payment_method_data: data.payment_method_data,
|
||||
browser_info: data.browser_info,
|
||||
currency: data.currency,
|
||||
amount: Some(data.amount),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::PaymentsAuthorizeData> for types::PaymentsPreProcessingData {
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
|
||||
fn try_from(data: types::PaymentsAuthorizeData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
payment_method_data: Some(data.payment_method_data),
|
||||
amount: Some(data.amount),
|
||||
email: data.email,
|
||||
currency: Some(data.currency),
|
||||
payment_method_type: data.payment_method_type,
|
||||
setup_mandate_details: data.setup_mandate_details,
|
||||
capture_method: data.capture_method,
|
||||
order_details: data.order_details,
|
||||
router_return_url: data.router_return_url,
|
||||
webhook_url: data.webhook_url,
|
||||
complete_authorize_url: data.complete_authorize_url,
|
||||
browser_info: data.browser_info,
|
||||
surcharge_details: data.surcharge_details,
|
||||
connector_transaction_id: None,
|
||||
redirect_response: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::CompleteAuthorizeData> for types::PaymentsPreProcessingData {
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
|
||||
fn try_from(data: types::CompleteAuthorizeData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
payment_method_data: data.payment_method_data,
|
||||
amount: Some(data.amount),
|
||||
email: data.email,
|
||||
currency: Some(data.currency),
|
||||
payment_method_type: None,
|
||||
setup_mandate_details: data.setup_mandate_details,
|
||||
capture_method: data.capture_method,
|
||||
order_details: None,
|
||||
router_return_url: None,
|
||||
webhook_url: None,
|
||||
complete_authorize_url: data.complete_authorize_url,
|
||||
browser_info: data.browser_info,
|
||||
surcharge_details: None,
|
||||
connector_transaction_id: data.connector_transaction_id,
|
||||
redirect_response: data.redirect_response,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,13 +3,12 @@ use async_trait::async_trait;
|
||||
use super::{ConstructFlowSpecificData, Feature};
|
||||
use crate::{
|
||||
core::{
|
||||
errors::{self, ConnectorErrorExt, RouterResult},
|
||||
errors::{ConnectorErrorExt, RouterResult},
|
||||
payments::{self, access_token, helpers, transformers, PaymentData},
|
||||
},
|
||||
routes::{metrics, AppState},
|
||||
services,
|
||||
types::{self, api, domain, storage},
|
||||
utils::OptionExt,
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
@ -221,18 +220,3 @@ pub async fn complete_authorize_preprocessing_steps<F: Clone>(
|
||||
Ok(router_data.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::CompleteAuthorizeData> for types::PaymentMethodTokenizationData {
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
|
||||
fn try_from(data: types::CompleteAuthorizeData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
payment_method_data: data
|
||||
.payment_method_data
|
||||
.get_required_value("payment_method_data")?,
|
||||
browser_info: data.browser_info,
|
||||
currency: data.currency,
|
||||
amount: Some(data.amount),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
||||
use super::{ConstructFlowSpecificData, Feature};
|
||||
use crate::{
|
||||
core::{
|
||||
errors::{self, ConnectorErrorExt, RouterResult},
|
||||
errors::{ConnectorErrorExt, RouterResult},
|
||||
mandate,
|
||||
payments::{
|
||||
self, access_token, customers, helpers, tokenization, transformers, PaymentData,
|
||||
@ -143,20 +143,6 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::SetupMandateRequestData> for types::ConnectorCustomerData {
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
fn try_from(data: types::SetupMandateRequestData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
email: data.email,
|
||||
payment_method_data: data.payment_method_data,
|
||||
description: None,
|
||||
phone: None,
|
||||
name: None,
|
||||
preprocessing_id: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl mandate::MandateBehaviour for types::SetupMandateRequestData {
|
||||
fn get_amount(&self) -> i64 {
|
||||
0
|
||||
@ -187,16 +173,3 @@ impl mandate::MandateBehaviour for types::SetupMandateRequestData {
|
||||
self.customer_acceptance.clone().map(From::from)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::SetupMandateRequestData> for types::PaymentMethodTokenizationData {
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
|
||||
fn try_from(data: types::SetupMandateRequestData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
payment_method_data: data.payment_method_data,
|
||||
browser_info: None,
|
||||
currency: data.currency,
|
||||
amount: data.amount,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1314,7 +1314,10 @@ fn response_to_capture_update(
|
||||
let capture =
|
||||
multiple_capture_data.get_capture_by_connector_capture_id(connector_capture_id);
|
||||
if let Some(capture) = capture {
|
||||
capture_update_list.push((capture.clone(), capture_sync_response.try_into()?))
|
||||
capture_update_list.push((
|
||||
capture.clone(),
|
||||
storage::CaptureUpdate::foreign_try_from(capture_sync_response)?,
|
||||
))
|
||||
} else {
|
||||
// connector_capture_id may not be populated in the captures table in some case
|
||||
// if so, we try to map the unmapped capture response and captures in DB.
|
||||
@ -1350,7 +1353,7 @@ fn get_capture_update_for_unmapped_capture_responses(
|
||||
{
|
||||
result.push((
|
||||
capture.clone(),
|
||||
storage::CaptureUpdate::try_from(capture_sync_response)?,
|
||||
storage::CaptureUpdate::foreign_try_from(capture_sync_response)?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1617,10 +1617,12 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::CaptureSyncResponse> for storage::CaptureUpdate {
|
||||
impl ForeignTryFrom<types::CaptureSyncResponse> for storage::CaptureUpdate {
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
|
||||
fn try_from(capture_sync_response: types::CaptureSyncResponse) -> Result<Self, Self::Error> {
|
||||
fn foreign_try_from(
|
||||
capture_sync_response: types::CaptureSyncResponse,
|
||||
) -> Result<Self, Self::Error> {
|
||||
match capture_sync_response {
|
||||
types::CaptureSyncResponse::Success {
|
||||
resource_id,
|
||||
|
||||
@ -9,7 +9,9 @@ use common_utils::{
|
||||
use diesel_models::business_profile::BusinessProfile;
|
||||
use error_stack::ResultExt;
|
||||
use hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt;
|
||||
pub use hyperswitch_domain_models::router_request_types::{AuthenticationData, SurchargeDetails};
|
||||
pub use hyperswitch_domain_models::router_request_types::{
|
||||
AuthenticationData, PaymentCharges, SurchargeDetails,
|
||||
};
|
||||
use redis_interface::errors::RedisError;
|
||||
use router_env::{instrument, tracing};
|
||||
|
||||
@ -374,10 +376,3 @@ impl ForeignTryFrom<&storage::Authentication> for AuthenticationData {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, Clone)]
|
||||
pub struct PaymentCharges {
|
||||
pub charge_type: api_models::enums::PaymentChargeType,
|
||||
pub fees: i64,
|
||||
pub transfer_account_id: String,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user