Skip to content

Commit

Permalink
feat(core): add support for connectors having separate version call f…
Browse files Browse the repository at this point in the history
…or pre authentication (#4603)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
hrithikesh026 and hyperswitch-bot[bot] authored May 21, 2024
1 parent fea2ea6 commit 528d692
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,4 @@ refunds = "hyperswitch-refund-events"
disputes = "hyperswitch-dispute-events"

[saved_payment_methods]
sdk_eligible_payment_methods = "card"
sdk_eligible_payment_methods = "card"
2 changes: 1 addition & 1 deletion config/deployments/integration_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,4 @@ connectors_with_webhook_source_verification_call = "paypal" # List of co
keys = "user-agent"

[saved_payment_methods]
sdk_eligible_payment_methods = "card"
sdk_eligible_payment_methods = "card"
2 changes: 1 addition & 1 deletion config/deployments/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,4 @@ connectors_with_webhook_source_verification_call = "paypal" # List of connec
keys = "user-agent"

[saved_payment_methods]
sdk_eligible_payment_methods = "card"
sdk_eligible_payment_methods = "card"
2 changes: 1 addition & 1 deletion config/deployments/sandbox.toml
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,4 @@ connectors_with_webhook_source_verification_call = "paypal" # List of con
keys = "user-agent"

[saved_payment_methods]
sdk_eligible_payment_methods = "card"
sdk_eligible_payment_methods = "card"
2 changes: 1 addition & 1 deletion config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,4 @@ refunds = "hyperswitch-refund-events"
disputes = "hyperswitch-dispute-events"

[saved_payment_methods]
sdk_eligible_payment_methods = "card"
sdk_eligible_payment_methods = "card"
9 changes: 9 additions & 0 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ pub enum AuthenticationConnectors {
Gpayments,
}

impl AuthenticationConnectors {
pub fn is_separate_version_call_required(&self) -> bool {
match self {
Self::Threedsecureio | Self::Netcetera => false,
Self::Gpayments => true,
}
}
}

#[cfg(feature = "payouts")]
#[derive(
Clone,
Expand Down
9 changes: 9 additions & 0 deletions crates/router/src/connector/gpayments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl api::IncomingWebhook for Gpayments {
impl api::ExternalAuthentication for Gpayments {}
impl api::ConnectorAuthentication for Gpayments {}
impl api::ConnectorPreAuthentication for Gpayments {}
impl api::ConnectorPreAuthenticationVersionCall for Gpayments {}
impl api::ConnectorPostAuthentication for Gpayments {}
impl
ConnectorIntegration<
Expand All @@ -221,6 +222,14 @@ impl
> for Gpayments
{
}
impl
ConnectorIntegration<
api::PreAuthenticationVersionCall,
types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
> for Gpayments
{
}
impl
ConnectorIntegration<
api::PostAuthentication,
Expand Down
10 changes: 10 additions & 0 deletions crates/router/src/connector/netcetera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn build_endpoint(
}

impl api::ConnectorPreAuthentication for Netcetera {}
impl api::ConnectorPreAuthenticationVersionCall for Netcetera {}
impl api::ExternalAuthentication for Netcetera {}
impl api::ConnectorAuthentication for Netcetera {}
impl api::ConnectorPostAuthentication for Netcetera {}
Expand Down Expand Up @@ -451,3 +452,12 @@ impl
> for Netcetera
{
}

impl
ConnectorIntegration<
api::PreAuthenticationVersionCall,
types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
> for Netcetera
{
}
14 changes: 10 additions & 4 deletions crates/router/src/connector/threedsecureio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ impl api::IncomingWebhook for Threedsecureio {
}

impl api::ConnectorPreAuthentication for Threedsecureio {}
impl api::ConnectorPreAuthenticationVersionCall for Threedsecureio {}
impl api::ExternalAuthentication for Threedsecureio {}
impl api::ConnectorAuthentication for Threedsecureio {}
impl api::ConnectorPostAuthentication for Threedsecureio {}
Expand Down Expand Up @@ -409,10 +410,6 @@ impl
data: data.clone(),
http_code: res.status_code,
})
// Ok(types::authentication::PreAuthNRouterData {
// response,
// ..data.clone()
// })
}

fn get_error_response(
Expand Down Expand Up @@ -527,3 +524,12 @@ impl
self.build_error_response(res, event_builder)
}
}

impl
ConnectorIntegration<
api::PreAuthenticationVersionCall,
types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
> for Threedsecureio
{
}
41 changes: 35 additions & 6 deletions crates/router/src/core/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,41 @@ pub async fn perform_pre_authentication(
)
.await?;

let router_data = transformers::construct_pre_authentication_router_data(
authentication_connector_name.clone(),
card_number,
&three_ds_connector_account,
business_profile.merchant_id.clone(),
)?;
let authentication = if authentication_connector.is_separate_version_call_required() {
let router_data: core_types::authentication::PreAuthNVersionCallRouterData =
transformers::construct_pre_authentication_router_data(
authentication_connector_name.clone(),
card_number.clone(),
&three_ds_connector_account,
business_profile.merchant_id.clone(),
)?;
let router_data = utils::do_auth_connector_call(
state,
authentication_connector_name.clone(),
router_data,
)
.await?;

let updated_authentication =
utils::update_trackers(state, router_data, authentication, acquirer_details.clone())
.await?;
// from version call response, we will get to know the maximum supported 3ds version.
// If the version is not greater than or equal to 3DS 2.0, We should not do the successive pre authentication call.
if !updated_authentication.is_separate_authn_required() {
return Ok(updated_authentication);
}
updated_authentication
} else {
authentication
};

