Skip to content

Commit 053c79d

Browse files
refactor(connector): [noon] enhance response status mapping (#2575)
1 parent 92f7918 commit 053c79d

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

crates/router/src/connector/noon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ impl ConnectorCommon for Noon {
134134
Ok(ErrorResponse {
135135
status_code: res.status_code,
136136
code: response.result_code.to_string(),
137-
message: response.message,
138-
reason: Some(response.class_description),
137+
message: response.class_description,
138+
reason: Some(response.message),
139139
})
140140
}
141141
}

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
},
1010
core::errors,
1111
services,
12-
types::{self, api, storage::enums, ErrorResponse},
12+
types::{self, api, storage::enums, transformers::ForeignFrom, ErrorResponse},
1313
utils,
1414
};
1515

@@ -356,35 +356,53 @@ impl TryFrom<&types::ConnectorAuthType> for NoonAuthType {
356356
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
357357
#[strum(serialize_all = "UPPERCASE")]
358358
pub enum NoonPaymentStatus {
359+
Initiated,
359360
Authorized,
360361
Captured,
361362
PartiallyCaptured,
362-
Reversed,
363-
Cancelled,
363+
PartiallyRefunded,
364+
PaymentInfoAdded,
364365
#[serde(rename = "3DS_ENROLL_INITIATED")]
365366
ThreeDsEnrollInitiated,
366367
#[serde(rename = "3DS_ENROLL_CHECKED")]
367368
ThreeDsEnrollChecked,
368-
Failed,
369+
#[serde(rename = "3DS_RESULT_VERIFIED")]
370+
ThreeDsResultVerified,
371+
MarkedForReview,
372+
Authenticated,
373+
PartiallyReversed,
369374
#[default]
370375
Pending,
376+
Cancelled,
377+
Failed,
378+
Refunded,
371379
Expired,
380+
Reversed,
372381
Rejected,
382+
Locked,
373383
}
374384

375-
impl From<NoonPaymentStatus> for enums::AttemptStatus {
376-
fn from(item: NoonPaymentStatus) -> Self {
385+
impl ForeignFrom<(NoonPaymentStatus, Self)> for enums::AttemptStatus {
386+
fn foreign_from(data: (NoonPaymentStatus, Self)) -> Self {
387+
let (item, current_status) = data;
377388
match item {
378389
NoonPaymentStatus::Authorized => Self::Authorized,
379-
NoonPaymentStatus::Captured => Self::Charged,
380-
NoonPaymentStatus::PartiallyCaptured => Self::PartialCharged,
381-
NoonPaymentStatus::Reversed => Self::Voided,
390+
NoonPaymentStatus::Captured
391+
| NoonPaymentStatus::PartiallyCaptured
392+
| NoonPaymentStatus::PartiallyRefunded
393+
| NoonPaymentStatus::Refunded => Self::Charged,
394+
NoonPaymentStatus::Reversed | NoonPaymentStatus::PartiallyReversed => Self::Voided,
382395
NoonPaymentStatus::Cancelled | NoonPaymentStatus::Expired => Self::AuthenticationFailed,
383396
NoonPaymentStatus::ThreeDsEnrollInitiated | NoonPaymentStatus::ThreeDsEnrollChecked => {
384397
Self::AuthenticationPending
385398
}
399+
NoonPaymentStatus::ThreeDsResultVerified => Self::AuthenticationSuccessful,
386400
NoonPaymentStatus::Failed | NoonPaymentStatus::Rejected => Self::Failure,
387-
NoonPaymentStatus::Pending => Self::Pending,
401+
NoonPaymentStatus::Pending | NoonPaymentStatus::MarkedForReview => Self::Pending,
402+
NoonPaymentStatus::Initiated
403+
| NoonPaymentStatus::PaymentInfoAdded
404+
| NoonPaymentStatus::Authenticated => Self::Started,
405+
NoonPaymentStatus::Locked => current_status,
388406
}
389407
}
390408
}
@@ -448,7 +466,7 @@ impl<F, T>
448466
});
449467
let order = item.response.result.order;
450468
Ok(Self {
451-
status: enums::AttemptStatus::from(order.status),
469+
status: enums::AttemptStatus::foreign_from((order.status, item.data.status)),
452470
response: match order.error_message {
453471
Some(error_message) => Err(ErrorResponse {
454472
code: order.error_code.to_string(),

0 commit comments

Comments
 (0)