Skip to content
Open
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
39 changes: 36 additions & 3 deletions crates/hyperswitch_connectors/src/connectors/silverflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use common_utils::{
errors::CustomResult,
ext_traits::{BytesExt, StringExt},
request::{Method, Request, RequestBuilder, RequestContent},
types::{AmountConvertor, MinorUnit, MinorUnitForConnector},
};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
Expand All @@ -28,7 +29,7 @@ use hyperswitch_domain_models::{
SupportedPaymentMethods, SupportedPaymentMethodsExt,
},
types::{
PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData,
AmountUnit, PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData,
RefundSyncRouterData, RefundsRouterData,
},
};
Expand All @@ -49,11 +50,15 @@ use transformers as silverflow;
use crate::{constants::headers, types::ResponseRouterData, utils};

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

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

Expand Down Expand Up @@ -353,6 +358,12 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
let integrity_object = utils::get_authorise_integrity_object(
self.amount_converter,
response.amount.value,
response.amount.currency.clone(),
)?;
data.integrity_check = Ok(integrity_object);
RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
Expand Down Expand Up @@ -428,6 +439,12 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Sil
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
let integrity_object = utils::get_sync_integrity_object(
self.amount_converter,
response.amount.value,
response.amount.currency.clone(),
)?;
data.integrity_check = Ok(integrity_object);
RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
Expand Down Expand Up @@ -679,6 +696,12 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Silverf
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
let integrity_object = utils::get_refund_integrity_object(
self.amount_converter,
response.amount.value,
response.amount.currency.clone(),
)?;
data.integrity_check = Ok(integrity_object);
RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
Expand Down Expand Up @@ -755,6 +778,12 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Silverflo
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
let integrity_object = utils::get_refund_integrity_object(
self.amount_converter,
response.amount.value,
response.amount.currency.clone(),
)?;
data.integrity_check = Ok(integrity_object);
RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
Expand Down Expand Up @@ -978,4 +1007,8 @@ impl ConnectorSpecifications for Silverflow {
fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {
Some(&SILVERFLOW_SUPPORTED_WEBHOOK_FLOWS)
}

fn get_amount_unit(&self) -> Option<AmountUnit> {
Some(AmountUnit::Minor)
}
}
19 changes: 17 additions & 2 deletions crates/hyperswitch_connectors/src/connectors/square.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use common_utils::{
errors::CustomResult,
ext_traits::ByteSliceExt,
request::{Method, Request, RequestBuilder, RequestContent},
types::{AmountConvertor, MinorUnit, MinorUnitForConnector},
};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
Expand All @@ -31,7 +32,7 @@ use hyperswitch_domain_models::{
SupportedPaymentMethods, SupportedPaymentMethodsExt,
},
types::{
PaymentsAuthorizeRouterData, PaymentsAuthorizeSessionTokenRouterData,
AmountUnit, PaymentsAuthorizeRouterData, PaymentsAuthorizeSessionTokenRouterData,
PaymentsCancelRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData,
RefundSyncRouterData, RefundsRouterData, TokenizationRouterData,
},
Expand Down Expand Up @@ -60,7 +61,17 @@ use crate::{
};

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

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

impl api::Payment for Square {}
impl api::PaymentSession for Square {}
Expand Down Expand Up @@ -1000,4 +1011,8 @@ impl ConnectorSpecifications for Square {
fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {
Some(&*SQUARE_SUPPORTED_WEBHOOK_FLOWS)
}

fn get_amount_unit(&self) -> Option<AmountUnit> {
Some(AmountUnit::Minor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use hyperswitch_domain_models::{
router_request_types::ResponseId,
router_response_types::{PaymentsResponseData, RefundsResponseData},
types,
types::AmountConvert,
};
use hyperswitch_interfaces::errors;
use masking::{ExposeInterface, PeekInterface, Secret};
Expand Down Expand Up @@ -286,7 +287,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for SquarePaymentsRequest {
}
},
amount_money: SquarePaymentsAmountData {
amount: item.request.amount,
amount: item.convert_amount()?.amount,
currency: item.request.currency,
},
autocomplete,
Expand Down Expand Up @@ -428,7 +429,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for SquareRefundRequest {
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
Ok(Self {
amount_money: SquarePaymentsAmountData {
amount: item.request.refund_amount,
amount: item.convert_amount()?.amount,
currency: item.request.currency,
},
idempotency_key: Secret::new(item.request.refund_id.clone()),
Expand Down