Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(connector): [Cryptopay] fix amount_captured population logic in response handling (#9674)

Saptak Duttaa4bf608b7ddf
diff --git a/crates/hyperswitch_connectors/src/connectors/cryptopay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/cryptopay/transformers.rs
index a9bc6f27f9..27ccbbf75b 100644
--- a/crates/hyperswitch_connectors/src/connectors/cryptopay/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/cryptopay/transformers.rs
@@ -201,8 +201,8 @@ impl<F, T>
charges: None,
})
};
- match amount_captured_in_minor_units {
- Some(minor_amount) => {
+ match (amount_captured_in_minor_units, status) {
+ (Some(minor_amount), enums::AttemptStatus::Charged) => {
let amount_captured = Some(minor_amount.get_amount_as_i64());
Ok(Self {
status,
@@ -212,7 +212,7 @@ impl<F, T>
..item.data
})
}
- None => Ok(Self {
+ _ => Ok(Self {
status,
response,
..item.data
diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs
index 8c33ce1044..3a3a4b6fb7 100644
--- a/crates/router/src/connector/utils.rs
+++ b/crates/router/src/connector/utils.rs
@@ -180,31 +180,13 @@ where
payment_data,
);
let total_capturable_amount = payment_data.payment_attempt.get_total_amount();
- let is_overcapture_enabled = *payment_data
- .payment_attempt
- .is_overcapture_enabled
- .as_deref()
- .unwrap_or(&false);
if Some(total_capturable_amount) == captured_amount.map(MinorUnit::new)
- || (is_overcapture_enabled
- && captured_amount.is_some_and(|captured_amount| {
- MinorUnit::new(captured_amount) > total_capturable_amount
- }))
+ || (captured_amount.is_some_and(|captured_amount| {
+ MinorUnit::new(captured_amount) > total_capturable_amount
+ }))
{
Ok(enums::AttemptStatus::Charged)
- } else if captured_amount.is_some_and(|captured_amount| {
- MinorUnit::new(captured_amount) > total_capturable_amount
- }) {
- Err(ApiErrorResponse::IntegrityCheckFailed {
- reason: "captured_amount is greater than the total_capturable_amount"
- .to_string(),
- field_names: "captured_amount".to_string(),
- connector_transaction_id: payment_data
- .payment_attempt
- .connector_transaction_id
- .clone(),
- })?
} else if captured_amount.is_some_and(|captured_amount| {
MinorUnit::new(captured_amount) < total_capturable_amount
}) {
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index a2958d7508..7320a2a4f0 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -581,7 +581,7 @@ impl Capturable for PaymentsSyncData {
#[cfg(feature = "v1")]
fn get_captured_amount<F>(
&self,
- _amount_captured: Option<i64>,
+ amount_captured: Option<i64>,
payment_data: &PaymentData<F>,
) -> Option<i64>
where
@@ -591,6 +591,7 @@ impl Capturable for PaymentsSyncData {
.payment_attempt
.amount_to_capture
.or(payment_data.payment_intent.amount_captured)
+ .or(amount_captured.map(MinorUnit::new))
.or_else(|| Some(payment_data.payment_attempt.get_total_amount()))
.map(|amt| amt.get_amount_as_i64())
}