Skip to content

Commit

Permalink
feat(core): add SCA exemption field (#6578)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
Sakilmostak and hyperswitch-bot[bot] authored Nov 25, 2024
1 parent 83e8bc0 commit 2b8eb09
Show file tree
Hide file tree
Showing 37 changed files with 152 additions and 4 deletions.
8 changes: 8 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -18645,6 +18645,14 @@
}
}
},
"ScaExemptionType": {
"type": "string",
"description": "SCA Exemptions types available for authentication",
"enum": [
"low_value",
"transaction_risk_analysis"
]
},
"SdkInformation": {
"type": "object",
"description": "SDK Information if request is from SDK",
Expand Down
40 changes: 40 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -17019,6 +17019,14 @@
"type": "boolean",
"description": "Whether to calculate tax for this payment intent",
"nullable": true
},
"psd2_sca_exemption_type": {
"allOf": [
{
"$ref": "#/components/schemas/ScaExemptionType"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -17389,6 +17397,14 @@
"type": "boolean",
"description": "Whether to calculate tax for this payment intent",
"nullable": true
},
"psd2_sca_exemption_type": {
"allOf": [
{
"$ref": "#/components/schemas/ScaExemptionType"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -18583,6 +18599,14 @@
"type": "boolean",
"description": "Whether to calculate tax for this payment intent",
"nullable": true
},
"psd2_sca_exemption_type": {
"allOf": [
{
"$ref": "#/components/schemas/ScaExemptionType"
}
],
"nullable": true
}
},
"additionalProperties": false
Expand Down Expand Up @@ -19616,6 +19640,14 @@
"type": "boolean",
"description": "Whether to calculate tax for this payment intent",
"nullable": true
},
"psd2_sca_exemption_type": {
"allOf": [
{
"$ref": "#/components/schemas/ScaExemptionType"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -23284,6 +23316,14 @@
}
}
},
"ScaExemptionType": {
"type": "string",
"description": "SCA Exemptions types available for authentication",
"enum": [
"low_value",
"transaction_risk_analysis"
]
},
"SdkInformation": {
"type": "object",
"description": "SDK Information if request is from SDK",
Expand Down
4 changes: 4 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ pub struct PaymentsRequest {

/// Whether to calculate tax for this payment intent
pub skip_external_tax_calculation: Option<bool>,

/// Choose what kind of sca exemption is required for this payment
#[schema(value_type = Option<ScaExemptionType>)]
pub psd2_sca_exemption_type: Option<api_enums::ScaExemptionType>,
}

#[cfg(feature = "v1")]
Expand Down
25 changes: 24 additions & 1 deletion crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod diesel_exports {
DbMandateStatus as MandateStatus, DbPaymentMethodIssuerCode as PaymentMethodIssuerCode,
DbPaymentType as PaymentType, DbRefundStatus as RefundStatus,
DbRequestIncrementalAuthorization as RequestIncrementalAuthorization,
DbWebhookDeliveryAttempt as WebhookDeliveryAttempt,
DbScaExemptionType as ScaExemptionType, DbWebhookDeliveryAttempt as WebhookDeliveryAttempt,
};
}

Expand Down Expand Up @@ -1668,6 +1668,29 @@ pub enum PaymentType {
RecurringMandate,
}

/// SCA Exemptions types available for authentication
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "db_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum ScaExemptionType {
#[default]
LowValue,
TransactionRiskAnalysis,
}

#[derive(
Clone,
Copy,
Expand Down
6 changes: 3 additions & 3 deletions crates/diesel_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub mod diesel_exports {
DbRefundStatus as RefundStatus, DbRefundType as RefundType,
DbRequestIncrementalAuthorization as RequestIncrementalAuthorization,
DbRoleScope as RoleScope, DbRoutingAlgorithmKind as RoutingAlgorithmKind,
DbTotpStatus as TotpStatus, DbTransactionType as TransactionType,
DbUserRoleVersion as UserRoleVersion, DbUserStatus as UserStatus,
DbWebhookDeliveryAttempt as WebhookDeliveryAttempt,
DbScaExemptionType as ScaExemptionType, DbTotpStatus as TotpStatus,
DbTransactionType as TransactionType, DbUserRoleVersion as UserRoleVersion,
DbUserStatus as UserStatus, DbWebhookDeliveryAttempt as WebhookDeliveryAttempt,
};
}
pub use common_enums::*;
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub struct PaymentIntent {
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub payment_link_config: Option<PaymentLinkConfigRequestForPayments>,
pub id: common_utils::id_type::GlobalPaymentId,
pub psd2_sca_exemption_type: Option<storage_enums::ScaExemptionType>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -136,6 +137,7 @@ pub struct PaymentIntent {
pub organization_id: common_utils::id_type::OrganizationId,
pub tax_details: Option<TaxDetails>,
pub skip_external_tax_calculation: Option<bool>,
pub psd2_sca_exemption_type: Option<storage_enums::ScaExemptionType>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
Expand Down Expand Up @@ -352,6 +354,7 @@ pub struct PaymentIntentNew {
pub organization_id: common_utils::id_type::OrganizationId,
pub tax_details: Option<TaxDetails>,
pub skip_external_tax_calculation: Option<bool>,
pub psd2_sca_exemption_type: Option<storage_enums::ScaExemptionType>,
}

#[cfg(feature = "v2")]
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ diesel::table! {
organization_id -> Varchar,
tax_details -> Nullable<Jsonb>,
skip_external_tax_calculation -> Nullable<Bool>,
psd2_sca_exemption_type -> Nullable<ScaExemptionType>,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ diesel::table! {
payment_link_config -> Nullable<Jsonb>,
#[max_length = 64]
id -> Varchar,
psd2_sca_exemption_type -> Nullable<ScaExemptionType>,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/hyperswitch_domain_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub struct PaymentIntent {
pub organization_id: id_type::OrganizationId,
pub tax_details: Option<TaxDetails>,
pub skip_external_tax_calculation: Option<bool>,
pub psd2_sca_exemption_type: Option<storage_enums::ScaExemptionType>,
}

impl PaymentIntent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ impl behaviour::Conversion for PaymentIntent {
customer_present: Some(customer_present.as_bool()),
payment_link_config,
routing_algorithm_id,
psd2_sca_exemption_type: None,
})
}
async fn convert_back(
Expand Down Expand Up @@ -1551,6 +1552,7 @@ impl behaviour::Conversion for PaymentIntent {
shipping_cost: self.shipping_cost,
tax_details: self.tax_details,
skip_external_tax_calculation: self.skip_external_tax_calculation,
psd2_sca_exemption_type: self.psd2_sca_exemption_type,
})
}

Expand Down Expand Up @@ -1638,6 +1640,7 @@ impl behaviour::Conversion for PaymentIntent {
is_payment_processor_token_flow: storage_model.is_payment_processor_token_flow,
organization_id: storage_model.organization_id,
skip_external_tax_calculation: storage_model.skip_external_tax_calculation,
psd2_sca_exemption_type: storage_model.psd2_sca_exemption_type,
})
}
.await
Expand Down Expand Up @@ -1700,6 +1703,7 @@ impl behaviour::Conversion for PaymentIntent {
shipping_cost: self.shipping_cost,
tax_details: self.tax_details,
skip_external_tax_calculation: self.skip_external_tax_calculation,
psd2_sca_exemption_type: self.psd2_sca_exemption_type,
})
}
}
3 changes: 3 additions & 0 deletions crates/hyperswitch_domain_models/src/router_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ pub struct RouterData<Flow, Request, Response> {
pub header_payload: Option<payments::HeaderPayload>,

pub connector_mandate_request_reference_id: Option<String>,

/// Contains the type of sca exemption required for the transaction
pub psd2_sca_exemption_type: Option<common_enums::ScaExemptionType>,
}

