Skip to content

Commit

Permalink
merged main
Browse files Browse the repository at this point in the history
  • Loading branch information
tsdk02 committed Jun 24, 2024
2 parents 23be256 + e658899 commit 952fe3c
Show file tree
Hide file tree
Showing 103 changed files with 2,153 additions and 683 deletions.
3 changes: 2 additions & 1 deletion crates/hyperswitch_domain_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ readme = "README.md"
license.workspace = true

[features]
default = ["olap", "payouts"]
default = ["olap", "payouts", "frm"]
olap = []
payouts = ["api_models/payouts"]
frm = ["api_models/frm"]

[dependencies]
# First party deps
Expand Down
4 changes: 3 additions & 1 deletion crates/hyperswitch_domain_models/src/router_data_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ pub mod flow_common_types;

use std::{marker::PhantomData, ops::Deref};

#[cfg(feature = "frm")]
pub use flow_common_types::FrmFlowData;
#[cfg(feature = "payouts")]
pub use flow_common_types::PayoutFlowData;
pub use flow_common_types::{
AccessTokenFlowData, DisputesFlowData, ExternalAuthenticationFlowData, FilesFlowData,
FrmFlowData, MandateRevokeFlowData, PaymentFlowData, RefundFlowData, WebhookSourceVerifyData,
MandateRevokeFlowData, PaymentFlowData, RefundFlowData, WebhookSourceVerifyData,
};

