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

feat(connector): [CRYPTOPAY] Report underpaid/overpaid amount in outgoing webhooks (#4468)

DEEPANSHU BANSALcc1051da99c1
diff --git a/crates/router/src/connector/cryptopay.rs b/crates/router/src/connector/cryptopay.rs
index 2f9c996eff..7245694bd4 100644
--- a/crates/router/src/connector/cryptopay.rs
+++ b/crates/router/src/connector/cryptopay.rs
@@ -287,11 +287,14 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from(types::ResponseRouterData {
- response,
- data: data.clone(),
- http_code: res.status_code,
- })
+ types::RouterData::try_from((
+ types::ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ },
+ data.request.currency,
+ ))
}
fn get_error_response(
@@ -371,11 +374,14 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from(types::ResponseRouterData {
- response,
- data: data.clone(),
- http_code: res.status_code,
- })
+ types::RouterData::try_from((
+ types::ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ },
+ data.request.currency,
+ ))
}
fn get_error_response(
diff --git a/crates/router/src/connector/cryptopay/transformers.rs b/crates/router/src/connector/cryptopay/transformers.rs
index e6db0cf320..b8f398a0d9 100644
--- a/crates/router/src/connector/cryptopay/transformers.rs
+++ b/crates/router/src/connector/cryptopay/transformers.rs
@@ -1,8 +1,10 @@
use common_utils::pii;
+use error_stack::ResultExt;
use masking::Secret;
use reqwest::Url;
use serde::{Deserialize, Serialize};
+use super::utils as connector_utils;
use crate::{
connector::utils::{self, is_payment_failure, CryptoData, PaymentsAuthorizeRequestData},
consts,
@@ -146,17 +148,17 @@ pub struct CryptopayPaymentsResponse {
}
impl<F, T>
- TryFrom<types::ResponseRouterData<F, CryptopayPaymentsResponse, T, types::PaymentsResponseData>>
- for types::RouterData<F, T, types::PaymentsResponseData>
+ TryFrom<(
+ types::ResponseRouterData<F, CryptopayPaymentsResponse, T, types::PaymentsResponseData>,
+ diesel_models::enums::Currency,
+ )> for types::RouterData<F, T, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
- item: types::ResponseRouterData<
- F,
- CryptopayPaymentsResponse,
- T,
- types::PaymentsResponseData,
- >,
+ (item, currency): (
+ types::ResponseRouterData<F, CryptopayPaymentsResponse, T, types::PaymentsResponseData>,
+ diesel_models::enums::Currency,
+ ),
) -> Result<Self, Self::Error> {
let status = enums::AttemptStatus::from(item.response.data.status.clone());
let response = if is_payment_failure(status) {
@@ -197,11 +199,28 @@ impl<F, T>
incremental_authorization_allowed: None,
})
};
- Ok(Self {
- status,
- response,
- ..item.data
- })
+
+ match item.response.data.price_amount {
+ Some(price_amount) => {
+ let amount_captured = Some(
+ connector_utils::to_currency_lower_unit(price_amount, currency)?
+ .parse::<i64>()
+ .change_context(errors::ConnectorError::ParsingFailed)?,
+ );
+
+ Ok(Self {
+ status,
+ response,
+ amount_captured,
+ ..item.data
+ })
+ }
+ None => Ok(Self {
+ status,
+ response,
+ ..item.data
+ }),
+ }
}
}
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 23b3f1f693..c8de432fc0 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -1220,6 +1220,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData
None => types::SyncRequestType::SinglePaymentSync,
},
payment_method_type: payment_data.payment_attempt.payment_method_type,
+ currency: payment_data.currency,
})
}
}
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index 6004131be4..951be887ed 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -565,6 +565,7 @@ pub struct PaymentsSyncData {
pub sync_type: SyncRequestType,
pub mandate_id: Option<api_models::payments::MandateIds>,
pub payment_method_type: Option<storage_enums::PaymentMethodType>,
+ pub currency: storage_enums::Currency,
}
#[derive(Debug, Default, Clone)]
diff --git a/crates/router/tests/connectors/bambora.rs b/crates/router/tests/connectors/bambora.rs
index 46f61271ee..5cd82d097a 100644
--- a/crates/router/tests/connectors/bambora.rs
+++ b/crates/router/tests/connectors/bambora.rs
@@ -109,6 +109,7 @@ async fn should_sync_authorized_payment() {
sync_type: types::SyncRequestType::SinglePaymentSync,
connector_meta: None,
payment_method_type: None,
+ currency: enums::Currency::USD,
}),
None,
)
@@ -224,6 +225,7 @@ async fn should_sync_auto_captured_payment() {
sync_type: types::SyncRequestType::SinglePaymentSync,
connector_meta: None,
payment_method_type: None,
+ currency: enums::Currency::USD,
}),
None,
)
diff --git a/crates/router/tests/connectors/forte.rs b/crates/router/tests/connectors/forte.rs
index c7934b3711..c58cab38a2 100644
--- a/crates/router/tests/connectors/forte.rs
+++ b/crates/router/tests/connectors/forte.rs
@@ -157,6 +157,7 @@ async fn should_sync_authorized_payment() {
connector_meta: None,
mandate_id: None,
payment_method_type: None,
+ currency: enums::Currency::USD,
}),
get_default_payment_info(),
)
diff --git a/crates/router/tests/connectors/nexinets.rs b/crates/router/tests/connectors/nexinets.rs
index 7f42048c98..5948855ae8 100644
--- a/crates/router/tests/connectors/nexinets.rs
+++ b/crates/router/tests/connectors/nexinets.rs
@@ -125,6 +125,7 @@ async fn should_sync_authorized_payment() {
connector_meta,
mandate_id: None,
payment_method_type: None,
+ currency: enums::Currency::EUR,
}),
None,
)
diff --git a/crates/router/tests/connectors/paypal.rs b/crates/router/tests/connectors/paypal.rs
index 14690ae2a7..bded135f45 100644
--- a/crates/router/tests/connectors/paypal.rs
+++ b/crates/router/tests/connectors/paypal.rs
@@ -142,6 +142,7 @@ async fn should_sync_authorized_payment() {
sync_type: types::SyncRequestType::SinglePaymentSync,
connector_meta,
payment_method_type: None,
+ currency: enums::Currency::USD,
}),
get_default_payment_info(),
)
@@ -339,6 +340,7 @@ async fn should_sync_auto_captured_payment() {
sync_type: types::SyncRequestType::SinglePaymentSync,
connector_meta,
payment_method_type: None,
+ currency: enums::Currency::USD,
}),
get_default_payment_info(),
)
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index 47ec71cc94..6294108c82 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -997,6 +997,7 @@ impl Default for PaymentSyncType {
sync_type: types::SyncRequestType::SinglePaymentSync,
connector_meta: None,
payment_method_type: None,
+ currency: enums::Currency::USD,
};
Self(data)
}
diff --git a/crates/router/tests/connectors/zen.rs b/crates/router/tests/connectors/zen.rs
index c9a7be2b0a..95017e7da0 100644
--- a/crates/router/tests/connectors/zen.rs
+++ b/crates/router/tests/connectors/zen.rs
@@ -104,6 +104,7 @@ async fn should_sync_authorized_payment() {
connector_meta: None,
mandate_id: None,
payment_method_type: None,
+ currency: enums::Currency::USD,
}),
None,
)
@@ -219,6 +220,7 @@ async fn should_sync_auto_captured_payment() {
connector_meta: None,
mandate_id: None,
payment_method_type: None,
+ currency: enums::Currency::USD,
}),
None,
)