mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
fix(connector): [noon] sync with reference_id (#2544)
This commit is contained in:
@ -9,7 +9,6 @@ use error_stack::{IntoReport, ResultExt};
|
|||||||
use masking::PeekInterface;
|
use masking::PeekInterface;
|
||||||
use transformers as noon;
|
use transformers as noon;
|
||||||
|
|
||||||
use super::utils::PaymentsSyncRequestData;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
configs::settings,
|
configs::settings,
|
||||||
connector::utils as connector_utils,
|
connector::utils as connector_utils,
|
||||||
@ -276,10 +275,19 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
|
|||||||
req: &types::PaymentsSyncRouterData,
|
req: &types::PaymentsSyncRouterData,
|
||||||
connectors: &settings::Connectors,
|
connectors: &settings::Connectors,
|
||||||
) -> CustomResult<String, errors::ConnectorError> {
|
) -> CustomResult<String, errors::ConnectorError> {
|
||||||
let connector_transaction_id = req.request.get_connector_transaction_id()?;
|
//Added as a fix for past payments before the given timestamp we can reconcile using payment_id
|
||||||
|
let cutoff_timestamp: i64 = 1697023800;
|
||||||
|
|
||||||
|
let reference_id = if req.request.payment_attempt_created_at_as_utc < cutoff_timestamp {
|
||||||
|
req.payment_id.clone()
|
||||||
|
} else {
|
||||||
|
req.attempt_id.clone()
|
||||||
|
};
|
||||||
|
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{}payment/v1/order/{connector_transaction_id}",
|
"{}payment/v1/order/getbyreference/{}",
|
||||||
self.base_url(connectors)
|
self.base_url(connectors),
|
||||||
|
reference_id
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,9 +577,9 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
|
|||||||
connectors: &settings::Connectors,
|
connectors: &settings::Connectors,
|
||||||
) -> CustomResult<String, errors::ConnectorError> {
|
) -> CustomResult<String, errors::ConnectorError> {
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{}payment/v1/order/{}",
|
"{}payment/v1/order/getbyreference/{}",
|
||||||
self.base_url(connectors),
|
self.base_url(connectors),
|
||||||
req.request.connector_transaction_id
|
req.attempt_id
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connector::utils::{
|
connector::utils::{
|
||||||
self as conn_utils, CardData, PaymentsAuthorizeRequestData, RefundsRequestData, RouterData,
|
self as conn_utils, CardData, PaymentsAuthorizeRequestData, RouterData, WalletData,
|
||||||
WalletData,
|
|
||||||
},
|
},
|
||||||
core::errors,
|
core::errors,
|
||||||
services,
|
services,
|
||||||
@ -438,6 +437,7 @@ impl<F, T>
|
|||||||
pub struct NoonActionTransaction {
|
pub struct NoonActionTransaction {
|
||||||
amount: String,
|
amount: String,
|
||||||
currency: diesel_models::enums::Currency,
|
currency: diesel_models::enums::Currency,
|
||||||
|
transaction_reference: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@ -466,6 +466,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for NoonPaymentsActionRequest {
|
|||||||
item.request.currency,
|
item.request.currency,
|
||||||
)?,
|
)?,
|
||||||
currency: item.request.currency,
|
currency: item.request.currency,
|
||||||
|
transaction_reference: None,
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
api_operation: NoonApiOperations::Capture,
|
api_operation: NoonApiOperations::Capture,
|
||||||
@ -507,6 +508,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for NoonPaymentsActionRequest {
|
|||||||
item.request.currency,
|
item.request.currency,
|
||||||
)?,
|
)?,
|
||||||
currency: item.request.currency,
|
currency: item.request.currency,
|
||||||
|
transaction_reference: Some(item.request.refund_id.clone()),
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
api_operation: NoonApiOperations::Refund,
|
api_operation: NoonApiOperations::Refund,
|
||||||
@ -570,9 +572,11 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Deserialize)]
|
#[derive(Default, Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct NoonRefundResponseTransactions {
|
pub struct NoonRefundResponseTransactions {
|
||||||
id: String,
|
id: String,
|
||||||
status: RefundStatus,
|
status: RefundStatus,
|
||||||
|
transaction_reference: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Deserialize)]
|
#[derive(Default, Debug, Deserialize)]
|
||||||
@ -592,13 +596,19 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundSyncResponse>>
|
|||||||
fn try_from(
|
fn try_from(
|
||||||
item: types::RefundsResponseRouterData<api::RSync, RefundSyncResponse>,
|
item: types::RefundsResponseRouterData<api::RSync, RefundSyncResponse>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let connector_refund_id = item.data.request.get_connector_refund_id()?;
|
|
||||||
let noon_transaction: &NoonRefundResponseTransactions = item
|
let noon_transaction: &NoonRefundResponseTransactions = item
|
||||||
.response
|
.response
|
||||||
.result
|
.result
|
||||||
.transactions
|
.transactions
|
||||||
.iter()
|
.iter()
|
||||||
.find(|transaction| transaction.id == connector_refund_id)
|
.find(|transaction| {
|
||||||
|
transaction
|
||||||
|
.transaction_reference
|
||||||
|
.clone()
|
||||||
|
.map_or(false, |transaction_instance| {
|
||||||
|
transaction_instance == item.data.request.refund_id
|
||||||
|
})
|
||||||
|
})
|
||||||
.ok_or(errors::ConnectorError::ResponseHandlingFailed)?;
|
.ok_or(errors::ConnectorError::ResponseHandlingFailed)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|||||||
@ -1050,6 +1050,11 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData
|
|||||||
),
|
),
|
||||||
None => types::SyncRequestType::SinglePaymentSync,
|
None => types::SyncRequestType::SinglePaymentSync,
|
||||||
},
|
},
|
||||||
|
payment_attempt_created_at_as_utc: payment_data
|
||||||
|
.payment_attempt
|
||||||
|
.created_at
|
||||||
|
.assume_utc()
|
||||||
|
.unix_timestamp(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -476,6 +476,9 @@ pub struct PaymentsSyncData {
|
|||||||
pub connector_meta: Option<serde_json::Value>,
|
pub connector_meta: Option<serde_json::Value>,
|
||||||
pub sync_type: SyncRequestType,
|
pub sync_type: SyncRequestType,
|
||||||
pub mandate_id: Option<api_models::payments::MandateIds>,
|
pub mandate_id: Option<api_models::payments::MandateIds>,
|
||||||
|
//This is being added as a temporary fix, will be deprecated before or by v1.65.0
|
||||||
|
// #2628
|
||||||
|
pub payment_attempt_created_at_as_utc: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
|
|||||||
@ -108,6 +108,7 @@ async fn should_sync_authorized_payment() {
|
|||||||
capture_method: Some(diesel_models::enums::CaptureMethod::Manual),
|
capture_method: Some(diesel_models::enums::CaptureMethod::Manual),
|
||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta: None,
|
connector_meta: None,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -222,6 +223,7 @@ async fn should_sync_auto_captured_payment() {
|
|||||||
capture_method: Some(enums::CaptureMethod::Automatic),
|
capture_method: Some(enums::CaptureMethod::Automatic),
|
||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta: None,
|
connector_meta: None,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -153,6 +153,7 @@ async fn should_sync_authorized_payment() {
|
|||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta: None,
|
connector_meta: None,
|
||||||
mandate_id: None,
|
mandate_id: None,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
}),
|
}),
|
||||||
get_default_payment_info(),
|
get_default_payment_info(),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -123,6 +123,7 @@ async fn should_sync_authorized_payment() {
|
|||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta,
|
connector_meta,
|
||||||
mandate_id: None,
|
mandate_id: None,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -140,6 +140,7 @@ async fn should_sync_authorized_payment() {
|
|||||||
capture_method: None,
|
capture_method: None,
|
||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta,
|
connector_meta,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
}),
|
}),
|
||||||
get_default_payment_info(),
|
get_default_payment_info(),
|
||||||
)
|
)
|
||||||
@ -336,6 +337,7 @@ async fn should_sync_auto_captured_payment() {
|
|||||||
capture_method: Some(enums::CaptureMethod::Automatic),
|
capture_method: Some(enums::CaptureMethod::Automatic),
|
||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta,
|
connector_meta,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
}),
|
}),
|
||||||
get_default_payment_info(),
|
get_default_payment_info(),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -942,6 +942,7 @@ impl Default for PaymentSyncType {
|
|||||||
capture_method: None,
|
capture_method: None,
|
||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta: None,
|
connector_meta: None,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
};
|
};
|
||||||
Self(data)
|
Self(data)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,6 +102,7 @@ async fn should_sync_authorized_payment() {
|
|||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta: None,
|
connector_meta: None,
|
||||||
mandate_id: None,
|
mandate_id: None,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -216,6 +217,7 @@ async fn should_sync_auto_captured_payment() {
|
|||||||
sync_type: types::SyncRequestType::SinglePaymentSync,
|
sync_type: types::SyncRequestType::SinglePaymentSync,
|
||||||
connector_meta: None,
|
connector_meta: None,
|
||||||
mandate_id: None,
|
mandate_id: None,
|
||||||
|
payment_attempt_created_at_as_utc: 0,
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user