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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(connector): [noon] gracefully handle unknown response enum variants and missing optional fields (#13228)
Akshaya Shankar3c4fee8eb3b3
diff --git a/crates/hyperswitch_connectors/src/connectors/noon.rs b/crates/hyperswitch_connectors/src/connectors/noon.rsindex f914090e7f..9719bdd211 100644--- a/crates/hyperswitch_connectors/src/connectors/noon.rs+++ b/crates/hyperswitch_connectors/src/connectors/noon.rs@@ -40,6 +40,7 @@ use hyperswitch_interfaces::{ConnectorValidation,},configs::Connectors,+ consts::{NO_ERROR_CODE, NO_ERROR_MESSAGE},errors,events::connector_api_logs::ConnectorEvent,types::{@@ -160,6 +161,22 @@ impl ConnectorCommon for Noon {res: Response,event_builder: Option<&mut ConnectorEvent>,) -> CustomResult<ErrorResponse, errors::ConnectorError> {+ if res.response.is_empty() {+ return Ok(ErrorResponse {+ status_code: res.status_code,+ code: NO_ERROR_CODE.to_string(),+ message: NO_ERROR_MESSAGE.to_string(),+ reason: None,+ attempt_status: None,+ connector_transaction_id: None,+ connector_response_reference_id: None,+ network_advice_code: None,+ network_decline_code: None,+ network_error_message: None,+ connector_metadata: None,+ });+ }+let response: Result<noon::NoonErrorResponse, Report<common_utils::errors::ParsingError>> =res.response.parse_struct("NoonErrorResponse");@@ -897,6 +914,10 @@ impl webhooks::IncomingWebhook for Noon {request: &webhooks::IncomingWebhookRequestDetails<'_>,_context: Option<&webhooks::WebhookContext>,) -> CustomResult<IncomingWebhookEvent, errors::ConnectorError> {+ if request.body.is_empty() {+ return Ok(IncomingWebhookEvent::EndpointVerification);+ }+let details: noon::NoonWebhookEvent = request.body.parse_struct("NoonWebhookEvent")diff --git a/crates/hyperswitch_connectors/src/connectors/noon/transformers.rs b/crates/hyperswitch_connectors/src/connectors/noon/transformers.rsindex 214e586d06..0d3911a6b4 100644--- a/crates/hyperswitch_connectors/src/connectors/noon/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/noon/transformers.rs@@ -1,6 +1,6 @@use common_enums::enums::{self, AttemptStatus};use common_utils::{ext_traits::Encode, pii, request::Method, types::StringMajorUnit};-use error_stack::ResultExt;+use error_stack::{report, ResultExt};use hyperswitch_domain_models::{payment_method_data::{PaymentMethodData, WalletData},router_data::{ConnectorAuthType, ErrorResponse, RouterData},@@ -553,6 +553,8 @@ pub enum NoonPaymentStatus {Reversed,Rejected,Locked,+ #[serde(other)]+ Unknown,}fn get_payment_status(data: (NoonPaymentStatus, AttemptStatus)) -> AttemptStatus {@@ -577,6 +579,13 @@ fn get_payment_status(data: (NoonPaymentStatus, AttemptStatus)) -> AttemptStatus| NoonPaymentStatus::PaymentInfoAdded| NoonPaymentStatus::Authenticated => AttemptStatus::Started,NoonPaymentStatus::Locked => current_status,+ NoonPaymentStatus::Unknown => {+ router_env::logger::warn!(+ "Received unknown noon payment status; retaining previous status {:?}",+ current_status+ );+ current_status+ }}}@@ -785,6 +794,8 @@ impl<F> TryFrom<&NoonRouterData<&RefundsRouterData<F>>> for NoonPaymentsActionRe#[derive(Debug, Deserialize, Serialize)]pub enum NoonRevokeStatus {Cancelled,+ #[serde(other)]+ Unknown,}#[derive(Debug, Deserialize, Serialize)]@@ -828,6 +839,10 @@ impl<F>}),..item.data}),+ NoonRevokeStatus::Unknown => Err(report!(errors::ConnectorError::ResponseHandlingFailed)+ .attach_printable(+ "Received unknown noon mandate revoke status; cannot determine outcome without explicit mapping",+ )),}}}@@ -839,14 +854,22 @@ pub enum RefundStatus {Failed,#[default]Pending,+ #[serde(other)]+ Unknown,}-impl From<RefundStatus> for enums::RefundStatus {- fn from(item: RefundStatus) -> Self {- match item {- RefundStatus::Success => Self::Success,- RefundStatus::Failed => Self::Failure,- RefundStatus::Pending => Self::Pending,+fn get_refund_status(data: (RefundStatus, enums::RefundStatus)) -> enums::RefundStatus {+ let (item, current_status) = data;+ match item {+ RefundStatus::Success => enums::RefundStatus::Success,+ RefundStatus::Failed => enums::RefundStatus::Failure,+ RefundStatus::Pending => enums::RefundStatus::Pending,+ RefundStatus::Unknown => {+ router_env::logger::warn!(+ "Received unknown noon refund status; retaining previous status {:?}",+ current_status+ );+ current_status}}}@@ -869,7 +892,7 @@ pub struct NoonRefundResponseResult {pub struct RefundResponse {result: NoonRefundResponseResult,result_code: u32,- class_description: String,+ class_description: Option<String>,message: String,}@@ -879,8 +902,10 @@ impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRoutitem: RefundsResponseRouterData<Execute, RefundResponse>,) -> Result<Self, Self::Error> {let response = &item.response;- let refund_status =- enums::RefundStatus::from(response.result.transaction.status.to_owned());+ let refund_status = get_refund_status((+ response.result.transaction.status.to_owned(),+ item.data.request.refund_status,+ ));let response = if utils::is_refund_failure(refund_status) {Err(ErrorResponse {status_code: item.http_code,@@ -927,7 +952,7 @@ pub struct NoonRefundSyncResponseResult {pub struct RefundSyncResponse {result: NoonRefundSyncResponseResult,result_code: u32,- class_description: String,+ class_description: Option<String>,message: String,}@@ -950,7 +975,10 @@ impl TryFrom<RefundsResponseRouterData<RSync, RefundSyncResponse>> for RefundsRo})}).ok_or(errors::ConnectorError::ResponseHandlingFailed)?;- let refund_status = enums::RefundStatus::from(noon_transaction.status.to_owned());+ let refund_status = get_refund_status((+ noon_transaction.status.to_owned(),+ item.data.request.refund_status,+ ));let response = if utils::is_refund_failure(refund_status) {let response = &item.response;Err(ErrorResponse {@@ -1051,5 +1079,5 @@ impl From<NoonWebhookObject> for NoonPaymentsResponse {pub struct NoonErrorResponse {pub result_code: u32,pub message: String,- pub class_description: String,+ pub class_description: Option<String>,}