Skip to content

[BUG] refused payment responses missing error codes and messages for Access Worldpay #8687

@kashif-m

Description

@kashif-m

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

  1. Process a Worldpay payment that will be refused (e.g., insufficient funds)
  2. Check the deserialized response structure in logs
  3. Observe that it matches AuthorizedResponse instead of RefusedResponse
  4. Note that refusalDescription and refusalCode 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?

Are you willing to submit a PR?

Yes, I am willing to submit a PR!

Sub-issues

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions