mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
chore: introduce dedicated function to check for should continue after preprocessing
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
Currently in hyperswitch, under authorize flow, there can be a lot of flows that must be called before actually calling the authorize. Like session/access token, customer create, order create etc.
|
||||
Currently these are scattered all across the handler function 'pub async fn payments_operation_core<F, Req, Op, FData, D>(' .
|
||||
I want to standardize the flows like this.
|
||||
|
||||
PrimaryFlows and Secondary Flows.
|
||||
PrimaryFlows: The actual flow.
|
||||
SecondaryFlow: These flows might come as prerequisites before the Primary Flows. There can be multiple Secondary Flows for a PrimaryFlow.
|
||||
|
||||
PrimaryFlows can be defined as:
|
||||
1. A flow where the response is returned to the client.
|
||||
Eg: Authorize, Capture
|
||||
Authorize can have SessionToken, OrderCreate etc.
|
||||
|
||||
If Authorize is a PrimaryFlow, Then SessionTokena and OrderCreate will be SecondaryFlow.
|
||||
The order will be like SessionToken(2ndary) -> OrderCreate(2ndary) -> Authorize(Primary).
|
||||
Similarly,
|
||||
* SessionToken(2ndary) -> PreAuthN(Primary).
|
||||
* SessionToken(2ndary) -> AuthN(Primary).
|
||||
* PostAuthN(2ndary) -> Authorization(Primary)
|
||||
|
||||
Lets have marker trait for Primary and Secondary Flows. Feel free to come up with a better nomenclature for things.
|
||||
|
||||
Execution order must be known at compile time.
|
||||
@ -219,43 +219,55 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
|
||||
|
||||
async fn call_preprocessing_through_unified_connector_service<'a>(
|
||||
self,
|
||||
_state: &SessionState,
|
||||
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
|
||||
_lineage_ids: &grpc_client::LineageIds,
|
||||
#[cfg(feature = "v1")] _merchant_connector_account: helpers::MerchantConnectorAccountType,
|
||||
state: &SessionState,
|
||||
header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
|
||||
lineage_ids: &grpc_client::LineageIds,
|
||||
#[cfg(feature = "v1")] merchant_connector_account: helpers::MerchantConnectorAccountType,
|
||||
#[cfg(feature = "v2")]
|
||||
_merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
|
||||
_merchant_context: &domain::MerchantContext,
|
||||
merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
|
||||
merchant_context: &domain::MerchantContext,
|
||||
connector_data: &api::ConnectorData,
|
||||
_unified_connector_service_execution_mode: common_enums::ExecutionMode,
|
||||
_merchant_order_reference_id: Option<String>,
|
||||
unified_connector_service_execution_mode: common_enums::ExecutionMode,
|
||||
merchant_order_reference_id: Option<String>,
|
||||
) -> RouterResult<(Self, bool)> {
|
||||
let current_flow = api_interface::CurrentFlowInfo::CompleteAuthorize {
|
||||
request_data: &self.request,
|
||||
};
|
||||
if let Some(preprocessing_flow_details) = connector_data
|
||||
let optional_preprocessing_flow = connector_data
|
||||
.connector
|
||||
.get_preprocessing_flow_if_needed(current_flow)
|
||||
{
|
||||
let updated_router_data = match preprocessing_flow_details.flow_name {
|
||||
api_interface::PreProcessingFlowName::Authenticate => {
|
||||
// Call UCS for Authenticate flow
|
||||
self
|
||||
}
|
||||
api_interface::PreProcessingFlowName::PostAuthenticate => {
|
||||
// Call UCS for PostAuthenticate flow
|
||||
self
|
||||
}
|
||||
};
|
||||
let pre_processing_flow_response = api_interface::PreProcessingFlowResponse {
|
||||
response: &updated_router_data.response,
|
||||
attempt_status: updated_router_data.status,
|
||||
};
|
||||
let should_continue =
|
||||
(preprocessing_flow_details.should_continue)(&pre_processing_flow_response);
|
||||
Ok((updated_router_data, should_continue))
|
||||
} else {
|
||||
Ok((self, true))
|
||||
.get_preprocessing_flow_if_needed(current_flow);
|
||||
match optional_preprocessing_flow {
|
||||
Some(preprocessing_flow) => {
|
||||
let updated_router_data = handle_preprocessing_through_unified_connector_service(
|
||||
self,
|
||||
state,
|
||||
header_payload,
|
||||
lineage_ids,
|
||||
merchant_connector_account.clone(),
|
||||
merchant_context,
|
||||
connector_data,
|
||||
unified_connector_service_execution_mode,
|
||||
merchant_order_reference_id.clone(),
|
||||
preprocessing_flow,
|
||||
)
|
||||
.await?;
|
||||
let pre_processing_flow_response = api_interface::PreProcessingFlowResponse {
|
||||
response: &updated_router_data.response,
|
||||
attempt_status: updated_router_data.status,
|
||||
};
|
||||
let current_flow = api_interface::CurrentFlowInfo::CompleteAuthorize {
|
||||
request_data: &updated_router_data.request,
|
||||
};
|
||||
let should_continue = connector_data
|
||||
.connector
|
||||
.decide_should_continue_after_preprocessing(
|
||||
current_flow,
|
||||
preprocessing_flow,
|
||||
pre_processing_flow_response,
|
||||
);
|
||||
Ok((updated_router_data, should_continue))
|
||||
}
|
||||
None => Ok((self, true)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,6 +289,41 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_preprocessing_through_unified_connector_service(
|
||||
router_data: types::RouterData<
|
||||
api::CompleteAuthorize,
|
||||
types::CompleteAuthorizeData,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
_state: &SessionState,
|
||||
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
|
||||
_lineage_ids: &grpc_client::LineageIds,
|
||||
#[cfg(feature = "v1")] _merchant_connector_account: helpers::MerchantConnectorAccountType,
|
||||
#[cfg(feature = "v2")] _merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
|
||||
_merchant_context: &domain::MerchantContext,
|
||||
_connector_data: &api::ConnectorData,
|
||||
_unified_connector_service_execution_mode: common_enums::ExecutionMode,
|
||||
_merchant_order_reference_id: Option<String>,
|
||||
preprocessing_flow_name: api_interface::PreProcessingFlowName,
|
||||
) -> RouterResult<
|
||||
types::RouterData<
|
||||
api::CompleteAuthorize,
|
||||
types::CompleteAuthorizeData,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
> {
|
||||
match preprocessing_flow_name {
|
||||
api_interface::PreProcessingFlowName::Authenticate => {
|
||||
// Call UCS for Authenticate flow
|
||||
Ok(router_data)
|
||||
}
|
||||
api_interface::PreProcessingFlowName::PostAuthenticate => {
|
||||
// Call UCS for PostAuthenticate flow
|
||||
Ok(router_data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn complete_authorize_preprocessing_steps<F: Clone>(
|
||||
state: &SessionState,
|
||||
router_data: &types::RouterData<F, types::CompleteAuthorizeData, types::PaymentsResponseData>,
|
||||
|
||||
Reference in New Issue
Block a user