From 82545555d79da654575decf5ed02aa6f12df6469 Mon Sep 17 00:00:00 2001 From: SamraatBansal <55536657+SamraatBansal@users.noreply.github.com> Date: Wed, 28 Jun 2023 14:34:54 +0530 Subject: [PATCH] feat(connector): [Noon] add error response handling in payments response (#1494) --- .../router/src/connector/noon/transformers.rs | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/crates/router/src/connector/noon/transformers.rs b/crates/router/src/connector/noon/transformers.rs index d98ad9c135..020aa23188 100644 --- a/crates/router/src/connector/noon/transformers.rs +++ b/crates/router/src/connector/noon/transformers.rs @@ -7,7 +7,7 @@ use crate::{ }, core::errors, services, - types::{self, api, storage::enums}, + types::{self, api, storage::enums, ErrorResponse}, }; // These needs to be accepted from SDK, need to be done after 1.0.0 stability as API contract will change @@ -280,6 +280,8 @@ pub struct NoonSubscriptionResponse { pub struct NoonPaymentsOrderResponse { status: NoonPaymentStatus, id: u64, + error_code: u64, + error_message: Option, } #[derive(Debug, Deserialize)] @@ -324,17 +326,24 @@ impl connector_mandate_id: Some(subscription_data.identifier), payment_method_id: None, }); + let order = item.response.result.order; Ok(Self { - status: enums::AttemptStatus::from(item.response.result.order.status), - response: Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId( - item.response.result.order.id.to_string(), - ), - redirection_data, - mandate_reference, - connector_metadata: None, - network_txn_id: None, - }), + status: enums::AttemptStatus::from(order.status), + response: match order.error_message { + Some(error_message) => Err(ErrorResponse { + code: order.error_code.to_string(), + message: error_message.clone(), + reason: Some(error_message), + status_code: item.http_code, + }), + _ => Ok(types::PaymentsResponseData::TransactionResponse { + resource_id: types::ResponseId::ConnectorTransactionId(order.id.to_string()), + redirection_data, + mandate_reference, + connector_metadata: None, + network_txn_id: None, + }), + }, ..item.data }) }