Skip to content

Commit

Permalink
fix(connector): [Trustpay] fix deserialization error for incoming web…
Browse files Browse the repository at this point in the history
…hook response for trustpay and add error code mapping '800.100.203' (juspay#4199)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
prasunna09 and hyperswitch-bot[bot] committed Mar 26, 2024
1 parent 4f0c788 commit 84bef25
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/router/src/connector/trustpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ impl api::IncomingWebhook for Trustpay {
dispute_stage: api_models::enums::DisputeStage::Dispute,
connector_dispute_id,
connector_reason: reason.reason.reject_reason,
connector_reason_code: Some(reason.reason.code),
connector_reason_code: reason.reason.code,
challenge_required_by: None,
connector_status: payment_info.status.to_string(),
created_at: None,
Expand Down
47 changes: 38 additions & 9 deletions crates/router/src/connector/trustpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct Amount {
#[derive(Default, Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Reason {
pub code: String,
pub code: Option<String>,
pub reject_reason: Option<String>,
}

Expand Down Expand Up @@ -510,6 +510,7 @@ fn is_payment_failed(payment_status: &str) -> (bool, &'static str) {
"800.100.172" => (true, "Transaction declined (account blocked)"),
"800.100.190" => (true, "Transaction declined (invalid configuration data)"),
"800.100.202" => (true, "Account Closed"),
"800.100.203" => (true, "Insufficient Funds"),
"800.120.100" => (true, "Rejected by throttling"),
"800.300.102" => (true, "Country blacklisted"),
"800.300.401" => (true, "Bin blacklisted"),
Expand Down Expand Up @@ -823,9 +824,16 @@ fn handle_bank_redirects_sync_response(
.status_reason_information
.unwrap_or_default();
Some(types::ErrorResponse {
code: reason_info.reason.code.clone(),
code: reason_info
.reason
.code
.clone()
.unwrap_or(consts::NO_ERROR_CODE.to_string()),
// message vary for the same code, so relying on code alone as it is unique
message: reason_info.reason.code,
message: reason_info
.reason
.code
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
reason: reason_info.reason.reject_reason,
status_code,
attempt_status: None,
Expand Down Expand Up @@ -875,9 +883,16 @@ pub fn handle_webhook_response(
.status_reason_information
.unwrap_or_default();
Some(types::ErrorResponse {
code: reason_info.reason.code.clone(),
code: reason_info
.reason
.code
.clone()
.unwrap_or(consts::NO_ERROR_CODE.to_string()),
// message vary for the same code, so relying on code alone as it is unique
message: reason_info.reason.code,
message: reason_info
.reason
.code
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
reason: reason_info.reason.reject_reason,
status_code,
attempt_status: None,
Expand Down Expand Up @@ -1483,9 +1498,16 @@ fn handle_webhooks_refund_response(
let error = if utils::is_refund_failure(refund_status) {
let reason_info = response.status_reason_information.unwrap_or_default();
Some(types::ErrorResponse {
code: reason_info.reason.code.clone(),
code: reason_info
.reason
.code
.clone()
.unwrap_or(consts::NO_ERROR_CODE.to_string()),
// message vary for the same code, so relying on code alone as it is unique
message: reason_info.reason.code,
message: reason_info
.reason
.code
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
reason: reason_info.reason.reject_reason,
status_code,
attempt_status: None,
Expand Down Expand Up @@ -1540,9 +1562,16 @@ fn handle_bank_redirects_refund_sync_response(
.status_reason_information
.unwrap_or_default();
Some(types::ErrorResponse {
code: reason_info.reason.code.clone(),
code: reason_info
.reason
.code
.clone()
.unwrap_or(consts::NO_ERROR_CODE.to_string()),
// message vary for the same code, so relying on code alone as it is unique
message: reason_info.reason.code,
message: reason_info
.reason
.code
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
reason: reason_info.reason.reject_reason,
status_code,
attempt_status: None,
Expand Down

0 comments on commit 84bef25

Please sign in to comment.