Skip to content
15 changes: 15 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -9805,6 +9805,21 @@
"type": "string",
"description": "The unified error message across all connectors.\nIf there is a translation available, this will have the translated message",
"nullable": true
},
"network_advice_code": {
"type": "string",
"description": "This field can be returned for both approved and refused Mastercard payments.\nThis code provides additional information about the type of transaction or the reason why the payment failed.\nIf the payment failed, the network advice code gives guidance on if and when you can retry the payment.",
"nullable": true
},
"network_decline_code": {
"type": "string",
"description": "For card errors resulting from a card issuer decline, a brand specific 2, 3, or 4 digit code which indicates the reason the authorization failed.",
"nullable": true
},
"network_error_message": {
"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
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5517,6 +5517,14 @@ pub struct ErrorDetails {
/// The unified error message across all connectors.
/// If there is a translation available, this will have the translated message
pub unified_message: Option<String>,
/// This field can be returned for both approved and refused Mastercard payments.
/// This code provides additional information about the type of transaction or the reason why the payment failed.
/// If the payment failed, the network advice code gives guidance on if and when you can retry the payment.
pub network_advice_code: Option<String>,
/// For card errors resulting from a card issuer decline, a brand specific 2, 3, or 4 digit code which indicates the reason the authorization failed.
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>,
}

/// Token information that can be used to initiate transactions by the merchant.
Expand Down Expand Up @@ -8609,4 +8617,12 @@ pub struct RecordAttemptErrorDetails {
pub code: String,
/// error message sent by billing connector.
pub message: String,
/// This field can be returned for both approved and refused Mastercard payments.
/// This code provides additional information about the type of transaction or the reason why the payment failed.
/// If the payment failed, the network advice code gives guidance on if and when you can retry the payment.
pub network_advice_code: Option<String>,
/// For card errors resulting from a card issuer decline, a brand specific 2, 3, or 4 digit code which indicates the reason the authorization failed.
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>,
}
14 changes: 14 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ pub struct PaymentAttempt {
pub connector_token_details: Option<ConnectorTokenDetails>,
pub id: id_type::GlobalAttemptId,
pub feature_metadata: Option<PaymentAttemptFeatureMetadata>,
/// This field can be returned for both approved and refused Mastercard payments.
/// This code provides additional information about the type of transaction or the reason why the payment failed.
/// If the payment failed, the network advice code gives guidance on if and when you can retry the payment.
pub network_advice_code: Option<String>,
/// For card errors resulting from a card issuer decline, a brand specific 2, 3, or 4 digit code which indicates the reason the authorization failed.
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>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -322,6 +330,9 @@ pub struct PaymentAttemptNew {
pub extended_authorization_applied: Option<ExtendedAuthorizationAppliedBool>,
pub capture_before: Option<PrimitiveDateTime>,
pub connector: Option<String>,
pub network_decline_code: Option<String>,
pub network_advice_code: Option<String>,
pub network_error_message: Option<String>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -846,6 +857,9 @@ pub struct PaymentAttemptUpdateInternal {
// card_network: Option<String>,
pub connector_token_details: Option<ConnectorTokenDetails>,
pub feature_metadata: Option<PaymentAttemptFeatureMetadata>,
pub network_decline_code: Option<String>,
pub network_advice_code: Option<String>,
pub network_error_message: Option<String>,
}

#[cfg(feature = "v1")]
Expand Down
5 changes: 5 additions & 0 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,11 @@ diesel::table! {
#[max_length = 64]
id -> Varchar,
feature_metadata -> Nullable<Jsonb>,
#[max_length = 32]
network_advice_code -> Nullable<Varchar>,
#[max_length = 32]
network_decline_code -> Nullable<Varchar>,
network_error_message -> Nullable<Text>,
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/hyperswitch_connectors/src/connectors/aci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ impl ConnectorCommon for Aci {
}),
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})
}
}
Expand Down
10 changes: 6 additions & 4 deletions crates/hyperswitch_connectors/src/connectors/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ impl ConnectorCommon for Adyen {
reason: Some(response.message),
attempt_status: None,
connector_transaction_id: response.psp_reference,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})
}
}
Expand Down Expand Up @@ -993,8 +994,9 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
status_code: res.status_code,
attempt_status: Some(enums::AttemptStatus::Failure),
connector_transaction_id: Some(response.psp_reference),
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
}),
..data.clone()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub struct AdditionalData {
funds_availability: Option<String>,
refusal_reason_raw: Option<String>,
refusal_code_raw: Option<String>,
merchant_advice_code: Option<String>,
#[serde(flatten)]
riskdata: Option<RiskData>,
}
Expand Down Expand Up @@ -3744,14 +3745,19 @@ pub fn get_adyen_response(
status_code,
attempt_status: None,
connector_transaction_id: Some(response.psp_reference.clone()),
issuer_error_code: response
network_advice_code: response
.additional_data
.as_ref()
.and_then(|data| data.refusal_code_raw.clone()),
issuer_error_message: response
.and_then(|data| data.extract_network_advice_code()),
network_decline_code: response
.additional_data
.as_ref()
.and_then(|data| data.refusal_reason_raw.clone()),
.and_then(|data| data.refusal_code_raw.clone()),
network_error_message: response.additional_data.as_ref().and_then(|data| {
data.refusal_reason_raw
.clone()
.or(data.merchant_advice_code.clone())
}),
})
} else {
None
Expand Down Expand Up @@ -3824,8 +3830,9 @@ pub fn get_webhook_response(
status_code,
attempt_status: None,
connector_transaction_id: Some(response.transaction_id.clone()),
issuer_error_code: response.refusal_code_raw.clone(),
issuer_error_message: response.refusal_reason_raw.clone(),
network_advice_code: None,
network_decline_code: response.refusal_code_raw.clone(),
network_error_message: response.refusal_reason_raw.clone(),
})
} else {
None
Expand Down Expand Up @@ -3891,11 +3898,12 @@ pub fn get_redirection_response(
status_code,
attempt_status: None,
connector_transaction_id: response.psp_reference.clone(),
issuer_error_code: response
network_advice_code: None,
network_decline_code: response
.additional_data
.as_ref()
.and_then(|data| data.refusal_code_raw.clone()),
issuer_error_message: response
network_error_message: response
.additional_data
.as_ref()
.and_then(|data| data.refusal_reason_raw.clone()),
Expand Down Expand Up @@ -3975,8 +3983,9 @@ pub fn get_present_to_shopper_response(
status_code,
attempt_status: None,
connector_transaction_id: response.psp_reference.clone(),
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})
} else {
None
Expand Down Expand Up @@ -4042,8 +4051,9 @@ pub fn get_qr_code_response(
status_code,
attempt_status: None,
connector_transaction_id: response.psp_reference.clone(),
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})
} else {
None
Expand Down Expand Up @@ -4101,11 +4111,15 @@ pub fn get_redirection_error_response(
status_code,
attempt_status: None,
connector_transaction_id: response.psp_reference.clone(),
issuer_error_code: response
network_advice_code: response
.additional_data
.as_ref()
.and_then(|data| data.extract_network_advice_code()),
network_decline_code: response
.additional_data
.as_ref()
.and_then(|data| data.refusal_code_raw.clone()),
issuer_error_message: response
network_error_message: response
.additional_data
.as_ref()
.and_then(|data| data.refusal_reason_raw.clone()),
Expand Down Expand Up @@ -5626,8 +5640,9 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for AcceptDisputeRouterData {
)?,
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
}),
..data.clone()
})
Expand Down Expand Up @@ -5666,8 +5681,9 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for SubmitEvidenceRouterData
)?,
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
}),
..data.clone()
})
Expand Down Expand Up @@ -5708,8 +5724,9 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for DefendDisputeRouterData {
)?,
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
}),
..data.clone()
})
Expand Down Expand Up @@ -5830,3 +5847,17 @@ impl
})
}
}