let router_data: core_types::authentication::PreAuthNRouterData =
transformers::construct_pre_authentication_router_data(
authentication_connector_name.clone(),
card_number,
&three_ds_connector_account,
business_profile.merchant_id.clone(),
)?;
let router_data =
utils::do_auth_connector_call(state, authentication_connector_name, router_data).await?;

Expand Down
10 changes: 8 additions & 2 deletions crates/router/src/core/authentication/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ pub fn construct_post_authentication_router_data(
)
}

pub fn construct_pre_authentication_router_data(
pub fn construct_pre_authentication_router_data<F: Clone>(
authentication_connector: String,
card_holder_account_number: cards::CardNumber,
merchant_connector_account: &payments_helpers::MerchantConnectorAccountType,
merchant_id: String,
) -> RouterResult<types::authentication::PreAuthNRouterData> {
) -> RouterResult<
types::RouterData<
F,
types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
>,
> {
let router_request = types::authentication::PreAuthNRequestData {
card_holder_account_number,
};
Expand Down
19 changes: 19 additions & 0 deletions crates/router/src/core/payments/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,7 @@ macro_rules! default_imp_for_connector_authentication {
$( impl api::ExternalAuthentication for $path::$connector {}
impl api::ConnectorAuthentication for $path::$connector {}
impl api::ConnectorPreAuthentication for $path::$connector {}
impl api::ConnectorPreAuthenticationVersionCall for $path::$connector {}
impl api::ConnectorPostAuthentication for $path::$connector {}
impl
services::ConnectorIntegration<
Expand All @@ -2583,6 +2584,13 @@ macro_rules! default_imp_for_connector_authentication {
types::authentication::AuthenticationResponseData,
> for $path::$connector
{}
impl
services::ConnectorIntegration<
api::PreAuthenticationVersionCall,
types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
> for $path::$connector
{}
impl
services::ConnectorIntegration<
api::PostAuthentication,
Expand All @@ -2599,6 +2607,8 @@ impl<const T: u8> api::ExternalAuthentication for connector::DummyConnector<T> {
#[cfg(feature = "dummy_connector")]
impl<const T: u8> api::ConnectorPreAuthentication for connector::DummyConnector<T> {}
#[cfg(feature = "dummy_connector")]
impl<const T: u8> api::ConnectorPreAuthenticationVersionCall for connector::DummyConnector<T> {}
#[cfg(feature = "dummy_connector")]
impl<const T: u8> api::ConnectorAuthentication for connector::DummyConnector<T> {}
#[cfg(feature = "dummy_connector")]
impl<const T: u8> api::ConnectorPostAuthentication for connector::DummyConnector<T> {}
Expand All @@ -2622,6 +2632,15 @@ impl<const T: u8>
{
}
#[cfg(feature = "dummy_connector")]
impl<const T: u8>
services::ConnectorIntegration<
api::PreAuthenticationVersionCall,
types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
> for connector::DummyConnector<T>
{
}
#[cfg(feature = "dummy_connector")]
impl<const T: u8>
services::ConnectorIntegration<
api::PostAuthentication,
Expand Down
13 changes: 13 additions & 0 deletions crates/router/src/types/api/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use crate::core::errors;
#[derive(Debug, Clone)]
pub struct PreAuthentication;

#[derive(Debug, Clone)]
pub struct PreAuthenticationVersionCall;

#[derive(Debug, Clone)]
pub struct Authentication;

Expand Down Expand Up @@ -94,6 +97,15 @@ pub trait ConnectorPreAuthentication:
{
}

pub trait ConnectorPreAuthenticationVersionCall:
services::ConnectorIntegration<
PreAuthenticationVersionCall,
types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
>
{
}

pub trait ConnectorPostAuthentication:
services::ConnectorIntegration<
PostAuthentication,
Expand All @@ -107,6 +119,7 @@ pub trait ExternalAuthentication:
super::ConnectorCommon
+ ConnectorAuthentication
+ ConnectorPreAuthentication
+ ConnectorPreAuthenticationVersionCall
+ ConnectorPostAuthentication
{
}
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/types/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ pub struct ConnectorPostAuthenticationRequestData {
pub type PreAuthNRouterData =
RouterData<api::PreAuthentication, PreAuthNRequestData, AuthenticationResponseData>;

pub type PreAuthNVersionCallRouterData =
RouterData<api::PreAuthenticationVersionCall, PreAuthNRequestData, AuthenticationResponseData>;

pub type ConnectorAuthenticationRouterData =
RouterData<api::Authentication, ConnectorAuthenticationRequestData, AuthenticationResponseData>;

Expand Down

0 comments on commit 528d692

Please sign in to comment.