Skip to content

Commit 9ef60e4

Browse files
fix(connector): [noon] sync with reference_id (#2544)
1 parent 9f446bc commit 9ef60e4

File tree

10 files changed

+45
-10
lines changed

10 files changed

+45
-10
lines changed

crates/router/src/connector/noon.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use error_stack::{IntoReport, ResultExt};
99
use masking::PeekInterface;
1010
use transformers as noon;
1111

12-
use super::utils::PaymentsSyncRequestData;
1312
use crate::{
1413
configs::settings,
1514
connector::utils as connector_utils,
@@ -276,10 +275,19 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
276275
req: &types::PaymentsSyncRouterData,
277276
connectors: &settings::Connectors,
278277
) -> CustomResult<String, errors::ConnectorError> {
279-
let connector_transaction_id = req.request.get_connector_transaction_id()?;
278+
//Added as a fix for past payments before the given timestamp we can reconcile using payment_id
279+
let cutoff_timestamp: i64 = 1697023800;
280+
281+
let reference_id = if req.request.payment_attempt_created_at_as_utc < cutoff_timestamp {
282+
req.payment_id.clone()
283+
} else {
284+
req.attempt_id.clone()
285+
};
286+
280287
Ok(format!(
281-
"{}payment/v1/order/{connector_transaction_id}",
282-
self.base_url(connectors)
288+
"{}payment/v1/order/getbyreference/{}",
289+
self.base_url(connectors),
290+
reference_id
283291
))
284292
}
285293

@@ -569,9 +577,9 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
569577
connectors: &settings::Connectors,
570578
) -> CustomResult<String, errors::ConnectorError> {
571579
Ok(format!(
572-
"{}payment/v1/order/{}",
580+
"{}payment/v1/order/getbyreference/{}",
573581
self.base_url(connectors),
574-
req.request.connector_transaction_id
582+
req.attempt_id
575583
))
576584
}
577585

crates/router/src/connector/noon/transformers.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use serde::{Deserialize, Serialize};
44

55
use crate::{
66
connector::utils::{
7-
self as conn_utils, CardData, PaymentsAuthorizeRequestData, RefundsRequestData, RouterData,
8-
WalletData,
7+
self as conn_utils, CardData, PaymentsAuthorizeRequestData, RouterData, WalletData,
98
},
109
core::errors,
1110
services,
@@ -438,6 +437,7 @@ impl<F, T>
438437
pub struct NoonActionTransaction {
439438
amount: String,
440439
currency: diesel_models::enums::Currency,
440+
transaction_reference: Option<String>,
441441
}
442442

443443
#[derive(Debug, Serialize)]
@@ -466,6 +466,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for NoonPaymentsActionRequest {
466466
item.request.currency,
467467
)?,
468468
currency: item.request.currency,
469+
transaction_reference: None,
469470
};
470471
Ok(Self {
471472
api_operation: NoonApiOperations::Capture,
@@ -507,6 +508,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for NoonPaymentsActionRequest {
507508
item.request.currency,
508509
)?,
509510
currency: item.request.currency,
511+
transaction_reference: Some(item.request.refund_id.clone()),
510512
};
511513
Ok(Self {
512514
api_operation: NoonApiOperations::Refund,
@@ -570,9 +572,11 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>
570572
}
571573

572574
#[derive(Default, Debug, Deserialize)]
575+
#[serde(rename_all = "camelCase")]
573576
pub struct NoonRefundResponseTransactions {
574577
id: String,
575578
status: RefundStatus,
579+
transaction_reference: Option<String>,
576580
}
577581

578582
#[derive(Default, Debug, Deserialize)]
@@ -592,13 +596,19 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundSyncResponse>>
592596
fn try_from(
593597
item: types::RefundsResponseRouterData<api::RSync, RefundSyncResponse>,
594598
) -> Result<Self, Self::Error> {
595-
let connector_refund_id = item.data.request.get_connector_refund_id()?;
596599
let noon_transaction: &NoonRefundResponseTransactions = item
597600
.response
598601
.result
599602
.transactions
600603
.iter()
601-
.find(|transaction| transaction.id == connector_refund_id)
604+
.find(|transaction| {
605+
transaction
606+
.transaction_reference
607+
.clone()
608+
.map_or(false, |transaction_instance| {
609+
transaction_instance == item.data.request.refund_id
610+
})
611+
})
602612
.ok_or(errors::ConnectorError::ResponseHandlingFailed)?;
603613

604614
Ok(Self {

crates/router/src/core/payments/transformers.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,11 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData
10501050
),
10511051
None => types::SyncRequestType::SinglePaymentSync,
10521052
},
1053+
payment_attempt_created_at_as_utc: payment_data
1054+
.payment_attempt
1055+
.created_at
1056+
.assume_utc()
1057+
.unix_timestamp(),
10531058
})
10541059
}
10551060
}