impl AdditionalData {
// Split merchant advice code into at most 2 parts and get the first part and trim spaces,
// Return the first part as a String.
pub fn extract_network_advice_code(&self) -> Option<String> {
self.merchant_advice_code.as_ref().and_then(|code| {
let mut parts = code.splitn(2, ':');
let first_part = parts.next()?.trim();
// Ensure there is a second part (meaning ':' was present).
parts.next()?;
Some(first_part.to_string())
})
}
}
5 changes: 3 additions & 2 deletions crates/hyperswitch_connectors/src/connectors/airwallex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ impl ConnectorCommon for Airwallex {
reason: response.source,
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/hyperswitch_connectors/src/connectors/amazonpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ impl ConnectorCommon for Amazonpay {
reason: response.reason,
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,9 @@ fn get_error_response(
status_code,
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})
})
.unwrap_or_else(|| ErrorResponse {
Expand All @@ -1011,8 +1012,9 @@ fn get_error_response(
status_code,
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})),
Some(authorizedotnet::TransactionResponse::AuthorizedotnetTransactionResponseError(_))
| None => {
Expand All @@ -1029,8 +1031,9 @@ fn get_error_response(
status_code,
attempt_status: None,
connector_transaction_id: None,
issuer_error_code: None,
issuer_error_message: None,
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
})
}
}
Expand Down
Loading
Loading