fix(router): fixed integrity check failures in case of 3ds flow in sync flow (#5279)

This commit is contained in:
Sahkal Poddar
2024-07-12 05:14:16 +05:30
committed by GitHub
parent 43741df4a7
commit 6d372efbed
12 changed files with 61 additions and 47 deletions

View File

@ -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)]
@ -384,7 +382,6 @@ pub struct PaymentsSyncData {
pub amount: MinorUnit,
pub integrity_object: Option<SyncIntegrityObject>,
pub captured_amount: Option<MinorUnit>,
}
#[derive(Debug, Default, Clone)]

View File

@ -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() {
@ -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() {
@ -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(),
));
}
});
@ -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() {
@ -322,7 +345,11 @@ impl GetIntegrityObject<SyncIntegrityObject> for PaymentsSyncData {
SyncIntegrityObject {
amount: Some(self.amount),
currency: Some(self.currency),
captured_amount: self.captured_amount,
}
}
}
#[inline]
fn format_mismatch(field: &str, expected: &str, found: &str) -> String {
format!("{} expected {} but found {}", field, expected, found)
}

View File

@ -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));

View File

@ -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,
})
}

View File

@ -72,7 +72,7 @@ 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,
@ -80,7 +80,15 @@ impl Feature<api::PSync, types::PaymentsSyncData>
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),
_ => {

View File

@ -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,
@ -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,
})
}
}

View File

@ -114,7 +114,6 @@ async fn should_sync_authorized_payment() {
payment_experience: None,
integrity_object: None,
amount: MinorUnit::new(100),
captured_amount: None,
}),
None,
)
@ -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,
)

View File

@ -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(),
)

View File

@ -130,7 +130,6 @@ async fn should_sync_authorized_payment() {
payment_experience: None,
integrity_object: None,
amount: MinorUnit::new(100),
captured_amount: None,
}),
None,
)

View File

@ -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(),
)
@ -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(),
)

View File

@ -1000,7 +1000,6 @@ impl Default for PaymentSyncType {
payment_experience: None,
amount: MinorUnit::new(100),
integrity_object: None,
captured_amount: None,
};
Self(data)
}

View File

@ -108,7 +108,6 @@ async fn should_sync_authorized_payment() {
payment_experience: None,
amount: MinorUnit::new(100),
integrity_object: None,
captured_amount: None,
}),
None,
)
@ -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,
)