Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ pub struct SyncIntegrityObject {
pub amount: Option<MinorUnit>,
/// Sync currency
pub currency: Option<storage_enums::Currency>,
/// Sync capture amount in case of automatic capture
pub captured_amount: Option<MinorUnit>,
}

#[derive(Debug, serde::Deserialize, Clone)]
Expand Down Expand Up @@ -384,7 +382,6 @@ pub struct PaymentsSyncData {

pub amount: MinorUnit,
pub integrity_object: Option<SyncIntegrityObject>,
pub captured_amount: Option<MinorUnit>,
}

#[derive(Debug, Default, Clone)]
Expand Down
75 changes: 51 additions & 24 deletions crates/hyperswitch_interfaces/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,19 @@ impl FlowIntegrity for RefundIntegrityObject {
let mut mismatched_fields = Vec::new();

if req_integrity_object.currency != res_integrity_object.currency {
mismatched_fields.push("currency".to_string());
mismatched_fields.push(format_mismatch(
"currency",
&req_integrity_object.currency.to_string(),
&res_integrity_object.currency.to_string(),
));
}

if req_integrity_object.refund_amount != res_integrity_object.refund_amount {
mismatched_fields.push("refund_amount".to_string());
mismatched_fields.push(format_mismatch(
"refund_amount",
&req_integrity_object.refund_amount.to_string(),
&res_integrity_object.refund_amount.to_string(),
));
}

if mismatched_fields.is_empty() {
Expand All @@ -170,11 +178,19 @@ impl FlowIntegrity for AuthoriseIntegrityObject {
let mut mismatched_fields = Vec::new();

if req_integrity_object.amount != res_integrity_object.amount {
mismatched_fields.push("amount".to_string());
mismatched_fields.push(format_mismatch(
"amount",
&req_integrity_object.amount.to_string(),
&res_integrity_object.amount.to_string(),
));
}

if req_integrity_object.currency != res_integrity_object.currency {
mismatched_fields.push("currency".to_string());
mismatched_fields.push(format_mismatch(
"currency",
&req_integrity_object.currency.to_string(),
&res_integrity_object.currency.to_string(),
));
}

if mismatched_fields.is_empty() {
Expand All @@ -199,30 +215,29 @@ impl FlowIntegrity for SyncIntegrityObject {
) -> Result<(), IntegrityCheckError> {
let mut mismatched_fields = Vec::new();

res_integrity_object
.captured_amount
.zip(req_integrity_object.captured_amount)
.map(|tup| {
if tup.0 != tup.1 {
mismatched_fields.push("captured_amount".to_string());
}
});

res_integrity_object
.amount
.zip(req_integrity_object.amount)
.map(|tup| {
if tup.0 != tup.1 {
mismatched_fields.push("amount".to_string());
.map(|(res_amount, req_amount)| {
if res_amount != req_amount {
mismatched_fields.push(format_mismatch(
"amount",
&req_amount.to_string(),
&res_amount.to_string(),
));
}
});

res_integrity_object
.currency
.zip(req_integrity_object.currency)
.map(|tup| {
if tup.0 != tup.1 {
mismatched_fields.push("currency".to_string());
.map(|(res_currency, req_currency)| {
if res_currency != req_currency {
mismatched_fields.push(format_mismatch(
"currency",
&req_currency.to_string(),
&res_currency.to_string(),
));
}
});

Expand Down Expand Up @@ -251,14 +266,22 @@ impl FlowIntegrity for CaptureIntegrityObject {
res_integrity_object
.capture_amount
.zip(req_integrity_object.capture_amount)
.map(|tup| {
if tup.0 != tup.1 {
mismatched_fields.push("capture_amount".to_string());
.map(|(res_amount, req_amount)| {
if res_amount != req_amount {
mismatched_fields.push(format_mismatch(
"capture_amount",
&req_amount.to_string(),
&res_amount.to_string(),
));
}
});

if req_integrity_object.currency != res_integrity_object.currency {
mismatched_fields.push("currency".to_string());
mismatched_fields.push(format_mismatch(
"currency",
&req_integrity_object.currency.to_string(),
&res_integrity_object.currency.to_string(),
));
}

if mismatched_fields.is_empty() {
Expand Down Expand Up @@ -322,7 +345,11 @@ impl GetIntegrityObject<SyncIntegrityObject> for PaymentsSyncData {
SyncIntegrityObject {
amount: Some(self.amount),
currency: Some(self.currency),
captured_amount: self.captured_amount,
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This function can be inline

#[inline]
fn format_mismatch(field: &str, expected: &str, found: &str) -> String {
format!("{} expected {} but found {}", field, expected, found)
}
1 change: 0 additions & 1 deletion crates/router/src/connector/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,6 @@ impl
self.amount_converter,
response.amount,
response.currency.clone(),
response.amount_received,
)?;

event_builder.map(|i| i.set_response_body(&response));
Expand Down
6 changes: 0 additions & 6 deletions crates/router/src/connector/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2914,21 +2914,15 @@ pub fn get_sync_integrity_object<T>(
amount_convertor: &dyn AmountConvertor<Output = T>,
amount: T,
currency: String,
captured_amount: Option<T>,
) -> Result<SyncIntegrityObject, error_stack::Report<errors::ConnectorError>> {
let currency_enum = enums::Currency::from_str(currency.to_uppercase().as_str())
.change_context(errors::ConnectorError::ParsingFailed)?;
let amount_in_minor_unit =
convert_back_amount_to_minor_units(amount_convertor, amount, currency_enum)?;

let capture_amount_in_minor_unit = captured_amount
.map(|amount| convert_back_amount_to_minor_units(amount_convertor, amount, currency_enum))
.transpose()?;

Ok(SyncIntegrityObject {
amount: Some(amount_in_minor_unit),
currency: Some(currency_enum),
captured_amount: capture_amount_in_minor_unit,
})
}

Expand Down
12 changes: 10 additions & 2 deletions crates/router/src/core/payments/flows/psync_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,23 @@ impl Feature<api::PSync, types::PaymentsSyncData>
types::SyncRequestType::MultipleCaptureSync(pending_connector_capture_id_list),
Ok(services::CaptureSyncMethod::Individual),
) => {
let resp = self
let mut new_router_data = self
.execute_connector_processing_step_for_each_capture(
state,
pending_connector_capture_id_list,
call_connector_action,
connector_integration,
)
.await?;
Ok(resp)
// Initiating Integrity checks
let integrity_result = helpers::check_integrity_based_on_flow(
&new_router_data.request,
&new_router_data.response,
);

new_router_data.integrity_check = integrity_result;

Ok(new_router_data)
}
(types::SyncRequestType::MultipleCaptureSync(_), Err(err)) => Err(err),
_ => {
Expand Down
2 changes: 0 additions & 2 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,6 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData
.as_ref()
.map(|surcharge_details| surcharge_details.final_amount)
.unwrap_or(payment_data.amount.into());
let captured_amount = payment_data.payment_intent.amount_captured;
Ok(Self {
amount,
integrity_object: None,
Expand All @@ -1395,7 +1394,6 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData
payment_method_type: payment_data.payment_attempt.payment_method_type,
currency: payment_data.currency,
payment_experience: payment_data.payment_attempt.payment_experience,
captured_amount,
})
}
}
Expand Down
2 changes: 0 additions & 2 deletions crates/router/tests/connectors/bambora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ async fn should_sync_authorized_payment() {
payment_experience: None,
integrity_object: None,
amount: MinorUnit::new(100),
captured_amount: None,
}),
None,
)
Expand Down Expand Up @@ -234,7 +233,6 @@ async fn should_sync_auto_captured_payment() {
payment_experience: None,
integrity_object: None,
amount: MinorUnit::new(100),
captured_amount: None,
}),
None,
)
Expand Down
1 change: 0 additions & 1 deletion crates/router/tests/connectors/forte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ async fn should_sync_authorized_payment() {
payment_experience: None,
integrity_object: None,
amount: MinorUnit::new(100),
captured_amount: None,
}),
get_default_payment_info(),
)
Expand Down
1 change: 0 additions & 1 deletion crates/router/tests/connectors/nexinets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ async fn should_sync_authorized_payment() {
payment_experience: None,
integrity_object: None,
amount: MinorUnit::new(100),
captured_amount: None,
}),
None,
)
Expand Down
2 changes: 0 additions & 2 deletions crates/router/tests/connectors/paypal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ async fn should_sync_authorized_payment() {
payment_experience: None,
integrity_object: None,
amount: MinorUnit::new(100),
captured_amount: None,
}),
get_default_payment_info(),
)
Expand Down Expand Up @@ -349,7 +348,6 @@ async fn should_sync_auto_captured_payment() {
payment_experience: None,
amount: MinorUnit::new(100),
integrity_object: None,
captured_amount: None,
}),
get_default_payment_info(),
)
Expand Down
1 change: 0 additions & 1 deletion crates/router/tests/connectors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,6 @@ impl Default for PaymentSyncType {
payment_experience: None,
amount: MinorUnit::new(100),
integrity_object: None,
captured_amount: None,
};
Self(data)
}
Expand Down
2 changes: 0 additions & 2 deletions crates/router/tests/connectors/zen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ async fn should_sync_authorized_payment() {
payment_experience: None,
amount: MinorUnit::new(100),
integrity_object: None,
captured_amount: None,
}),
None,
)
Expand Down Expand Up @@ -228,7 +227,6 @@ async fn should_sync_auto_captured_payment() {
payment_experience: None,
amount: MinorUnit::new(100),
integrity_object: None,
captured_amount: None,
}),
None,
)
Expand Down