Skip to content

Commit

Permalink
3ds
Browse files Browse the repository at this point in the history
  • Loading branch information
awasthi21 committed Sep 25, 2024
1 parent dec0a57 commit 35b85d5
Show file tree
Hide file tree
Showing 13 changed files with 389 additions and 46 deletions.
1 change: 1 addition & 0 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business-sandbox.cryptopay.me"
cybersource.base_url = "https://apitest.cybersource.com/"
datatrans.base_url = "https://api.sandbox.datatrans.com/"
datatrans.secondary_base_url = "https://pay.sandbox.datatrans.com/"
deutschebank.base_url = "https://testmerch.directpos.de/rest-api"
dlocal.base_url = "https://sandbox.dlocal.com/"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down
1 change: 1 addition & 0 deletions config/deployments/integration_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business-sandbox.cryptopay.me"
cybersource.base_url = "https://apitest.cybersource.com/"
datatrans.base_url = "https://api.sandbox.datatrans.com/"
datatrans.secondary_base_url = "https://pay.sandbox.datatrans.com/"
deutschebank.base_url = "https://testmerch.directpos.de/rest-api"
dlocal.base_url = "https://sandbox.dlocal.com/"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down
1 change: 1 addition & 0 deletions config/deployments/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business.cryptopay.me/"
cybersource.base_url = "https://api.cybersource.com/"
datatrans.base_url = "https://api.datatrans.com/"
datatrans.secondary_base_url = "https://pay.datatrans.com/"
dlocal.base_url = "https://sandbox.dlocal.com/"
deutschebank.base_url = "https://merch.directpos.de/rest-api"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down
1 change: 1 addition & 0 deletions config/deployments/sandbox.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business-sandbox.cryptopay.me"
cybersource.base_url = "https://apitest.cybersource.com/"
datatrans.base_url = "https://api.sandbox.datatrans.com/"
datatrans.secondary_base_url = "https://pay.sandbox.datatrans.com/"
dlocal.base_url = "https://sandbox.dlocal.com/"
deutschebank.base_url = "https://testmerch.directpos.de/rest-api"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down
1 change: 1 addition & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business-sandbox.cryptopay.me"
cybersource.base_url = "https://apitest.cybersource.com/"
datatrans.base_url = "https://api.sandbox.datatrans.com/"
datatrans.secondary_base_url = "https://pay.sandbox.datatrans.com/"
deutschebank.base_url = "https://testmerch.directpos.de/rest-api"
dlocal.base_url = "https://sandbox.dlocal.com/"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down
1 change: 1 addition & 0 deletions config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business-sandbox.cryptopay.me"
cybersource.base_url = "https://apitest.cybersource.com/"
datatrans.base_url = "https://api.sandbox.datatrans.com/"
datatrans.secondary_base_url = "https://pay.sandbox.datatrans.com/"
deutschebank.base_url = "https://testmerch.directpos.de/rest-api"
dlocal.base_url = "https://sandbox.dlocal.com/"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down
2 changes: 2 additions & 0 deletions crates/hyperswitch_domain_models/src/router_request_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub struct PaymentsIncrementalAuthorizationData {
pub currency: storage_enums::Currency,
pub reason: Option<String>,
pub connector_transaction_id: String,
pub minor_additional_amount: MinorUnit,
pub minor_total_amount: MinorUnit,
}

