Skip to content

feat(core): populate UCS status_code in response headers #8788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api-reference/v2/openapi_spec_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -10566,6 +10566,12 @@
"type": "string",
"description": "A string indicating how to proceed with an network error if payment gateway provide one. This is used to understand the network error code better.",
"nullable": true
},
"status_code": {
"type": "integer",
"format": "int32",
"description": "HTTP status code returned by the connector",
"nullable": true
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5702,6 +5702,8 @@ pub struct ErrorDetails {
pub network_decline_code: Option<String>,
/// A string indicating how to proceed with an network error if payment gateway provide one. This is used to understand the network error code better.
pub network_error_message: Option<String>,
/// HTTP status code returned by the connector
pub status_code: Option<i32>,
}

/// Token information that can be used to initiate transactions by the merchant.
Expand Down
5 changes: 5 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub struct PaymentAttempt {
/// A string indicating how to proceed with an network error if payment gateway provide one. This is used to understand the network error code better.
pub network_error_message: Option<String>,
pub connector_request_reference_id: Option<String>,
pub status_code: Option<i32>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -346,6 +347,7 @@ pub struct PaymentAttemptNew {
pub processor_merchant_id: Option<id_type::MerchantId>,
pub created_by: Option<String>,
pub connector_request_reference_id: Option<String>,
pub status_code: Option<i32>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -883,6 +885,7 @@ pub struct PaymentAttemptUpdateInternal {
pub network_advice_code: Option<String>,
pub network_error_message: Option<String>,
pub connector_request_reference_id: Option<String>,
pub status_code: Option<i32>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -914,6 +917,7 @@ impl PaymentAttemptUpdateInternal {
payment_method_id,
connector_request_reference_id,
connector_response_reference_id,
status_code,
} = self;

PaymentAttempt {
Expand Down Expand Up @@ -990,6 +994,7 @@ impl PaymentAttemptUpdateInternal {
network_error_message: network_error_message.or(source.network_error_message),
connector_request_reference_id: connector_request_reference_id
.or(source.connector_request_reference_id),
status_code: status_code.or(source.status_code),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ diesel::table! {
network_error_message -> Nullable<Text>,
#[max_length = 255]
connector_request_reference_id -> Nullable<Varchar>,
status_code -> Nullable<Int4>,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/external_services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ reqwest = { version = "0.11.27", features = ["rustls-tls"] }
http = "0.2.12"
url = { version = "2.5.4", features = ["serde"] }
quick-xml = { version = "0.31.0", features = ["serialize"] }
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "a9f7cd96693fa034ea69d8e21125ea0f76182fae", package = "rust-grpc-client" }
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "40b6e227430664986a4c36c216b84c149309a9ea", package = "rust-grpc-client" }


# First party crates
Expand Down
1 change: 1 addition & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ impl From<&api_models::payments::RecordAttemptErrorDetails>
network_advice_code: error.network_advice_code.clone(),
network_decline_code: error.network_decline_code.clone(),
network_error_message: error.network_error_message.clone(),
status_code: None,
}
}
}
14 changes: 14 additions & 0 deletions crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ pub struct ErrorDetails {
pub network_decline_code: Option<String>,
/// A string indicating how to proceed with an network error if payment gateway provide one. This is used to understand the network error code better.
pub network_error_message: Option<String>,
/// HTTP status code returned by the connector
pub status_code: Option<i32>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2371,6 +2373,7 @@ impl behaviour::Conversion for PaymentAttempt {
processor_merchant_id: Some(processor_merchant_id),
created_by: created_by.map(|cb| cb.to_string()),
connector_request_reference_id,
status_code: error.as_ref().and_then(|details| details.status_code),
})
}

Expand Down Expand Up @@ -2438,6 +2441,7 @@ impl behaviour::Conversion for PaymentAttempt {
network_advice_code: storage_model.network_advice_code,
network_decline_code: storage_model.network_decline_code,
network_error_message: storage_model.network_error_message,
status_code: storage_model.status_code,
});

Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
Expand Down Expand Up @@ -2645,6 +2649,9 @@ impl behaviour::Conversion for PaymentAttempt {
processor_merchant_id: Some(processor_merchant_id),
created_by: created_by.map(|cb| cb.to_string()),
connector_request_reference_id,
status_code: error_details
.as_ref()
.and_then(|details| details.status_code),
})
}
}
Expand Down Expand Up @@ -2687,6 +2694,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
network_error_message: None,
connector_request_reference_id,
connector_response_reference_id,
status_code: None,
},
PaymentAttemptUpdate::ErrorUpdate {
status,
Expand Down Expand Up @@ -2720,6 +2728,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
network_error_message: error.network_error_message,
connector_request_reference_id: None,
connector_response_reference_id: None,
status_code: error.status_code,
},
PaymentAttemptUpdate::ConfirmIntentResponse(confirm_intent_response_update) => {
let ConfirmIntentResponseUpdate {
Expand Down Expand Up @@ -2759,6 +2768,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
network_error_message: None,
connector_request_reference_id: None,
connector_response_reference_id,
status_code: None,
}
}
PaymentAttemptUpdate::SyncUpdate {
Expand Down Expand Up @@ -2791,6 +2801,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
network_error_message: None,
connector_request_reference_id: None,
connector_response_reference_id: None,
status_code: None,
},
PaymentAttemptUpdate::CaptureUpdate {
status,
Expand Down Expand Up @@ -2822,6 +2833,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
network_error_message: None,
connector_request_reference_id: None,
connector_response_reference_id: None,
status_code: None,
},
PaymentAttemptUpdate::PreCaptureUpdate {
amount_to_capture,
Expand Down Expand Up @@ -2852,6 +2864,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
network_error_message: None,
connector_request_reference_id: None,
connector_response_reference_id: None,
status_code: None,
},
PaymentAttemptUpdate::ConfirmIntentTokenized {
status,
Expand Down Expand Up @@ -2886,6 +2899,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
network_error_message: None,
connector_request_reference_id: None,
connector_response_reference_id: None,
status_code: None,
},
}
}
Expand Down
12 changes: 8 additions & 4 deletions crates/hyperswitch_domain_models/src/router_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ impl
code,
message,
reason,
status_code: _,
status_code,
attempt_status: _,
connector_transaction_id,
network_decline_code,
Expand All @@ -668,6 +668,7 @@ impl
network_advice_code,
network_decline_code,
network_error_message,
status_code: Some(i32::from(status_code)),
};

