diff --git a/crates/router/src/connector/trustpay.rs b/crates/router/src/connector/trustpay.rs index 2430aac6c19f..286eaf9cb542 100644 --- a/crates/router/src/connector/trustpay.rs +++ b/crates/router/src/connector/trustpay.rs @@ -137,9 +137,11 @@ impl ConnectorCommon for Trustpay { message: option_error_code_message .map(|error_code_message| error_code_message.error_code) .unwrap_or(consts::NO_ERROR_MESSAGE.to_string()), - reason: reason.or(response_data.description), + reason: reason + .or(response_data.description) + .or(response_data.payment_description), attempt_status: None, - connector_transaction_id: None, + connector_transaction_id: response_data.instance_id, }) } Err(error_msg) => { @@ -363,19 +365,7 @@ impl ConnectorIntegration CustomResult { - let response: trustpay::TrustPayTransactionStatusErrorResponse = res - .response - .parse_struct("trustpay transaction status ErrorResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - Ok(ErrorResponse { - status_code: res.status_code, - code: response.status.to_string(), - // message vary for the same code, so relying on code alone as it is unique - message: response.status.to_string(), - reason: Some(response.payment_description), - attempt_status: None, - connector_transaction_id: None, - }) + self.build_error_response(res) } fn handle_response( diff --git a/crates/router/src/connector/trustpay/transformers.rs b/crates/router/src/connector/trustpay/transformers.rs index e985eff11976..270a702bd6ec 100644 --- a/crates/router/src/connector/trustpay/transformers.rs +++ b/crates/router/src/connector/trustpay/transformers.rs @@ -722,13 +722,13 @@ fn handle_cards_response( reason: msg, status_code, attempt_status: None, - connector_transaction_id: None, + connector_transaction_id: Some(response.instance_id.clone()), }) } else { None }; let payment_response_data = types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId(response.instance_id), + resource_id: types::ResponseId::ConnectorTransactionId(response.instance_id.clone()), redirection_data, mandate_reference: None, connector_metadata: None, @@ -825,14 +825,24 @@ fn handle_bank_redirects_sync_response( reason: reason_info.reason.reject_reason, status_code, attempt_status: None, - connector_transaction_id: None, + connector_transaction_id: Some( + response + .payment_information + .references + .payment_request_id + .clone(), + ), }) } else { None }; let payment_response_data = types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - response.payment_information.references.payment_request_id, + response + .payment_information + .references + .payment_request_id + .clone(), ), redirection_data: None, mandate_reference: None, @@ -1637,16 +1647,13 @@ pub struct Errors { } #[derive(Default, Debug, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct TrustpayErrorResponse { pub status: i64, pub description: Option, pub errors: Option>, -} - -#[derive(Deserialize)] -pub struct TrustPayTransactionStatusErrorResponse { - pub status: i64, - pub payment_description: String, + pub instance_id: Option, + pub payment_description: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]