crates/router/src/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ pub struct PaymentsSyncData {
476476
pub connector_meta: Option<serde_json::Value>,
477477
pub sync_type: SyncRequestType,
478478
pub mandate_id: Option<api_models::payments::MandateIds>,
479+
//This is being added as a temporary fix, will be deprecated before or by v1.65.0
480+
// #2628
481+
pub payment_attempt_created_at_as_utc: i64,
479482
}
480483

481484
#[derive(Debug, Default, Clone)]

crates/router/tests/connectors/bambora.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ async fn should_sync_authorized_payment() {
108108
capture_method: Some(diesel_models::enums::CaptureMethod::Manual),
109109
sync_type: types::SyncRequestType::SinglePaymentSync,
110110
connector_meta: None,
111+
payment_attempt_created_at_as_utc: 0,
111112
}),
112113
None,
113114
)
@@ -222,6 +223,7 @@ async fn should_sync_auto_captured_payment() {
222223
capture_method: Some(enums::CaptureMethod::Automatic),
223224
sync_type: types::SyncRequestType::SinglePaymentSync,
224225
connector_meta: None,
226+
payment_attempt_created_at_as_utc: 0,
225227
}),
226228
None,
227229
)

crates/router/tests/connectors/forte.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ async fn should_sync_authorized_payment() {
153153
sync_type: types::SyncRequestType::SinglePaymentSync,
154154
connector_meta: None,
155155
mandate_id: None,
156+
payment_attempt_created_at_as_utc: 0,
156157
}),
157158
get_default_payment_info(),
158159
)

crates/router/tests/connectors/nexinets.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ async fn should_sync_authorized_payment() {
123123
sync_type: types::SyncRequestType::SinglePaymentSync,
124124
connector_meta,
125125
mandate_id: None,
126+
payment_attempt_created_at_as_utc: 0,
126127
}),
127128
None,
128129
)

crates/router/tests/connectors/paypal.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ async fn should_sync_authorized_payment() {
140140
capture_method: None,
141141
sync_type: types::SyncRequestType::SinglePaymentSync,
142142
connector_meta,
143+
payment_attempt_created_at_as_utc: 0,
143144
}),
144145
get_default_payment_info(),
145146
)
@@ -336,6 +337,7 @@ async fn should_sync_auto_captured_payment() {
336337
capture_method: Some(enums::CaptureMethod::Automatic),
337338
sync_type: types::SyncRequestType::SinglePaymentSync,
338339
connector_meta,
340+
payment_attempt_created_at_as_utc: 0,
339341
}),
340342
get_default_payment_info(),
341343
)

crates/router/tests/connectors/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ impl Default for PaymentSyncType {
942942
capture_method: None,
943943
sync_type: types::SyncRequestType::SinglePaymentSync,
944944
connector_meta: None,
945+
payment_attempt_created_at_as_utc: 0,
945946
};
946947
Self(data)
947948
}

crates/router/tests/connectors/zen.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ async fn should_sync_authorized_payment() {
102102
sync_type: types::SyncRequestType::SinglePaymentSync,
103103
connector_meta: None,
104104
mandate_id: None,
105+
payment_attempt_created_at_as_utc: 0,
105106
}),
106107
None,
107108
)
@@ -216,6 +217,7 @@ async fn should_sync_auto_captured_payment() {
216217
sync_type: types::SyncRequestType::SinglePaymentSync,
217218
connector_meta: None,
218219
mandate_id: None,
220+
payment_attempt_created_at_as_utc: 0,
219221
}),
220222
None,
221223
)

0 commit comments

Comments
 (0)