Skip to content

Commit

Permalink
feat(connector): [AUTHORIZEDOTNET] Implement zero mandates (#4704)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshu-iiitu authored May 22, 2024
1 parent 78d6278 commit 8afeda5
Show file tree
Hide file tree
Showing 2 changed files with 421 additions and 128 deletions.
88 changes: 76 additions & 12 deletions crates/router/src/connector/authorizedotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,84 @@ impl
types::PaymentsResponseData,
> for Authorizedotnet
{
// Issue: #173
fn build_request(
fn get_headers(
&self,
_req: &types::RouterData<
api::SetupMandate,
types::SetupMandateRequestData,
types::PaymentsResponseData,
>,
req: &types::SetupMandateRouterData,
connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
// This connector does not require an auth header, the authentication details are sent in the request body
self.build_headers(req, connectors)
}
fn get_content_type(&self) -> &'static str {
self.common_get_content_type()
}
fn get_url(
&self,
_req: &types::SetupMandateRouterData,
connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
Ok(self.base_url(connectors).to_string())
}
fn get_request_body(
&self,
req: &types::SetupMandateRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
Err(errors::ConnectorError::NotImplemented(
"Setup Mandate flow for Authorizedotnet".to_string(),
)
.into())
) -> CustomResult<RequestContent, errors::ConnectorError> {
let connector_req = authorizedotnet::CreateCustomerProfileRequest::try_from(req)?;
Ok(RequestContent::Json(Box::new(connector_req)))
}

fn build_request(
&self,
req: &types::SetupMandateRouterData,
connectors: &settings::Connectors,
) -> CustomResult<Option<common_utils::request::Request>, errors::ConnectorError> {
Ok(Some(
services::RequestBuilder::new()
.method(services::Method::Post)
.url(&types::SetupMandateType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::SetupMandateType::get_headers(self, req, connectors)?)
.set_body(types::SetupMandateType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}

fn handle_response(
&self,
data: &types::SetupMandateRouterData,
event_builder: Option<&mut ConnectorEvent>,
res: types::Response,
) -> CustomResult<types::SetupMandateRouterData, errors::ConnectorError> {
use bytes::Buf;

// Handle the case where response bytes contains U+FEFF (BOM) character sent by connector
let encoding = encoding_rs::UTF_8;
let intermediate_response = encoding.decode_with_bom_removal(res.response.chunk());
let intermediate_response =
bytes::Bytes::copy_from_slice(intermediate_response.0.as_bytes());
let response: authorizedotnet::AuthorizedotnetSetupMandateResponse = intermediate_response
.parse_struct("AuthorizedotnetPaymentsResponse")
.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: types::Response,
event_builder: Option<&mut ConnectorEvent>,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
get_error_response(res, event_builder)
}
}

Expand Down
Loading

0 comments on commit 8afeda5

Please sign in to comment.