Skip to content
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

feat(connector): accept connector_transaction_id in error_response of connector flows for Trustpay #3060

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 5 additions & 15 deletions crates/router/src/connector/trustpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -363,19 +365,7 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
&self,
res: Response,
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
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(
Expand Down
27 changes: 17 additions & 10 deletions crates/router/src/connector/trustpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for bank redirects do we get payment_request_id instead of instance_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we use bank payment_request_id instead of instance_id for bank redirects. Ref page.no 333 of trustpay.rs

.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,
Expand Down Expand Up @@ -1637,16 +1647,13 @@ pub struct Errors {
}

#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm TrustPayTransactionStatusErrorResponse also requires camelCase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the struct TrustPayTransactionStatusErrorResponse is required to be a camelCase
Screenshot 2023-12-06 at 11 49 36 AM

pub struct TrustpayErrorResponse {
pub status: i64,
pub description: Option<String>,
pub errors: Option<Vec<Errors>>,
}

#[derive(Deserialize)]
pub struct TrustPayTransactionStatusErrorResponse {
pub status: i64,
pub payment_description: String,
pub instance_id: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't get instance_id for bank redirects failures right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes instance_id is not provided during all error scenarios.

pub payment_description: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down
Loading