PaymentAttemptUpdate::ErrorUpdate {
Expand Down Expand Up @@ -850,7 +851,7 @@ impl
code,
message,
reason,
status_code: _,
status_code,
attempt_status,
connector_transaction_id,
network_advice_code,
Expand All @@ -868,6 +869,7 @@ impl
network_advice_code,
network_decline_code,
network_error_message,
status_code: Some(i32::from(status_code)),
};

PaymentAttemptUpdate::ErrorUpdate {
Expand Down Expand Up @@ -1075,7 +1077,7 @@ impl
code,
message,
reason,
status_code: _,
status_code,
attempt_status: _,
connector_transaction_id,
network_advice_code,
Expand All @@ -1101,6 +1103,7 @@ impl
network_advice_code,
network_decline_code,
network_error_message,
status_code: Some(i32::from(status_code)),
};

PaymentAttemptUpdate::ErrorUpdate {
Expand Down Expand Up @@ -1330,7 +1333,7 @@ impl
code,
message,
reason,
status_code: _,
status_code,
attempt_status,
connector_transaction_id,
network_advice_code,
Expand All @@ -1348,6 +1351,7 @@ impl
network_advice_code,
network_decline_code,
network_error_message,
status_code: Some(i32::from(status_code)),
};

PaymentAttemptUpdate::ErrorUpdate {
Expand Down
2 changes: 1 addition & 1 deletion crates/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ reqwest = { version = "0.11.27", features = ["json", "rustls-tls", "gzip", "mult
ring = "0.17.14"
rust_decimal = { version = "1.37.1", features = ["serde-with-float", "serde-with-str"] }
rust-i18n = { git = "https://github.com/kashif-m/rust-i18n", rev = "f2d8096aaaff7a87a847c35a5394c269f75e077a" }
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "a9f7cd96693fa034ea69d8e21125ea0f76182fae", package = "rust-grpc-client" }
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "40b6e227430664986a4c36c216b84c149309a9ea", package = "rust-grpc-client" }
rustc-hash = "1.1.0"
rustls = "0.22"
rustls-pemfile = "2"
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5160,6 +5160,7 @@ impl ForeignFrom<&hyperswitch_domain_models::payments::payment_attempt::ErrorDet
network_advice_code: error_details.network_advice_code.clone(),
network_decline_code: error_details.network_decline_code.clone(),
network_error_message: error_details.network_error_message.clone(),
status_code: error_details.status_code,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,18 @@ impl ForeignTryFrom<payments_grpc::PaymentServiceAuthorizeResponse>
})
});