// Different patterns of authentication.
Expand Down
1 change: 1 addition & 0 deletions crates/openapi/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::admin::AcceptedCountries,
api_models::admin::AcceptedCurrencies,
api_models::enums::PaymentType,
api_models::enums::ScaExemptionType,
api_models::enums::PaymentMethod,
api_models::enums::PaymentMethodType,
api_models::enums::ConnectorType,
Expand Down
1 change: 1 addition & 0 deletions crates/openapi/src/openapi_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::admin::AcceptedCurrencies,
api_models::enums::ProductType,
api_models::enums::PaymentType,
api_models::enums::ScaExemptionType,
api_models::enums::PaymentMethod,
api_models::enums::PaymentMethodType,
api_models::enums::ConnectorType,
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub async fn perform_authentication(
email: Option<common_utils::pii::Email>,
webhook_url: String,
three_ds_requestor_url: String,
psd2_sca_exemption_type: Option<common_enums::ScaExemptionType>,
) -> CustomResult<api::authentication::AuthenticationResponse, ApiErrorResponse> {
let router_data = transformers::construct_authentication_router_data(
merchant_id,
Expand All @@ -60,6 +61,7 @@ pub async fn perform_authentication(
email,
webhook_url,
three_ds_requestor_url,
psd2_sca_exemption_type,
)?;
let response = Box::pin(utils::do_auth_connector_call(
state,
Expand Down
6 changes: 6 additions & 0 deletions crates/router/src/core/authentication/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn construct_authentication_router_data(
email: Option<common_utils::pii::Email>,
webhook_url: String,
three_ds_requestor_url: String,
psd2_sca_exemption_type: Option<common_enums::ScaExemptionType>,
) -> RouterResult<types::authentication::ConnectorAuthenticationRouterData> {
let router_request = types::authentication::ConnectorAuthenticationRequestData {
payment_method_data,
Expand Down Expand Up @@ -70,6 +71,7 @@ pub fn construct_authentication_router_data(
types::PaymentAddress::default(),
router_request,
&merchant_connector_account,
psd2_sca_exemption_type,
)
}

Expand All @@ -94,6 +96,7 @@ pub fn construct_post_authentication_router_data(
types::PaymentAddress::default(),
router_request,
&merchant_connector_account,
None,
)
}

Expand All @@ -119,6 +122,7 @@ pub fn construct_pre_authentication_router_data<F: Clone>(
types::PaymentAddress::default(),
router_request,
merchant_connector_account,
None,
)
}

Expand All @@ -129,6 +133,7 @@ pub fn construct_router_data<F: Clone, Req, Res>(
address: types::PaymentAddress,
request_data: Req,
merchant_connector_account: &payments_helpers::MerchantConnectorAccountType,
psd2_sca_exemption_type: Option<common_enums::ScaExemptionType>,
) -> RouterResult<types::RouterData<F, Req, Res>> {
let test_mode: Option<bool> = merchant_connector_account.is_test_mode_on();
let auth_type: types::ConnectorAuthType = merchant_connector_account
Expand Down Expand Up @@ -185,6 +190,7 @@ pub fn construct_router_data<F: Clone, Req, Res>(
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
psd2_sca_exemption_type,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/fraud_check/flows/checkout_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
psd2_sca_exemption_type: None,
};

Ok(router_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub async fn construct_fulfillment_router_data<'a>(
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
psd2_sca_exemption_type: None,
};
Ok(router_data)
}
1 change: 1 addition & 0 deletions crates/router/src/core/fraud_check/flows/record_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
psd2_sca_exemption_type: None,
};

Ok(router_data)
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/fraud_check/flows/sale_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
psd2_sca_exemption_type: None,
};

Ok(router_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
psd2_sca_exemption_type: None,
};

Ok(router_data)
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/mandate/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub async fn construct_mandate_revoke_router_data(
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
psd2_sca_exemption_type: None,
};

Ok(router_data)
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6277,6 +6277,7 @@ pub async fn payment_external_authentication(
optional_customer.and_then(|customer| customer.email.map(pii::Email::from)),
webhook_url,
authentication_details.three_ds_requestor_url.clone(),
payment_intent.psd2_sca_exemption_type,
))
.await?;
Ok(services::ApplicationResponse::Json(
Expand Down
Loading

0 comments on commit 2b8eb09

Please sign in to comment.