Skip to content

Commit

Permalink
refactor(router): review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hex1c committed Nov 10, 2024
1 parent 8cd3afd commit f81ba20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
30 changes: 17 additions & 13 deletions crates/router/src/connector/netcetera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl
req: &types::authentication::PreAuthNRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
let connector_router_data = NetceteraRouterData::try_from((MinorUnit::zero(), req))?;
let connector_router_data = NetceteraRouterData::try_from((Some(MinorUnit::zero()), req))?;
let req_obj =
netcetera::NetceteraPreAuthenticationRequest::try_from(&connector_router_data)?;
Ok(RequestContent::Json(Box::new(req_obj)))
Expand Down Expand Up @@ -378,18 +378,22 @@ impl
req: &types::authentication::ConnectorAuthenticationRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
let currency =
req.request
.currency
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "currency",
})?;
let amount = req.request.amount.map(MinorUnit::new).ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "amount",
},
)?;
let amount = utils::convert_amount(self.amount_convertor, amount, currency)?;
let amount = match req.request.amount {
Some(amount) => {
let currency =
req.request
.currency
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "currency",
})?;
Some(utils::convert_amount(
self.amount_convertor,
MinorUnit::new(amount),
currency,
)?)
}
None => None,
};
let connector_router_data = NetceteraRouterData::try_from((amount, req))?;
let req_obj = netcetera::NetceteraAuthenticationRequest::try_from(&connector_router_data);
Ok(RequestContent::Json(Box::new(req_obj?)))
Expand Down
8 changes: 4 additions & 4 deletions crates/router/src/connector/netcetera/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use crate::{

//TODO: Fill the struct with respective fields
pub struct NetceteraRouterData<T> {
pub amount: MinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
pub amount: Option<MinorUnit>, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
pub router_data: T,
}

impl<T> TryFrom<(MinorUnit, T)> for NetceteraRouterData<T> {
impl<T> TryFrom<(Option<MinorUnit>, T)> for NetceteraRouterData<T> {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from((amount, router_data): (MinorUnit, T)) -> Result<Self, Self::Error> {
fn try_from((amount, router_data): (Option<MinorUnit>, T)) -> Result<Self, Self::Error> {
Ok(Self {
amount,
router_data,
Expand Down Expand Up @@ -470,7 +470,7 @@ impl TryFrom<&NetceteraRouterData<&types::authentication::ConnectorAuthenticatio
let purchase = netcetera_types::Purchase {
purchase_instal_data: None,
merchant_risk_indicator: None,
purchase_amount: Some(item.amount),
purchase_amount: item.amount,
purchase_currency: currency.iso_4217().to_string(),
purchase_exponent: currency.number_of_digits_after_decimal_point(),
purchase_date: Some(
Expand Down

0 comments on commit f81ba20

Please sign in to comment.