#[derive(Debug, Clone, Default)]
Expand Down
2 changes: 1 addition & 1 deletion crates/hyperswitch_interfaces/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Connectors {
pub coinbase: ConnectorParams,
pub cryptopay: ConnectorParams,
pub cybersource: ConnectorParams,
pub datatrans: ConnectorParams,
pub datatrans: ConnectorParamsWithSecondaryBaseUrl,
pub deutschebank: ConnectorParams,
pub dlocal: ConnectorParams,
#[cfg(feature = "dummy_connector")]
Expand Down
113 changes: 111 additions & 2 deletions crates/router/src/connector/datatrans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use api_models::enums::{CaptureMethod, PaymentMethodType};
use base64::Engine;
use common_utils::types::{AmountConvertor, MinorUnit, MinorUnitForConnector};
use error_stack::{report, ResultExt};
use hyperswitch_connectors::utils::RouterData;
use masking::PeekInterface;
use transformers::{self as datatrans};

Expand Down Expand Up @@ -31,6 +32,7 @@ impl api::PaymentSession for Datatrans {}
impl api::ConnectorAccessToken for Datatrans {}
impl api::MandateSetup for Datatrans {}
impl api::PaymentAuthorize for Datatrans {}
impl api::PaymentIncrementalAuthorization for Datatrans {}
impl api::PaymentSync for Datatrans {}
impl api::PaymentCapture for Datatrans {}
impl api::PaymentVoid for Datatrans {}
Expand Down Expand Up @@ -193,11 +195,15 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P

fn get_url(
&self,
_req: &types::PaymentsAuthorizeRouterData,
req: &types::PaymentsAuthorizeRouterData,
connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
let base_url = self.base_url(connectors);
Ok(format!("{base_url}v1/transactions/authorize"))
if req.is_three_ds() {
Ok(format!("{base_url}v1/transactions"))
} else {
Ok(format!("{base_url}v1/transactions/authorize"))
}
}

fn get_request_body(
Expand Down Expand Up @@ -685,3 +691,106 @@ impl api::IncomingWebhook for Datatrans {
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
}
}

impl
ConnectorIntegration<
api::IncrementalAuthorization,
types::PaymentsIncrementalAuthorizationData,
types::PaymentsResponseData,
> for Datatrans
{
fn get_headers(
&self,
req: &types::PaymentsIncrementalAuthorizationRouterData,
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_request_body(
&self,
req: &types::PaymentsIncrementalAuthorizationRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
let amount = connector_utils::convert_amount(
self.amount_converter,
req.request.minor_additional_amount,
req.request.currency,
)?;
let connector_router_data = datatrans::DatatransRouterData::try_from((amount, req))?;
let connector_request =
datatrans::DatatransIncrementalAuthorizationPaymentRequest::try_from(
&connector_router_data,
)?;
Ok(RequestContent::Json(Box::new(connector_request)))
}
fn get_url(
&self,
req: &types::PaymentsIncrementalAuthorizationRouterData,
connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
let connector_payment_id = req.request.connector_transaction_id.clone();
let base_url = self.base_url(connectors);
Ok(format!(
"{base_url}v1/transactions/{connector_payment_id}/increase"
))
}

fn build_request(
&self,
req: &types::PaymentsIncrementalAuthorizationRouterData,
connectors: &settings::Connectors,
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
Ok(Some(
services::RequestBuilder::new()
.method(services::Method::Post)
.url(&types::IncrementalAuthorizationType::get_url(
self, req, connectors,
)?)
.attach_default_headers()
.headers(types::IncrementalAuthorizationType::get_headers(
self, req, connectors,
)?)
.set_body(types::IncrementalAuthorizationType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
fn handle_response(
&self,
data: &types::PaymentsIncrementalAuthorizationRouterData,
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<
types::RouterData<
api::IncrementalAuthorization,
types::PaymentsIncrementalAuthorizationData,
types::PaymentsResponseData,
>,
errors::ConnectorError,
> {
let response: datatrans::DatatransIncrementalAuthorizationResponse = res
.response
.parse_struct("Datatrans DatatransIncrementalAuthorizationResponse")
.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,
})
.change_context(errors::ConnectorError::ResponseHandlingFailed)
}
fn get_error_response(
&self,
res: Response,
event_builder: Option<&mut ConnectorEvent>,
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
self.build_error_response(res, event_builder)
}
}
Loading

0 comments on commit 35b85d5

Please sign in to comment.