let status_code = u16::try_from(response.status_code.unwrap_or(500)).map_err(|_| {
UnifiedConnectorServiceError::RequestEncodingFailedWithReason(
"Failed to convert status code to u16".to_string(),
)
})?;

let response = if response.error_code.is_some() {
Err(ErrorResponse {
code: response.error_code().to_owned(),
message: response.error_message().to_owned(),
reason: Some(response.error_message().to_owned()),
status_code: 500, //TODO: To be handled once UCS sends proper status codes
status_code,
attempt_status: Some(status),
connector_transaction_id: connector_response_reference_id,
network_decline_code: None,
Expand Down Expand Up @@ -426,12 +432,18 @@ impl ForeignTryFrom<payments_grpc::PaymentServiceGetResponse>
})
});

let status_code = u16::try_from(response.status_code.unwrap_or(500)).map_err(|_| {
UnifiedConnectorServiceError::RequestEncodingFailedWithReason(
"Failed to convert status code to u16".to_string(),
)
})?;

let response = if response.error_code.is_some() {
Err(ErrorResponse {
code: response.error_code().to_owned(),
message: response.error_message().to_owned(),
reason: Some(response.error_message().to_owned()),
status_code: 500, //TODO: To be handled once UCS sends proper status codes
status_code,
attempt_status: Some(status),
connector_transaction_id: connector_response_reference_id,
network_decline_code: None,
Expand Down Expand Up @@ -485,12 +497,18 @@ impl ForeignTryFrom<payments_grpc::PaymentServiceRegisterResponse>
})
});

let status_code = u16::try_from(response.status_code.unwrap_or(500)).map_err(|_| {
UnifiedConnectorServiceError::RequestEncodingFailedWithReason(
"Failed to convert status code to u16".to_string(),
)
})?;

let response = if response.error_code.is_some() {
Err(ErrorResponse {
code: response.error_code().to_owned(),
message: response.error_message().to_owned(),
reason: Some(response.error_message().to_owned()),
status_code: 500, //TODO: To be handled once UCS sends proper status codes
status_code,
attempt_status: Some(status),
connector_transaction_id: connector_response_reference_id,
network_decline_code: None,
Expand Down Expand Up @@ -574,12 +592,18 @@ impl ForeignTryFrom<payments_grpc::PaymentServiceRepeatEverythingResponse>
})
});

let status_code = u16::try_from(response.status_code.unwrap_or(500)).map_err(|_| {
UnifiedConnectorServiceError::RequestEncodingFailedWithReason(
"Failed to convert status code to u16".to_string(),
)
})?;

let response = if response.error_code.is_some() {
Err(ErrorResponse {
code: response.error_code().to_owned(),
message: response.error_message().to_owned(),
reason: Some(response.error_message().to_owned()),
status_code: 500, //TODO: To be handled once UCS sends proper status codes
status_code,
attempt_status: Some(status),
connector_transaction_id: transaction_id,
network_decline_code: None,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE payment_attempt
DROP COLUMN IF EXISTS status_code;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE payment_attempt
ADD COLUMN IF NOT EXISTS status_code INTEGER;
Loading