Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(connector): [DEUTSCHEBANK] Implement SEPA recurring payments #5925

Merged
merged 12 commits into from
Sep 20, 2024
1 change: 1 addition & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ pub struct ConnectorMandateReferenceId {
pub connector_mandate_id: Option<String>,
pub payment_method_id: Option<String>,
pub update_history: Option<Vec<UpdateHistory>>,
pub mandate_metadata: Option<serde_json::Value>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]
Expand Down
74 changes: 57 additions & 17 deletions crates/hyperswitch_connectors/src/connectors/deutschebank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ use transformers as deutschebank;
use crate::{
constants::headers,
types::ResponseRouterData,
utils::{self, PaymentsCompleteAuthorizeRequestData, RefundsRequestData},
utils::{
self, PaymentsAuthorizeRequestData, PaymentsCompleteAuthorizeRequestData,
RefundsRequestData,
},
};

#[derive(Clone)]
Expand Down Expand Up @@ -182,6 +185,16 @@ impl ConnectorValidation for Deutschebank {
),
}
}

fn validate_mandate_payment(
&self,
pm_type: Option<enums::PaymentMethodType>,
pm_data: hyperswitch_domain_models::payment_method_data::PaymentMethodData,
) -> CustomResult<(), errors::ConnectorError> {
let mandate_supported_pmd =
std::collections::HashSet::from([utils::PaymentMethodDataType::SepaBankDebit]);
utils::is_mandate_supported(pm_data, pm_type, mandate_supported_pmd, self.id())
}
}

impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for Deutschebank {
Expand Down Expand Up @@ -302,13 +315,26 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData

fn get_url(
&self,
_req: &PaymentsAuthorizeRouterData,
req: &PaymentsAuthorizeRouterData,
connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
Ok(format!(
"{}/services/v2.1/managedmandate",
self.base_url(connectors)
))
if req.request.connector_mandate_id().is_none() {
Ok(format!(
"{}/services/v2.1/managedmandate",
self.base_url(connectors)
))
} else {
let event_id = req.connector_request_reference_id.clone();
let tx_action = if req.request.is_auto_capture()? {
"authorization"
} else {
"preauthorization"
};
Ok(format!(
"{}/services/v2.1/payment/event/{event_id}/directdebit/{tx_action}",
self.base_url(connectors)
))
}
}

fn get_request_body(
Expand Down Expand Up @@ -356,17 +382,31 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<PaymentsAuthorizeRouterData, errors::ConnectorError> {
let response: deutschebank::DeutschebankMandatePostResponse = res
.response
.parse_struct("Deutschebank PaymentsAuthorizeResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
})
if data.request.connector_mandate_id().is_none() {
let response: deutschebank::DeutschebankMandatePostResponse = res
.response
.parse_struct("DeutschebankMandatePostResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
})
} else {
let response: deutschebank::DeutschebankPaymentsResponse = res
.response
.parse_struct("DeutschebankPaymentsAuthorizeResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
})
}
}

fn get_error_response(
Expand Down
Loading
Loading