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

refactor(connector): [Loonio] add Integrity Check (#13402)

Swangi Kumaric10e822ed3a2
diff --git a/crates/hyperswitch_connectors/src/connectors/loonio.rs b/crates/hyperswitch_connectors/src/connectors/loonio.rs
index aaed788cb9..bc8516bc99 100644
--- a/crates/hyperswitch_connectors/src/connectors/loonio.rs
+++ b/crates/hyperswitch_connectors/src/connectors/loonio.rs
@@ -341,6 +341,33 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Loo
.response
.parse_struct("loonio LoonioPaymentResponseData")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ let response_integrity_object = match &response {
+ loonio::LoonioPaymentResponseData::Sync(sync_response) => {
+ if let (Some(amount), Some(currency)) =
+ (sync_response.amount, sync_response.currency_code)
+ {
+ Some(utils::get_sync_integrity_object(
+ self.amount_converter,
+ amount,
+ currency.to_string(),
+ )?)
+ } else {
+ None
+ }
+ }
+ loonio::LoonioPaymentResponseData::Webhook(webhook_body) => webhook_body
+ .currency_code
+ .map(|currency| {
+ utils::get_sync_integrity_object(
+ self.amount_converter,
+ webhook_body.amount,
+ currency.to_string(),
+ )
+ })
+ .transpose()?,
+ };
+
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
@@ -348,6 +375,12 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Loo
data: data.clone(),
http_code: res.status_code,
})
+ .map(|mut router_data| {
+ if let Some(integrity_object) = response_integrity_object {
+ router_data.request.integrity_object = Some(integrity_object);
+ }
+ router_data
+ })
}
fn get_error_response(
@@ -506,6 +539,18 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Loonio
res.response
.parse_struct("loonio RefundResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ let response_integrity_object =
+ if let (Some(amount), Some(currency)) = (response.amount, response.currency_code) {
+ Some(utils::get_refund_integrity_object(
+ self.amount_converter,
+ amount,
+ currency.to_string(),
+ )?)
+ } else {
+ None
+ };
+
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
@@ -513,6 +558,12 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Loonio
data: data.clone(),
http_code: res.status_code,
})
+ .map(|mut router_data| {
+ if let Some(integrity_object) = response_integrity_object {
+ router_data.request.integrity_object = Some(integrity_object);
+ }
+ router_data
+ })
}
fn get_error_response(
@@ -574,6 +625,18 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Loonio {
.response
.parse_struct("loonio RefundSyncResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ let response_integrity_object =
+ if let (Some(amount), Some(currency)) = (response.amount, response.currency_code) {
+ Some(utils::get_refund_integrity_object(
+ self.amount_converter,
+ amount,
+ currency.to_string(),
+ )?)
+ } else {
+ None
+ };
+
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
@@ -581,6 +644,12 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Loonio {
data: data.clone(),
http_code: res.status_code,
})
+ .map(|mut router_data| {
+ if let Some(integrity_object) = response_integrity_object {
+ router_data.request.integrity_object = Some(integrity_object);
+ }
+ router_data
+ })
}
fn get_error_response(
diff --git a/crates/hyperswitch_connectors/src/connectors/loonio/transformers.rs b/crates/hyperswitch_connectors/src/connectors/loonio/transformers.rs
index 5b86d60f8d..08065b92d0 100644
--- a/crates/hyperswitch_connectors/src/connectors/loonio/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/loonio/transformers.rs
@@ -214,6 +214,8 @@ pub struct LoonioTransactionSyncResponse {
pub transaction_id: String,
pub state: LoonioTransactionStatus,
pub customer_bank_info: Option<LoonioCustomerInfo>,
+ pub amount: Option<FloatMajorUnit>,
+ pub currency_code: Option<Currency>,
}
#[derive(Default, Debug, Serialize)]
@@ -354,6 +356,8 @@ impl From<RefundStatus> for enums::RefundStatus {
pub struct RefundResponse {
id: String,
status: RefundStatus,
+ pub amount: Option<FloatMajorUnit>,
+ pub currency_code: Option<Currency>,
}
impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRouterData<Execute> {
@@ -431,6 +435,7 @@ pub enum LoonioWebhookTransactionType {
#[derive(Debug, Serialize, Deserialize)]
pub struct LoonioWebhookBody {
pub amount: FloatMajorUnit,
+ pub currency_code: Option<Currency>,
pub api_transaction_id: String,
pub signature: Option<String>,
pub event_code: LoonioWebhookEventCode,