Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(connector): implement pre auth flow for gpayments (#4692)

Hrithikeshbed42ce4be90
diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rs
index 4d5b709bba..91ac15a9e4 100644
--- a/crates/api_models/src/enums.rs
+++ b/crates/api_models/src/enums.rs
@@ -95,7 +95,7 @@ pub enum Connector {
Globalpay,
Globepay,
Gocardless,
- // Gpayments, Added as template code for future usage
+ Gpayments,
Helcim,
Iatapay,
Klarna,
@@ -210,7 +210,7 @@ impl Connector {
| Self::Globalpay
| Self::Globepay
| Self::Gocardless
- // | Self::Gpayments Added as template code for future usage
+ | Self::Gpayments
| Self::Helcim
| Self::Iatapay
| Self::Klarna
diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs
index f02f5e61c3..845307bee4 100644
--- a/crates/connector_configs/src/connector.rs
+++ b/crates/connector_configs/src/connector.rs
@@ -282,7 +282,7 @@ impl ConnectorConfig {
Connector::Globalpay => Ok(connector_data.globalpay),
Connector::Globepay => Ok(connector_data.globepay),
Connector::Gocardless => Ok(connector_data.gocardless),
- // Connector::Gpayments => Ok(connector_data.gpayments), Added as template code for future usage
+ Connector::Gpayments => Ok(connector_data.gpayments),
Connector::Helcim => Ok(connector_data.helcim),
Connector::Klarna => Ok(connector_data.klarna),
Connector::Mollie => Ok(connector_data.mollie),
diff --git a/crates/diesel_models/src/authentication.rs b/crates/diesel_models/src/authentication.rs
index 71a16dcb86..09e495241f 100644
--- a/crates/diesel_models/src/authentication.rs
+++ b/crates/diesel_models/src/authentication.rs
@@ -94,6 +94,18 @@ pub struct AuthenticationNew {
#[derive(Debug)]
pub enum AuthenticationUpdate {
+ PreAuthenticationVersionCallUpdate {
+ maximum_supported_3ds_version: common_utils::types::SemanticVersion,
+ message_version: common_utils::types::SemanticVersion,
+ },
+ PreAuthenticationThreeDsMethodCall {
+ threeds_server_transaction_id: String,
+ three_ds_method_data: Option<String>,
+ three_ds_method_url: Option<String>,
+ acquirer_bin: Option<String>,
+ acquirer_merchant_id: Option<String>,
+ connector_metadata: Option<serde_json::Value>,
+ },
PreAuthenticationUpdate {
threeds_server_transaction_id: String,
maximum_supported_3ds_version: common_utils::types::SemanticVersion,
@@ -116,6 +128,7 @@ pub enum AuthenticationUpdate {
acs_reference_number: Option<String>,
acs_trans_id: Option<String>,
acs_signed_content: Option<String>,
+ connector_metadata: Option<serde_json::Value>,
authentication_status: common_enums::AuthenticationStatus,
ds_trans_id: Option<String>,
},
@@ -283,7 +296,6 @@ impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {
error_code,
error_message,
authentication_status: Some(authentication_status),
-
connector_authentication_id,
authentication_type: None,
authentication_lifecycle_status: None,
@@ -342,6 +354,7 @@ impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {
acs_reference_number,
acs_trans_id,
acs_signed_content,
+ connector_metadata,
authentication_status,
ds_trans_id,
} => Self {
@@ -353,6 +366,7 @@ impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {
acs_reference_number,
acs_trans_id,
acs_signed_content,
+ connector_metadata,
authentication_status: Some(authentication_status),
ds_trans_id,
..Default::default()
@@ -369,6 +383,30 @@ impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {
authentication_status: Some(authentication_status),
..Default::default()
},
+ AuthenticationUpdate::PreAuthenticationVersionCallUpdate {
+ maximum_supported_3ds_version,
+ message_version,
+ } => Self {
+ maximum_supported_version: Some(maximum_supported_3ds_version),
+ message_version: Some(message_version),
+ ..Default::default()
+ },
+ AuthenticationUpdate::PreAuthenticationThreeDsMethodCall {
+ threeds_server_transaction_id,
+ three_ds_method_data,
+ three_ds_method_url,
+ acquirer_bin,
+ acquirer_merchant_id,
+ connector_metadata,
+ } => Self {
+ threeds_server_transaction_id: Some(threeds_server_transaction_id),
+ three_ds_method_data,
+ three_ds_method_url,
+ acquirer_bin,
+ acquirer_merchant_id,
+ connector_metadata,
+ ..Default::default()
+ },
}
}
}
diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rs
index 57d579e1a0..b61a60ecd3 100644
--- a/crates/hyperswitch_domain_models/src/router_response_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_response_types.rs
@@ -2,7 +2,7 @@ pub mod disputes;
pub mod fraud_check;
use std::collections::HashMap;
-use common_utils::{request::Method, types::MinorUnit};
+use common_utils::{request::Method, types as common_types, types::MinorUnit};
pub use disputes::{AcceptDisputeResponse, DefendDisputeResponse, SubmitEvidenceResponse};
use crate::router_request_types::{authentication::AuthNFlowType, ResponseId};
@@ -205,6 +205,15 @@ pub struct MandateRevokeResponseData {
#[derive(Debug, Clone)]
pub enum AuthenticationResponseData {
+ PreAuthVersionCallResponse {
+ maximum_supported_3ds_version: common_types::SemanticVersion,
+ },
+ PreAuthThreeDsMethodCallResponse {
+ threeds_server_transaction_id: String,
+ three_ds_method_data: Option<String>,
+ three_ds_method_url: Option<String>,
+ connector_metadata: Option<serde_json::Value>,
+ },
PreAuthNResponse {
threeds_server_transaction_id: String,
maximum_supported_3ds_version: common_utils::types::SemanticVersion,
@@ -219,6 +228,7 @@ pub enum AuthenticationResponseData {
authn_flow_type: AuthNFlowType,
authentication_value: Option<String>,
trans_status: common_enums::TransactionStatus,
+ connector_metadata: Option<serde_json::Value>,
ds_trans_id: Option<String>,
},
PostAuthNResponse {
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index 144d6f0798..84af6dfdde 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -71,7 +71,7 @@ qrcode = "0.14.0"
rand = "0.8.5"
rand_chacha = "0.3.1"
regex = "1.10.4"
-reqwest = { version = "0.11.27", features = ["json", "native-tls", "gzip", "multipart"] }
+reqwest = { version = "0.11.27", features = ["json", "native-tls","__rustls", "gzip", "multipart"] }
ring = "0.17.8"
roxmltree = "0.19.0"
rust_decimal = { version = "1.35.0", features = ["serde-with-float", "serde-with-str"] }
diff --git a/crates/router/src/connector/gpayments.rs b/crates/router/src/connector/gpayments.rs
index 71c6a65e6d..4d72788a2d 100644
--- a/crates/router/src/connector/gpayments.rs
+++ b/crates/router/src/connector/gpayments.rs
@@ -1,20 +1,18 @@
+pub mod gpayments_types;
pub mod transformers;
use std::fmt::Debug;
+use common_utils::request::RequestContent;
use error_stack::{report, ResultExt};
-use masking::ExposeInterface;
use transformers as gpayments;
use crate::{
configs::settings,
core::errors::{self, CustomResult},
events::connector_api_logs::ConnectorEvent,
- headers,
- services::{
- request::{self, Mask},
- ConnectorIntegration, ConnectorValidation,
- },
+ headers, services,
+ services::{request, ConnectorIntegration, ConnectorValidation},
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
@@ -55,15 +53,13 @@ where
{
fn build_headers(
&self,
- req: &types::RouterData<Flow, Request, Response>,
+ _req: &types::RouterData<Flow, Request, Response>,
_connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
- let mut header = vec![(
+ let header = vec![(
headers::CONTENT_TYPE.to_string(),
self.get_content_type().to_string().into(),
)];
- let mut api_key = self.get_auth_header(&req.connector_auth_type)?;
- header.append(&mut api_key);
Ok(header)
}
}
@@ -90,14 +86,9 @@ impl ConnectorCommon for Gpayments {
fn get_auth_header(
&self,
- auth_type: &types::ConnectorAuthType,
+ _auth_type: &types::ConnectorAuthType,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
- let auth = gpayments::GpaymentsAuthType::try_from(auth_type)
- .change_context(errors::ConnectorError::FailedToObtainAuthType)?;
- Ok(vec![(
- headers::AUTHORIZATION.to_string(),
- auth.api_key.expose().into_masked(),
- )])
+ Ok(vec![])
}
fn build_error_response(
@@ -105,9 +96,9 @@ impl ConnectorCommon for Gpayments {
res: Response,
event_builder: Option<&mut ConnectorEvent>,
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
- let response: gpayments::GpaymentsErrorResponse = res
+ let response: gpayments_types::TDS2ApiError = res
.response
- .parse_struct("GpaymentsErrorResponse")
+ .parse_struct("gpayments_types TDS2ApiError")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
@@ -115,9 +106,9 @@ impl ConnectorCommon for Gpayments {
Ok(ErrorResponse {
status_code: res.status_code,
- code: response.code,
- message: response.message,
- reason: response.reason,
+ code: response.error_code,
+ message: response.error_description,
+ reason: response.error_detail,
attempt_status: None,
connector_transaction_id: None,
})
@@ -206,6 +197,16 @@ impl api::ConnectorAuthentication for Gpayments {}
impl api::ConnectorPreAuthentication for Gpayments {}
impl api::ConnectorPreAuthenticationVersionCall for Gpayments {}
impl api::ConnectorPostAuthentication for Gpayments {}
+
+fn build_endpoint(
+ base_url: &str,
+ connector_metadata: &Option<common_utils::pii::SecretSerdeValue>,
+) -> CustomResult<String, errors::ConnectorError> {
+ let metadata = gpayments::GpaymentsMetaData::try_from(connector_metadata)?;
+ let endpoint_prefix = metadata.endpoint_prefix;
+ Ok(base_url.replace("{{merchant_endpoint_prefix}}", &endpoint_prefix))
+}
+
impl
ConnectorIntegration<
api::Authentication,
@@ -214,27 +215,208 @@ impl
> for Gpayments
{
}
+
impl
ConnectorIntegration<
- api::PreAuthentication,
- types::authentication::PreAuthNRequestData,
+ api::PostAuthentication,
+ types::authentication::ConnectorPostAuthenticationRequestData,
types::authentication::AuthenticationResponseData,
> for Gpayments
{
}
+
impl
ConnectorIntegration<
- api::PreAuthenticationVersionCall,
+ api::PreAuthentication,
types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
> for Gpayments
{
+ fn get_headers(
+ &self,
+ req: &types::authentication::PreAuthNRouterData,
+ connectors: &settings::Connectors,
+ ) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ req: &types::authentication::PreAuthNRouterData,
+ connectors: &settings::Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ let base_url = build_endpoint(self.base_url(connectors), &req.connector_meta_data)?;
+ Ok(format!("{}/api/v2/auth/brw/init?mode=custom", base_url,))
+ }
+
+ fn get_request_body(
+ &self,
+ req: &types::authentication::PreAuthNRouterData,
+ _connectors: &settings::Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_router_data = gpayments::GpaymentsRouterData::try_from((0, req))?;
+ let req_obj =
+ gpayments_types::GpaymentsPreAuthenticationRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(req_obj)))
+ }
+
+ fn build_request(
+ &self,
+ req: &types::authentication::PreAuthNRouterData,
+ connectors: &settings::Connectors,
+ ) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
+ let gpayments_auth_type = gpayments::GpaymentsAuthType::try_from(&req.connector_auth_type)?;
+ Ok(Some(
+ services::RequestBuilder::new()
+ .method(services::Method::Post)
+ .url(
+ &types::authentication::ConnectorPreAuthenticationType::get_url(
+ self, req, connectors,
+ )?,
+ )
+ .attach_default_headers()
+ .headers(
+ types::authentication::ConnectorPreAuthenticationType::get_headers(
+ self, req, connectors,
+ )?,
+ )
+ .set_body(
+ types::authentication::ConnectorPreAuthenticationType::get_request_body(
+ self, req, connectors,
+ )?,
+ )
+ .add_certificate(Some(gpayments_auth_type.certificate))
+ .add_certificate_key(Some(gpayments_auth_type.private_key))
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &types::authentication::PreAuthNRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<types::authentication::PreAuthNRouterData, errors::ConnectorError> {
+ let response: gpayments_types::GpaymentsPreAuthenticationResponse = res
+ .response
+ .parse_struct("gpayments GpaymentsPreAuthenticationResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ types::RouterData::try_from(types::ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
}
impl
ConnectorIntegration<
- api::PostAuthentication,
- types::authentication::ConnectorPostAuthenticationRequestData,
+ api::PreAuthenticationVersionCall,
+ types::authentication::PreAuthNRequestData,
types::authentication::AuthenticationResponseData,
> for Gpayments
{
+ fn get_headers(
+ &self,
+ req: &types::authentication::PreAuthNVersionCallRouterData,
+ connectors: &settings::Connectors,
+ ) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ req: &types::authentication::PreAuthNVersionCallRouterData,
+ connectors: &settings::Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ let base_url = build_endpoint(self.base_url(connectors), &req.connector_meta_data)?;
+ Ok(format!("{}/api/v2/auth/enrol", base_url,))
+ }
+
+ fn get_request_body(
+ &self,
+ req: &types::authentication::PreAuthNVersionCallRouterData,
+ _connectors: &settings::Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_router_data = gpayments::GpaymentsRouterData::try_from((0, req))?;
+ let req_obj =
+ gpayments_types::GpaymentsPreAuthVersionCallRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(req_obj)))
+ }
+
+ fn build_request(
+ &self,
+ req: &types::authentication::PreAuthNVersionCallRouterData,
+ connectors: &settings::Connectors,
+ ) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
+ let gpayments_auth_type = gpayments::GpaymentsAuthType::try_from(&req.connector_auth_type)?;
+ Ok(Some(
+ services::RequestBuilder::new()
+ .method(services::Method::Post)
+ .url(
+ &types::authentication::ConnectorPreAuthenticationVersionCallType::get_url(
+ self, req, connectors,
+ )?,
+ )
+ .attach_default_headers()
+ .headers(
+ types::authentication::ConnectorPreAuthenticationVersionCallType::get_headers(
+ self, req, connectors,
+ )?,
+ )
+ .set_body(
+ types::authentication::ConnectorPreAuthenticationVersionCallType::get_request_body(
+ self, req, connectors,
+ )?,
+ )
+ .add_certificate(Some(gpayments_auth_type.certificate))
+ .add_certificate_key(Some(gpayments_auth_type.private_key))
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &types::authentication::PreAuthNVersionCallRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<types::authentication::PreAuthNVersionCallRouterData, errors::ConnectorError>
+ {
+ let response: gpayments_types::GpaymentsPreAuthVersionCallResponse = res
+ .response
+ .parse_struct("gpayments GpaymentsPreAuthVersionCallResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ types::RouterData::try_from(types::ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
}
diff --git a/crates/router/src/connector/gpayments/gpayments_types.rs b/crates/router/src/connector/gpayments/gpayments_types.rs
new file mode 100644
index 0000000000..c95e778bcb
--- /dev/null
+++ b/crates/router/src/connector/gpayments/gpayments_types.rs
@@ -0,0 +1,124 @@
+use cards::CardNumber;
+use common_utils::types;
+use masking::{Deserialize, Serialize};
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct GpaymentsConnectorMetaData {
+ pub authentication_url: String,
+ pub three_ds_requestor_trans_id: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+#[serde(rename_all = "camelCase")]
+pub struct GpaymentsPreAuthVersionCallRequest {
+ pub acct_number: CardNumber,
+ pub merchant_id: String,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+#[serde(rename_all = "camelCase")]
+pub struct GpaymentsPreAuthVersionCallResponse {
+ pub enrolment_status: EnrollmentStatus,
+ pub supported_message_versions: Option<Vec<types::SemanticVersion>>,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub enum EnrollmentStatus {
+ #[serde(rename = "00")]
+ NotEnrolled,
+ #[serde(rename = "01")]
+ Enrolled,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+#[serde(rename_all = "camelCase")]
+pub struct TDS2ApiError {
+ pub error_code: String,
+ pub error_component: Option<String>,
+ pub error_description: String,
+ pub error_detail: Option<String>,
+ pub error_message_type: Option<String>,
+ pub message_type: String,
+ pub message_version: Option<String>,
+ #[serde(rename = "sdkTransID")]
+ pub sdk_trans_id: Option<String>,
+ #[serde(rename = "threeDSServerTransID")]
+ pub three_ds_server_trans_id: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+#[serde(rename_all = "camelCase")]
+pub struct GpaymentsPreAuthenticationRequest {
+ pub acct_number: CardNumber,
+ pub card_scheme: Option<CardScheme>,
+ pub challenge_window_size: Option<ChallengeWindowSize>,
+
+ /// URL where the 3DS requestor receives events during authentication.
+ /// ActiveServer calls this URL through the iframe to notify events occurring during authentication.
+ ///
+ /// Example: "https://example.requestor.com/3ds-notify"
+ /// Length: Maximum 2000 characters
+ pub event_callback_url: String,
+
+ /// Merchant identifier assigned by the acquirer.
+ /// This may be the same value used in authorization requests sent on behalf of the 3DS Requestor.
+ ///
+ /// Example: "1234567890123456789012345678901234"
+ /// Length: Maximum 35 characters
+ pub merchant_id: String,
+
+ /// Optional boolean. If set to true, ActiveServer will not collect the browser information automatically.
+ /// The requestor must have a backend implementation to collect browser information.
+ pub skip_auto_browser_info_collect: Option<bool>,
+
+ /// Universal unique transaction identifier assigned by the 3DS Requestor to identify a single transaction.
+ ///
+ /// Example: "6afa6072-9412-446b-9673-2f98b3ee98a2"
+ /// Length: 36 characters
+ #[serde(rename = "threeDSRequestorTransID")]
+ pub three_ds_requestor_trans_id: String,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub enum ChallengeWindowSize {
+ #[serde(rename = "01")]
+ Size250x400,
+ #[serde(rename = "02")]
+ Size390x400,
+ #[serde(rename = "03")]
+ Size500x600,
+ #[serde(rename = "04")]
+ Size600x400,
+ #[serde(rename = "05")]
+ FullScreen,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+#[serde(rename_all = "UPPERCASE")]
+pub enum CardScheme {
+ Visa,
+ MasterCard,
+ AmericanExpress,
+ JCB,
+ Discover,
+ UnionPay,
+ Mir,
+ Eftpos,
+ BCard,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+#[serde(rename_all = "camelCase")]
+pub struct GpaymentsPreAuthenticationResponse {
+ pub auth_url: String,
+ pub mon_url: Option<String>,
+ pub resolved_card_scheme: Option<CardScheme>,
+ #[serde(rename = "threeDSMethodAvailable")]
+ pub three_ds_method_available: Option<bool>,
+ #[serde(rename = "threeDSMethodUrl")]
+ pub three_ds_method_url: Option<String>,
+ #[serde(rename = "threeDSServerCallbackUrl")]
+ pub three_ds_server_callback_url: Option<String>,
+ #[serde(rename = "threeDSServerTransID")]
+ pub three_ds_server_trans_id: String,
+}
diff --git a/crates/router/src/connector/gpayments/transformers.rs b/crates/router/src/connector/gpayments/transformers.rs
index 3ace928e23..ee98d26e38 100644
--- a/crates/router/src/connector/gpayments/transformers.rs
+++ b/crates/router/src/connector/gpayments/transformers.rs
@@ -1,7 +1,14 @@
+use error_stack::ResultExt;
use masking::Secret;
use serde::{Deserialize, Serialize};
-use crate::{core::errors, types};
+use super::gpayments_types;
+use crate::{
+ connector::utils,
+ consts,
+ core::errors,
+ types::{self, api},
+};
//TODO: Fill the struct with respective fields
pub struct GpaymentsRouterData<T> {
@@ -9,24 +16,9 @@ pub struct GpaymentsRouterData<T> {
pub router_data: T,
}
-impl<T>
- TryFrom<(
- &types::api::CurrencyUnit,
- types::storage::enums::Currency,
- i64,
- T,
- )> for GpaymentsRouterData<T>
-{
+impl<T> TryFrom<(i64, T)> for GpaymentsRouterData<T> {
type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(
- (_currency_unit, _currency, amount, item): (
- &types::api::CurrencyUnit,
- types::storage::enums::Currency,
- i64,
- T,
- ),
- ) -> Result<Self, Self::Error> {
- //Todo : use utils to convert the amount to the type of amount that a connector accepts
+ fn try_from((amount, item): (i64, T)) -> Result<Self, Self::Error> {
Ok(Self {
amount,
router_data: item,
@@ -37,21 +29,45 @@ impl<T>
//TODO: Fill the struct with respective fields
// Auth Struct
pub struct GpaymentsAuthType {
- pub(super) api_key: Secret<String>,
+ /// base64 encoded certificate
+ pub certificate: Secret<String>,
+ /// base64 encoded private_key
+ pub private_key: Secret<String>,
}
impl TryFrom<&types::ConnectorAuthType> for GpaymentsAuthType {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(auth_type: &types::ConnectorAuthType) -> Result<Self, Self::Error> {
- match auth_type {
- types::ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
- api_key: api_key.to_owned(),
+ match auth_type.to_owned() {
+ types::ConnectorAuthType::CertificateAuth {
+ certificate,
+ private_key,
+ } => Ok(Self {
+ certificate,
+ private_key,
}),
_ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
}
}
}
+impl TryFrom<&GpaymentsRouterData<&types::authentication::PreAuthNVersionCallRouterData>>
+ for gpayments_types::GpaymentsPreAuthVersionCallRequest
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+
+ fn try_from(
+ value: &GpaymentsRouterData<&types::authentication::PreAuthNVersionCallRouterData>,
+ ) -> Result<Self, Self::Error> {
+ let router_data = value.router_data;
+ let metadata = GpaymentsMetaData::try_from(&router_data.connector_meta_data)?;
+ Ok(Self {
+ acct_number: router_data.request.card_holder_account_number.clone(),
+ merchant_id: metadata.merchant_id,
+ })
+ }
+}
+
//TODO: Fill the struct with respective fields
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
pub struct GpaymentsErrorResponse {
@@ -60,3 +76,146 @@ pub struct GpaymentsErrorResponse {
pub message: String,
pub reason: Option<String>,
}
+
+#[derive(Deserialize, PartialEq)]
+pub struct GpaymentsMetaData {
+ pub endpoint_prefix: String,
+ pub merchant_id: String,
+}
+
+impl TryFrom<&Option<common_utils::pii::SecretSerdeValue>> for GpaymentsMetaData {
+ type Error = error_stack::Report<errors::ConnectorError>;
+
+ fn try_from(
+ meta_data: &Option<common_utils::pii::SecretSerdeValue>,
+ ) -> Result<Self, Self::Error> {
+ let metadata: Self = utils::to_connector_meta_from_secret::<Self>(meta_data.clone())
+ .change_context(errors::ConnectorError::InvalidConnectorConfig {
+ config: "metadata",
+ })?;
+ Ok(metadata)
+ }
+}
+
+impl
+ TryFrom<
+ types::ResponseRouterData<
+ api::PreAuthenticationVersionCall,
+ gpayments_types::GpaymentsPreAuthVersionCallResponse,
+ types::authentication::PreAuthNRequestData,
+ types::authentication::AuthenticationResponseData,
+ >,
+ > for types::authentication::PreAuthNVersionCallRouterData
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: types::ResponseRouterData<
+ api::PreAuthenticationVersionCall,
+ gpayments_types::GpaymentsPreAuthVersionCallResponse,
+ types::authentication::PreAuthNRequestData,
+ types::authentication::AuthenticationResponseData,
+ >,
+ ) -> Result<Self, Self::Error> {
+ let version_response = item.response;
+ let response = Ok(
+ types::authentication::AuthenticationResponseData::PreAuthVersionCallResponse {
+ maximum_supported_3ds_version: version_response
+ .supported_message_versions
+ .and_then(|supported_version| supported_version.iter().max().cloned()) // if no version is returned for the card number, then
+ .unwrap_or(common_utils::types::SemanticVersion::new(0, 0, 0)),
+ },
+ );
+ Ok(Self {
+ response,
+ ..item.data.clone()
+ })
+ }
+}
+
+impl TryFrom<&GpaymentsRouterData<&types::authentication::PreAuthNRouterData>>
+ for gpayments_types::GpaymentsPreAuthenticationRequest
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+
+ fn try_from(
+ value: &GpaymentsRouterData<&types::authentication::PreAuthNRouterData>,
+ ) -> Result<Self, Self::Error> {
+ let router_data = value.router_data;
+ let metadata = GpaymentsMetaData::try_from(&router_data.connector_meta_data)?;
+ Ok(Self {
+ acct_number: router_data.request.card_holder_account_number.clone(),
+ card_scheme: None,
+ challenge_window_size: Some(gpayments_types::ChallengeWindowSize::FullScreen),
+ // This is a required field but we don't listen to event callbacks
+ event_callback_url: "https://webhook.site/55e3db24-7c4e-4432-9941-d806f68d210b"
+ .to_string(),
+ merchant_id: metadata.merchant_id,
+ // Since this feature is not in our favour, hard coded it to true
+ skip_auto_browser_info_collect: Some(true),
+ // should auto generate this id.
+ three_ds_requestor_trans_id: uuid::Uuid::new_v4().hyphenated().to_string(),
+ })
+ }
+}
+
+impl
+ TryFrom<
+ types::ResponseRouterData<
+ api::PreAuthentication,
+ gpayments_types::GpaymentsPreAuthenticationResponse,
+ types::authentication::PreAuthNRequestData,
+ types::authentication::AuthenticationResponseData,
+ >,
+ > for types::authentication::PreAuthNRouterData
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: types::ResponseRouterData<
+ api::PreAuthentication,
+ gpayments_types::GpaymentsPreAuthenticationResponse,
+ types::authentication::PreAuthNRequestData,
+ types::authentication::AuthenticationResponseData,
+ >,
+ ) -> Result<Self, Self::Error> {
+ let threeds_method_response = item.response;
+ let three_ds_method_data = threeds_method_response
+ .three_ds_method_url
+ .as_ref()
+ .map(|_| {
+ let three_ds_method_data_json = serde_json::json!({
+ "threeDSServerTransID": threeds_method_response.three_ds_server_trans_id,
+ "threeDSMethodNotificationURL": "https://webhook.site/bd06863d-82c2-42ea-b35b-5ffd5ecece71"
+ });
+ serde_json::to_string(&three_ds_method_data_json)
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)
+ .attach_printable("error while constructing three_ds_method_data_str")
+ .map(|three_ds_method_data_string| {
+ base64::Engine::encode(&consts::BASE64_ENGINE, three_ds_method_data_string)
+ })
+ })
+ .transpose()?;
+ let connector_metadata = Some(serde_json::json!(
+ gpayments_types::GpaymentsConnectorMetaData {
+ authentication_url: threeds_method_response.auth_url,
+ three_ds_requestor_trans_id: None,
+ }
+ ));
+ let response: Result<
+ types::authentication::AuthenticationResponseData,
+ types::ErrorResponse,
+ > = Ok(
+ types::authentication::AuthenticationResponseData::PreAuthThreeDsMethodCallResponse {
+ threeds_server_transaction_id: threeds_method_response
+ .three_ds_server_trans_id
+ .clone(),
+ three_ds_method_data,
+ three_ds_method_url: threeds_method_response.three_ds_method_url,
+ connector_metadata,
+ },
+ );
+ Ok(Self {
+ response,
+ ..item.data.clone()
+ })
+ }
+}
diff --git a/crates/router/src/connector/netcetera/transformers.rs b/crates/router/src/connector/netcetera/transformers.rs
index 25ed7c5271..2da08c402c 100644
--- a/crates/router/src/connector/netcetera/transformers.rs
+++ b/crates/router/src/connector/netcetera/transformers.rs
@@ -167,6 +167,7 @@ impl
authn_flow_type,
authentication_value: response.authentication_value,
trans_status: response.trans_status,
+ connector_metadata: None,
ds_trans_id: response.authentication_response.ds_trans_id,
},
)
diff --git a/crates/router/src/connector/threedsecureio/transformers.rs b/crates/router/src/connector/threedsecureio/transformers.rs
index 242d0dee94..140cef0fbc 100644
--- a/crates/router/src/connector/threedsecureio/transformers.rs
+++ b/crates/router/src/connector/threedsecureio/transformers.rs
@@ -187,6 +187,7 @@ impl
types::authentication::AuthNFlowType::Frictionless
},
authentication_value: response.authentication_value,
+ connector_metadata: None,
ds_trans_id: Some(response.ds_trans_id),
},
)
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 459da09f47..786952e3ee 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -1933,10 +1933,11 @@ pub(crate) fn validate_auth_and_metadata_type(
gocardless::transformers::GocardlessAuthType::try_from(val)?;
Ok(())
}
- // api_enums::Connector::Gpayments => {
- // gpayments::transformers::GpaymentsAuthType::try_from(val)?;
- // Ok(())
- // } Added as template code for future usage
+ api_enums::Connector::Gpayments => {
+ gpayments::transformers::GpaymentsAuthType::try_from(val)?;
+ gpayments::transformers::GpaymentsMetaData::try_from(connector_meta_data)?;
+ Ok(())
+ }
api_enums::Connector::Helcim => {
helcim::transformers::HelcimAuthType::try_from(val)?;
Ok(())
diff --git a/crates/router/src/core/authentication/utils.rs b/crates/router/src/core/authentication/utils.rs
index f67f66bfff..c2285b6de4 100644
--- a/crates/router/src/core/authentication/utils.rs
+++ b/crates/router/src/core/authentication/utils.rs
@@ -84,6 +84,7 @@ pub async fn update_trackers<F: Clone, Req>(
authn_flow_type,
authentication_value,
trans_status,
+ connector_metadata,
ds_trans_id,
} => {
let authentication_status =
@@ -98,6 +99,7 @@ pub async fn update_trackers<F: Clone, Req>(
acs_signed_content: authn_flow_type.get_acs_signed_content(),
authentication_type: authn_flow_type.get_decoupled_authentication_type(),
authentication_status,
+ connector_metadata,
ds_trans_id,
}
}
@@ -113,6 +115,28 @@ pub async fn update_trackers<F: Clone, Req>(
authentication_value,
eci,
},
+ AuthenticationResponseData::PreAuthVersionCallResponse {
+ maximum_supported_3ds_version,
+ } => storage::AuthenticationUpdate::PreAuthenticationVersionCallUpdate {
+ message_version: maximum_supported_3ds_version.clone(),
+ maximum_supported_3ds_version,
+ },
+ AuthenticationResponseData::PreAuthThreeDsMethodCallResponse {
+ threeds_server_transaction_id,
+ three_ds_method_data,
+ three_ds_method_url,
+ connector_metadata,
+ } => storage::AuthenticationUpdate::PreAuthenticationThreeDsMethodCall {
+ threeds_server_transaction_id,
+ three_ds_method_data,
+ three_ds_method_url,
+ connector_metadata,
+ acquirer_bin: acquirer_details
+ .as_ref()
+ .map(|acquirer_details| acquirer_details.acquirer_bin.clone()),
+ acquirer_merchant_id: acquirer_details
+ .map(|acquirer_details| acquirer_details.acquirer_merchant_id),
+ },
},
Err(error) => storage::AuthenticationUpdate::ErrorUpdate {
connector_authentication_id: error.connector_transaction_id,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 6e3f6a9bf6..e55f5a2778 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -90,6 +90,19 @@ pub fn create_identity_from_certificate_and_key(
.change_context(errors::ApiClientError::CertificateDecodeFailed)
}
+pub fn create_certificate(
+ encoded_certificate: masking::Secret<String>,
+) -> Result<Vec<reqwest::Certificate>, error_stack::Report<errors::ApiClientError>> {
+ let decoded_certificate = BASE64_ENGINE
+ .decode(encoded_certificate.expose())
+ .change_context(errors::ApiClientError::CertificateDecodeFailed)?;
+
+ let certificate = String::from_utf8(decoded_certificate)
+ .change_context(errors::ApiClientError::CertificateDecodeFailed)?;
+ reqwest::Certificate::from_pem_bundle(certificate.as_bytes())
+ .change_context(errors::ApiClientError::CertificateDecodeFailed)
+}
+
pub fn filter_mca_based_on_business_profile(
merchant_connector_accounts: Vec<domain::MerchantConnectorAccount>,
profile_id: Option<String>,
diff --git a/crates/router/src/services/api/client.rs b/crates/router/src/services/api/client.rs
index ae45a2a7fc..d6c55baf60 100644
--- a/crates/router/src/services/api/client.rs
+++ b/crates/router/src/services/api/client.rs
@@ -91,10 +91,15 @@ pub(super) fn create_client(
let client_builder = get_client_builder(proxy_config, should_bypass_proxy)?;
let identity = payments::helpers::create_identity_from_certificate_and_key(
- encoded_certificate,
+ encoded_certificate.clone(),
encoded_certificate_key,
)?;
-
+ let certificate_list = payments::helpers::create_certificate(encoded_certificate)?;
+ let client_builder = certificate_list
+ .into_iter()
+ .fold(client_builder, |client_builder, certificate| {
+ client_builder.add_root_certificate(certificate)
+ });
client_builder
.identity(identity)
.build()
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index aea5e326cf..1de3cc3489 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -395,7 +395,7 @@ impl ConnectorData {
| enums::Connector::Plaid
| enums::Connector::Riskified
| enums::Connector::Threedsecureio
- // | enums::Connector::Gpayments Added as template code for future usage
+ | enums::Connector::Gpayments
| enums::Connector::Netcetera => {
Err(report!(errors::ConnectorError::InvalidConnectorName)
.attach_printable(format!("invalid connector name: {connector_name}")))
diff --git a/crates/router/src/types/authentication.rs b/crates/router/src/types/authentication.rs
index 2ca918f76f..6da423764d 100644
--- a/crates/router/src/types/authentication.rs
+++ b/crates/router/src/types/authentication.rs
@@ -41,3 +41,9 @@ pub type ConnectorPreAuthenticationType = dyn services::ConnectorIntegration<
PreAuthNRequestData,
AuthenticationResponseData,
>;
+
+pub type ConnectorPreAuthenticationVersionCallType = dyn services::ConnectorIntegration<
+ api::PreAuthenticationVersionCall,
+ PreAuthNRequestData,
+ AuthenticationResponseData,
+>;
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 400c2f9981..2420fb568c 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -230,11 +230,11 @@ impl ForeignTryFrom<api_enums::Connector> for common_enums::RoutableConnectors {
api_enums::Connector::Globalpay => Self::Globalpay,
api_enums::Connector::Globepay => Self::Globepay,
api_enums::Connector::Gocardless => Self::Gocardless,
- // api_enums::Connector::Gpayments => {
- // Err(common_utils::errors::ValidationError::InvalidValue {
- // message: "gpayments is not a routable connector".to_string(),
- // })?
- // }Added as template code for future usage
+ api_enums::Connector::Gpayments => {
+ Err(common_utils::errors::ValidationError::InvalidValue {
+ message: "gpayments is not a routable connector".to_string(),
+ })?
+ }
api_enums::Connector::Helcim => Self::Helcim,
api_enums::Connector::Iatapay => Self::Iatapay,
api_enums::Connector::Klarna => Self::Klarna,
diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json
index 4ee0e58c77..62e7487503 100644
--- a/openapi/openapi_spec.json
+++ b/openapi/openapi_spec.json
@@ -7421,6 +7421,7 @@
"globalpay",
"globepay",
"gocardless",
+ "gpayments",
"helcim",
"iatapay",
"klarna",