Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions crates/hyperswitch_connectors/src/connectors/powertranz.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
pub mod transformers;

use std::fmt::Debug;

use api_models::enums::AuthenticationType;
use common_enums::enums;
use common_utils::{
errors::CustomResult,
ext_traits::{BytesExt, ValueExt},
request::{Method, Request, RequestBuilder, RequestContent},
types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},
};
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::{
Expand Down Expand Up @@ -49,8 +48,18 @@ use crate::{
utils::{self, PaymentsAuthorizeRequestData as _, PaymentsCompleteAuthorizeRequestData as _},
};

#[derive(Debug, Clone)]
pub struct Powertranz;
#[derive(Clone)]
pub struct Powertranz {
amount_converter: &'static (dyn AmountConvertor<Output = StringMajorUnit> + Sync),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use FloatMajorUnit for conversion

}

impl Powertranz {
pub fn new() -> &'static Self {
&Self {
amount_converter: &StringMajorUnitForConnector,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FloatMajorUnitForConnector here

}
}
}

impl api::Payment for Powertranz {}
impl api::PaymentSession for Powertranz {}
Expand Down Expand Up @@ -214,7 +223,13 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
req: &PaymentsAuthorizeRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
let connector_req = powertranz::PowertranzPaymentsRequest::try_from(req)?;
let amount_to_capture = utils::convert_amount(
self.amount_converter,
req.request.minor_amount,
req.request.currency,
)?;
let connector_router_data = powertranz::PowertranzRouterData::from((amount_to_capture, req));
let connector_req = powertranz::PowertranzPaymentsRequest::try_from(&connector_router_data)?;
Ok(RequestContent::Json(Box::new(connector_req)))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common_enums::enums::{self, AuthenticationType, Currency};
use common_utils::pii::IpAddress;
use common_utils::{pii::IpAddress, types::{StringMajorUnit}};
use hyperswitch_domain_models::{
payment_method_data::{Card, PaymentMethodData},
router_data::{ConnectorAuthType, ErrorResponse, RouterData},
Expand All @@ -20,6 +20,20 @@ use crate::{
utils::{self, CardData, PaymentsAuthorizeRequestData, RouterData as _},
};

pub struct PowertranzRouterData<T> {
pub amount: StringMajorUnit,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use FloatMajorUnit for conversion

pub router_data: T,
}

impl<T> From<(StringMajorUnit, T)> for PowertranzRouterData<T> {
fn from((amount, item): (StringMajorUnit, T)) -> Self {
Self {
amount,
router_data: item,
}
}
}
Comment on lines +28 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use FloatMajorUnit for conversion


const ISO_SUCCESS_CODES: [&str; 7] = ["00", "3D0", "3D1", "HP0", "TK0", "SP4", "FC0"];

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -103,12 +117,12 @@ pub struct RedirectResponsePayload {
pub spi_token: Secret<String>,
}

impl TryFrom<&PaymentsAuthorizeRouterData> for PowertranzPaymentsRequest {
impl TryFrom<&PowertranzRouterData<&PaymentsAuthorizeRouterData>> for PowertranzPaymentsRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
let source = match item.request.payment_method_data.clone() {
fn try_from(item: &PowertranzRouterData<&PaymentsAuthorizeRouterData>) -> Result<Self, Self::Error> {
let source = match item.router_data.request.payment_method_data.clone() {
PaymentMethodData::Card(card) => {
let card_holder_name = item.get_optional_billing_full_name();
let card_holder_name = item.router_data.get_optional_billing_full_name();
Source::try_from((&card, card_holder_name))
}
PaymentMethodData::Wallet(_)
Expand Down Expand Up @@ -137,20 +151,20 @@ impl TryFrom<&PaymentsAuthorizeRouterData> for PowertranzPaymentsRequest {
}?;
// let billing_address = get_address_details(&item.address.billing, &item.request.email);
// let shipping_address = get_address_details(&item.address.shipping, &item.request.email);
let (three_d_secure, extended_data) = match item.auth_type {
AuthenticationType::ThreeDs => (true, Some(ExtendedData::try_from(item)?)),
let (three_d_secure, extended_data) = match item.router_data.auth_type {
AuthenticationType::ThreeDs => (true, Some(ExtendedData::try_from(item.router_data)?)),
AuthenticationType::NoThreeDs => (false, None),
};
Ok(Self {
transaction_identifier: Uuid::new_v4().to_string(),
total_amount: utils::to_currency_base_unit_asf64(
item.request.amount,
item.request.currency,
item.router_data.request.amount,
item.router_data.request.currency,
)?,
Comment on lines 160 to 163
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the amount from PowertranzRouterData instead on converting at place

currency_code: Currency::iso_4217(&item.request.currency).to_string(),
currency_code: Currency::iso_4217(&item.router_data.request.currency).to_string(),
three_d_secure,
source,
order_identifier: item.connector_request_reference_id.clone(),
order_identifier: item.router_data.connector_request_reference_id.clone(),
// billing_address,
// shipping_address,
extended_data,
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 @@ -462,7 +462,7 @@ impl ConnectorData {
Ok(ConnectorEnum::Old(Box::new(connector::Placetopay::new())))
}
enums::Connector::Powertranz => {
Ok(ConnectorEnum::Old(Box::new(&connector::Powertranz)))
Ok(ConnectorEnum::Old(Box::new(connector::Powertranz::new())))
}
enums::Connector::Prophetpay => {
Ok(ConnectorEnum::Old(Box::new(&connector::Prophetpay)))
Expand Down
2 changes: 1 addition & 1 deletion crates/router/tests/connectors/powertranz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl utils::Connector for PowertranzTest {
fn get_data(&self) -> types::api::ConnectorData {
use router::connector::Powertranz;
utils::construct_connector_data_old(
Box::new(&Powertranz),
Box::new(Powertranz::new()),
types::Connector::Powertranz,
types::api::GetToken::Connector,
None,
Expand Down