Skip to content

Commit

Permalink
Merge branch 'main' into FEAT-4672
Browse files Browse the repository at this point in the history
  • Loading branch information
Rutam21 authored Nov 7, 2024
2 parents e2ceaa1 + 1ba3d84 commit b7020c8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 14 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to HyperSwitch will be documented here.

- - -

## 2024.11.07.0

### Features

- **analytics:** Implement currency conversion to power multi-currency aggregation ([#6418](https://github.com/juspay/hyperswitch/pull/6418)) ([`01c5216`](https://github.com/juspay/hyperswitch/commit/01c5216fdd6f1d841082868cccea6054b64e9e07))

### Bug Fixes

- **core:** PMD Not Getting Populated for Saved Card Transactions ([#6497](https://github.com/juspay/hyperswitch/pull/6497)) ([`b8b2060`](https://github.com/juspay/hyperswitch/commit/b8b206057c5b464420a6d115a1116ef5cc695bf7))

**Full Changelog:** [`2024.11.06.0...2024.11.07.0`](https://github.com/juspay/hyperswitch/compare/2024.11.06.0...2024.11.07.0)

- - -

## 2024.11.06.0

### Features
Expand Down
33 changes: 28 additions & 5 deletions crates/router/src/connector/wise.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
pub mod transformers;
use std::fmt::Debug;

#[cfg(feature = "payouts")]
use common_utils::request::RequestContent;
use common_utils::types::{AmountConvertor, MinorUnit, MinorUnitForConnector};
use error_stack::{report, ResultExt};
#[cfg(feature = "payouts")]
use masking::PeekInterface;
#[cfg(feature = "payouts")]
use router_env::{instrument, tracing};

use self::transformers as wise;
use super::utils::convert_amount;
use crate::{
configs::settings,
core::errors::{self, CustomResult},
Expand All @@ -27,8 +28,18 @@ use crate::{
utils::BytesExt,
};

#[derive(Debug, Clone)]
pub struct Wise;
#[derive(Clone)]
pub struct Wise {
amount_converter: &'static (dyn AmountConvertor<Output = MinorUnit> + Sync),
}

impl Wise {
pub fn new() -> &'static Self {
&Self {
amount_converter: &MinorUnitForConnector,
}
}
}

impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Wise
where
Expand Down Expand Up @@ -362,7 +373,13 @@ impl services::ConnectorIntegration<api::PoQuote, types::PayoutsData, types::Pay
req: &types::PayoutsRouterData<api::PoQuote>,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
let connector_req = wise::WisePayoutQuoteRequest::try_from(req)?;
let amount = convert_amount(
self.amount_converter,
req.request.minor_amount,
req.request.source_currency,
)?;
let connector_router_data = wise::WiseRouterData::from((amount, req));
let connector_req = wise::WisePayoutQuoteRequest::try_from(&connector_router_data)?;
Ok(RequestContent::Json(Box::new(connector_req)))
}

Expand Down Expand Up @@ -441,7 +458,13 @@ impl
req: &types::PayoutsRouterData<api::PoRecipient>,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
let connector_req = wise::WiseRecipientCreateRequest::try_from(req)?;
let amount = convert_amount(
self.amount_converter,
req.request.minor_amount,
req.request.source_currency,
)?;
let connector_router_data = wise::WiseRouterData::from((amount, req));
let connector_req = wise::WiseRecipientCreateRequest::try_from(&connector_router_data)?;
Ok(RequestContent::Json(Box::new(connector_req)))
}

Expand Down
35 changes: 28 additions & 7 deletions crates/router/src/connector/wise/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use api_models::payouts::PayoutMethodData;
#[cfg(feature = "payouts")]
use common_utils::pii::Email;
use common_utils::types::MinorUnit;
use masking::Secret;
use serde::{Deserialize, Serialize};

Expand All @@ -16,6 +17,20 @@ use crate::{
},
};
use crate::{core::errors, types};
#[derive(Debug, Serialize)]
pub struct WiseRouterData<T> {
pub amount: MinorUnit,
pub router_data: T,
}

impl<T> From<(MinorUnit, T)> for WiseRouterData<T> {
fn from((amount, router_data): (MinorUnit, T)) -> Self {
Self {
amount,
router_data,
}
}
}

pub struct WiseAuthType {
pub(super) api_key: Secret<String>,
Expand Down Expand Up @@ -156,8 +171,8 @@ pub struct WiseRecipientCreateResponse {
pub struct WisePayoutQuoteRequest {
source_currency: String,
target_currency: String,
source_amount: Option<i64>,
target_amount: Option<i64>,
source_amount: Option<MinorUnit>,
target_amount: Option<MinorUnit>,
pay_out: WisePayOutOption,
}

Expand Down Expand Up @@ -348,9 +363,12 @@ fn get_payout_bank_details(

// Payouts recipient create request transform
#[cfg(feature = "payouts")]
impl<F> TryFrom<&types::PayoutsRouterData<F>> for WiseRecipientCreateRequest {
impl<F> TryFrom<&WiseRouterData<&types::PayoutsRouterData<F>>> for WiseRecipientCreateRequest {
type Error = Error;
fn try_from(item: &types::PayoutsRouterData<F>) -> Result<Self, Self::Error> {
fn try_from(
item_data: &WiseRouterData<&types::PayoutsRouterData<F>>,
) -> Result<Self, Self::Error> {
let item = item_data.router_data;
let request = item.request.to_owned();
let customer_details = request.customer_details.to_owned();
let payout_method_data = item.get_payout_method_data()?;
Expand Down Expand Up @@ -420,14 +438,17 @@ impl<F> TryFrom<types::PayoutsResponseRouterData<F, WiseRecipientCreateResponse>

// Payouts quote request transform
#[cfg(feature = "payouts")]
impl<F> TryFrom<&types::PayoutsRouterData<F>> for WisePayoutQuoteRequest {
impl<F> TryFrom<&WiseRouterData<&types::PayoutsRouterData<F>>> for WisePayoutQuoteRequest {
type Error = Error;
fn try_from(item: &types::PayoutsRouterData<F>) -> Result<Self, Self::Error> {
fn try_from(
item_data: &WiseRouterData<&types::PayoutsRouterData<F>>,
) -> Result<Self, Self::Error> {
let item = item_data.router_data;
let request = item.request.to_owned();
let payout_type = request.get_payout_type()?;
match payout_type {
storage_enums::PayoutType::Bank => Ok(Self {
source_amount: Some(request.amount),
source_amount: Some(item_data.amount),
source_currency: request.source_currency.to_string(),
target_amount: None,
target_currency: request.destination_currency.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/types/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ impl ConnectorData {
enums::Connector::Stripe => {
Ok(ConnectorEnum::Old(Box::new(connector::Stripe::new())))
}
enums::Connector::Wise => Ok(ConnectorEnum::Old(Box::new(&connector::Wise))),
enums::Connector::Wise => Ok(ConnectorEnum::Old(Box::new(connector::Wise::new()))),
enums::Connector::Worldline => {
Ok(ConnectorEnum::Old(Box::new(&connector::Worldline)))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/tests/connectors/wise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl utils::Connector for WiseTest {
fn get_payout_data(&self) -> Option<api::ConnectorData> {
use router::connector::Wise;
Some(utils::construct_connector_data_old(
Box::new(&Wise),
Box::new(Wise::new()),
types::Connector::Wise,
api::GetToken::Connector,
None,
Expand Down

0 comments on commit b7020c8

Please sign in to comment.