-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Bug Description
Worldpay refused payment responses are not populating error codes and error messages due to incorrect deserialization. The WorldpayPaymentResponseFields
enum incorrectly deserializes refused responses as AuthorizedResponse
instead of RefusedResponse
, causing refusalCode
and refusalDescription
fields to be silently ignored.
Expected Behavior
Refused payment responses should deserialize as RefusedResponse
and populate error details in the final response.
Actual Behavior
Refused payment responses deserialize as AuthorizedResponse
, causing error codes and messages to be missing from the client response.
Steps To Reproduce
- Process a Worldpay payment that will be refused (e.g., insufficient funds)
- Check the deserialized response structure in logs
- Observe that it matches
AuthorizedResponse
instead ofRefusedResponse
- Note that
refusalDescription
andrefusalCode
are missing from the final response
Context For The Bug
Root Cause: Enum variant ordering in WorldpayPaymentResponseFields
causes #[serde(untagged)]
to match AuthorizedResponse
first since both response types share common fields.
Sample Worldpay Response:
{
"outcome": "refused",
"refusalDescription": "Insufficient funds",
"refusalCode": "51",
"paymentInstrument": {...},
"riskFactors": [...]
}
Current Enum Order:
pub enum WorldpayPaymentResponseFields {
AuthorizedResponse(Box<AuthorizedResponse>), // Matches first
DDCResponse(DDCResponse),
FraudHighRisk(FraudHighRiskResponse),
RefusedResponse(RefusedResponse), // Never reached
ThreeDsChallenged(ThreeDsChallengedResponse),
}
Fix: Reorder enum variants to put RefusedResponse
first and add #[serde(deny_unknown_fields)]
to AuthorizedResponse
.
Environment
Are you using hyperswitch hosted version? Yes
Have you spent some time checking if this bug has been raised before?
- I checked and didn't find a similar issue
Have you read the Contributing Guidelines?
- I have read the Contributing Guidelines
Are you willing to submit a PR?
Yes, I am willing to submit a PR!