use crate::router_data::{ConnectorAuthType, ErrorResponse};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
#[derive(Debug, Clone)]
pub struct PaymentFlowData {
pub merchant_id: String,
pub customer_id: Option<String>,
pub customer_id: Option<common_utils::id_type::CustomerId>,
pub connector_customer: Option<String>,
pub payment_id: String,
pub attempt_id: String,
Expand Down Expand Up @@ -54,7 +54,7 @@ pub struct PaymentFlowData {
#[derive(Debug, Clone)]
pub struct RefundFlowData {
pub merchant_id: String,
pub customer_id: Option<String>,
pub customer_id: Option<common_utils::id_type::CustomerId>,
pub payment_id: String,
pub attempt_id: String,
pub status: common_enums::AttemptStatus,
Expand All @@ -73,7 +73,7 @@ pub struct RefundFlowData {
#[derive(Debug, Clone)]
pub struct PayoutFlowData {
pub merchant_id: String,
pub customer_id: Option<String>,
pub customer_id: Option<common_utils::id_type::CustomerId>,
pub connector_customer: Option<String>,
pub return_url: Option<String>,
pub address: PaymentAddress,
Expand All @@ -85,6 +85,7 @@ pub struct PayoutFlowData {
pub quote_id: Option<String>,
}

#[cfg(feature = "frm")]
#[derive(Debug, Clone)]
pub struct FrmFlowData {
pub merchant_id: String,
Expand Down Expand Up @@ -127,7 +128,7 @@ pub struct DisputesFlowData {
#[derive(Debug, Clone)]
pub struct MandateRevokeFlowData {
pub merchant_id: String,
pub customer_id: String,
pub customer_id: common_utils::id_type::CustomerId,
pub payment_id: Option<String>,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license.workspace = true
[features]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts", "payout_retry", "business_profile_routing", "connector_choice_mca_id", "profile_specific_fallback_routing", "retry", "frm"]
email = ["external_services/email", "scheduler/email", "olap"]
frm = ["api_models/frm"]
frm = ["api_models/frm", "hyperswitch_domain_models/frm"]
stripe = ["dep:serde_qs"]
release = ["stripe", "email", "backwards_compatibility", "business_profile_routing", "accounts_cache", "kv_store", "connector_choice_mca_id", "profile_specific_fallback_routing", "vergen", "recon", "external_services/aws_kms", "external_services/aws_s3"]
olap = ["hyperswitch_domain_models/olap", "storage_impl/olap", "scheduler/olap", "api_models/olap", "dep:analytics"]
Expand Down
10 changes: 8 additions & 2 deletions crates/router/src/core/authentication/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use common_utils::ext_traits::ValueExt;
use error_stack::ResultExt;
use hyperswitch_domain_models::router_data_v2::ExternalAuthenticationFlowData;

use crate::{
consts,
Expand Down Expand Up @@ -241,11 +242,16 @@ where
Res: std::fmt::Debug + Clone + 'static,
F: std::fmt::Debug + Clone + 'static,
dyn api::Connector + Sync: services::api::ConnectorIntegration<F, Req, Res>,
dyn api::ConnectorV2 + Sync:
services::api::ConnectorIntegrationV2<F, ExternalAuthenticationFlowData, Req, Res>,
{
let connector_data =
api::AuthenticationConnectorData::get_connector_by_name(&authentication_connector_name)?;
let connector_integration: services::BoxedConnectorIntegration<'_, F, Req, Res> =
connector_data.connector.get_connector_integration();
let connector_integration: services::BoxedExternalAuthenticationConnectorIntegrationInterface<
F,
Req,
Res,
> = connector_data.connector.get_connector_integration();
let router_data = execute_connector_processing_step(
state,
connector_integration,
Expand Down
91 changes: 45 additions & 46 deletions crates/router/src/core/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ pub async fn accept_dispute(
api::GetToken::Connector,
dispute.merchant_connector_id.clone(),
)?;
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedDisputeConnectorIntegrationInterface<
api::Accept,
AcceptDisputeRequestData,
AcceptDisputeResponse,
Expand Down Expand Up @@ -225,8 +224,7 @@ pub async fn submit_evidence(
dispute.merchant_connector_id.clone(),
)?;

let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedDisputeConnectorIntegrationInterface<
api::Evidence,
SubmitEvidenceRequestData,
SubmitEvidenceResponse,
Expand Down Expand Up @@ -262,52 +260,53 @@ pub async fn submit_evidence(
reason: err.reason,
})?;
//Defend Dispute Optionally if connector expects to defend / submit evidence in a separate api call
let (dispute_status, connector_status) =
if connector_data.connector_name.requires_defend_dispute() {
let connector_integration_defend_dispute: services::BoxedConnectorIntegration<
'_,
let (dispute_status, connector_status) = if connector_data
.connector_name
.requires_defend_dispute()
{
let connector_integration_defend_dispute: services::BoxedDisputeConnectorIntegrationInterface<
api::Defend,
DefendDisputeRequestData,
DefendDisputeResponse,
> = connector_data.connector.get_connector_integration();
let defend_dispute_router_data = core_utils::construct_defend_dispute_router_data(
&state,
&payment_intent,
&payment_attempt,
&merchant_account,
&key_store,
&dispute,
)
.await?;
let defend_response = services::execute_connector_processing_step(
&state,
connector_integration_defend_dispute,
&defend_dispute_router_data,
payments::CallConnectorAction::Trigger,
None,
)
.await
.to_dispute_failed_response()
.attach_printable("Failed while calling defend dispute connector api")?;
let defend_dispute_response = defend_response.response.map_err(|err| {
errors::ApiErrorResponse::ExternalConnectorError {
code: err.code,
message: err.message,
connector: dispute.connector.clone(),
status_code: err.status_code,
reason: err.reason,
}
})?;
(
defend_dispute_response.dispute_status,
defend_dispute_response.connector_status,
)
} else {
(
submit_evidence_response.dispute_status,
submit_evidence_response.connector_status,
)
};
let defend_dispute_router_data = core_utils::construct_defend_dispute_router_data(
&state,
&payment_intent,
&payment_attempt,
&merchant_account,
&key_store,
&dispute,
)
.await?;
let defend_response = services::execute_connector_processing_step(
&state,
connector_integration_defend_dispute,
&defend_dispute_router_data,
payments::CallConnectorAction::Trigger,
None,
)
.await
.to_dispute_failed_response()
.attach_printable("Failed while calling defend dispute connector api")?;
let defend_dispute_response = defend_response.response.map_err(|err| {
errors::ApiErrorResponse::ExternalConnectorError {
code: err.code,
message: err.message,
connector: dispute.connector.clone(),
status_code: err.status_code,
reason: err.reason,
}
})?;
(
defend_dispute_response.dispute_status,
defend_dispute_response.connector_status,
)
} else {
(
submit_evidence_response.dispute_status,
submit_evidence_response.connector_status,
)
};
let update_dispute = diesel_models::dispute::DisputeUpdate::StatusUpdate {
dispute_status,
connector_status,
Expand Down
6 changes: 2 additions & 4 deletions crates/router/src/core/files/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ pub async fn retrieve_file_from_connector(
api::GetToken::Connector,
file_metadata.merchant_connector_id.clone(),
)?;
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedFilesConnectorIntegrationInterface<
api::Retrieve,
types::RetrieveFileRequestData,
types::RetrieveFileResponse,
Expand Down Expand Up @@ -279,8 +278,7 @@ pub async fn upload_and_get_provider_provider_file_id_profile_id(
.await
.change_context(errors::ApiErrorResponse::PaymentNotFound)?;

let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedFilesConnectorIntegrationInterface<
api::Upload,
types::UploadFileRequestData,
types::UploadFileResponse,
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/fraud_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,7 @@ pub async fn make_fulfillment_api_call(
.await
.change_context(errors::ApiErrorResponse::PaymentNotFound)?;
let connector_data = FraudCheckConnectorData::get_connector_by_name(&fraud_check.frm_name)?;
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedFrmConnectorIntegrationInterface<
Fulfillment,
frm_types::FraudCheckFulfillmentData,
frm_types::FraudCheckResponseData,
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/fraud_check/flows/checkout_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ pub async fn decide_frm_flow<'a, 'b>(
call_connector_action: payments::CallConnectorAction,
_merchant_account: &domain::MerchantAccount,
) -> RouterResult<FrmCheckoutRouterData> {
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedFrmConnectorIntegrationInterface<
frm_api::Checkout,
FraudCheckCheckoutData,
FraudCheckResponseData,
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/fraud_check/flows/record_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ pub async fn decide_frm_flow<'a, 'b>(
call_connector_action: payments::CallConnectorAction,
_merchant_account: &domain::MerchantAccount,
) -> RouterResult<FrmRecordReturnRouterData> {
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedFrmConnectorIntegrationInterface<
RecordReturn,
FraudCheckRecordReturnData,
FraudCheckResponseData,
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/fraud_check/flows/sale_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ pub async fn decide_frm_flow<'a, 'b>(
call_connector_action: payments::CallConnectorAction,
_merchant_account: &domain::MerchantAccount,
) -> RouterResult<FrmSaleRouterData> {
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedFrmConnectorIntegrationInterface<
frm_api::Sale,
FraudCheckSaleData,
FraudCheckResponseData,
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/fraud_check/flows/transaction_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ pub async fn decide_frm_flow<'a, 'b>(
call_connector_action: payments::CallConnectorAction,
_merchant_account: &domain::MerchantAccount,
) -> RouterResult<FrmTransactionRouterData> {
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedFrmConnectorIntegrationInterface<
frm_api::Transaction,
FraudCheckTransactionData,
FraudCheckResponseData,
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/mandate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ pub async fn revoke_mandate(
GetToken::Connector,
mandate.merchant_connector_id.clone(),
)?;
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedMandateRevokeConnectorIntegrationInterface<
types::api::MandateRevoke,
types::MandateRevokeRequestData,
types::MandateRevokeResponseData,
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ use crate::{
db::StorageInterface,
logger,
routes::{app::ReqState, metrics, payment_methods::ParentPaymentMethodToken, SessionState},
services::{self, api::Authenticate},
services::{self, api::Authenticate, ConnectorRedirectResponse},
types::{
self as router_types,
api::{self, authentication, ConnectorCallType},
api::{self, authentication, ConnectorCallType, ConnectorCommon},
domain,
storage::{self, enums as storage_enums, payment_attempt::PaymentAttemptExt},
transformers::{ForeignInto, ForeignTryInto},
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/payments/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ pub async fn refresh_connector_auth(
types::AccessToken,
>,
) -> RouterResult<Result<types::AccessToken, types::ErrorResponse>> {
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedAccessTokenConnectorIntegrationInterface<
api_types::AccessTokenAuth,
types::AccessTokenRequestData,
types::AccessToken,
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/payments/customers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ pub async fn create_connector_customer<F: Clone, T: Clone>(
router_data: &types::RouterData<F, T, types::PaymentsResponseData>,
customer_request_data: types::ConnectorCustomerData,
) -> RouterResult<Option<String>> {
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedPaymentConnectorIntegrationInterface<
api::CreateConnectorCustomer,
types::ConnectorCustomerData,
types::PaymentsResponseData,
Expand Down
13 changes: 5 additions & 8 deletions crates/router/src/core/payments/flows/authorize_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
logger,
routes::{metrics, SessionState},
services,
services::api::ConnectorValidation,
types::{self, api, domain, storage, transformers::ForeignFrom},
};

Expand Down Expand Up @@ -65,8 +66,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
connector_request: Option<services::Request>,
_business_profile: &storage::business_profile::BusinessProfile,
) -> RouterResult<Self> {
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedPaymentConnectorIntegrationInterface<
api::Authorize,
types::PaymentsAuthorizeData,
types::PaymentsResponseData,
Expand Down Expand Up @@ -111,8 +111,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
where
Self: Sized,
{
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedPaymentConnectorIntegrationInterface<
api::AuthorizeSessionToken,
types::AuthorizeSessionTokenData,
types::PaymentsResponseData,
Expand Down Expand Up @@ -202,8 +201,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
.to_payment_failed_response()?;
}

let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedPaymentConnectorIntegrationInterface<
api::Authorize,
types::PaymentsAuthorizeData,
types::PaymentsResponseData,
Expand Down Expand Up @@ -300,8 +298,7 @@ pub async fn authorize_preprocessing_steps<F: Clone>(
connector: &api::ConnectorData,
) -> RouterResult<types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>> {
if confirm {
let connector_integration: services::BoxedConnectorIntegration<
'_,
let connector_integration: services::BoxedPaymentConnectorIntegrationInterface<
api::PreProcessing,
types::PaymentsPreProcessingData,
types::PaymentsResponseData,
Expand Down
Loading

0 comments on commit 952fe3c

Please sign in to comment.