Skip to content

Commit

Permalink
mandates support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrudul Vajpayee authored and Mrudul Vajpayee committed Nov 8, 2024
1 parent 01951de commit 05708e2
Show file tree
Hide file tree
Showing 3 changed files with 305 additions and 63 deletions.
57 changes: 43 additions & 14 deletions crates/hyperswitch_connectors/src/connectors/nexixpay.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod transformers;
use std::collections::HashSet;

use common_enums::enums;
use common_utils::{
Expand All @@ -9,6 +10,7 @@ use common_utils::{
};
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::{
payment_method_data::PaymentMethodData,
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::{
access_token_auth::AccessTokenAuth,
Expand Down Expand Up @@ -46,7 +48,7 @@ use uuid::Uuid;
use crate::{
constants::headers,
types::ResponseRouterData,
utils::{self, RefundsRequestData},
utils::{self, PaymentMethodDataType, PaymentsAuthorizeRequestData, RefundsRequestData},
};

#[derive(Clone)]
Expand Down Expand Up @@ -212,6 +214,15 @@ impl ConnectorValidation for Nexixpay {
),
}
}
fn validate_mandate_payment(
&self,
pm_type: Option<enums::PaymentMethodType>,
pm_data: PaymentMethodData,
) -> CustomResult<(), errors::ConnectorError> {
let mandate_supported_pmd: HashSet<PaymentMethodDataType> =
HashSet::from([PaymentMethodDataType::Card]);
utils::is_mandate_supported(pm_data, pm_type, mandate_supported_pmd, self.id())
}
}

impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for Nexixpay {}
Expand Down Expand Up @@ -415,10 +426,14 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData

fn get_url(
&self,
_req: &PaymentsAuthorizeRouterData,
req: &PaymentsAuthorizeRouterData,
connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
Ok(format!("{}/orders/3steps/init", self.base_url(connectors)))
if req.request.connector_mandate_id().is_none() {
Ok(format!("{}/orders/3steps/init", self.base_url(connectors)))
} else {
Ok(format!("{}/orders/mit", self.base_url(connectors)))
}
}

fn get_request_body(
Expand Down Expand Up @@ -465,17 +480,31 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<PaymentsAuthorizeRouterData, errors::ConnectorError> {
let response: nexixpay::NexixpayPaymentsResponse = res
.response
.parse_struct("NexixpayPaymentsResponse")
.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: nexixpay::NexixpayPaymentsResponse = res
.response
.parse_struct("NexixpayPaymentsResponse")
.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: nexixpay::NexixpayMandateResponse = res
.response
.parse_struct("NexixpayMandateResponse")
.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

0 comments on commit 05708e2

Please sign in to comment.