Skip to content

fix(connectors): graceful response deserialization for klarna#12726

Open
sai-harsha-vardhan wants to merge 1 commit into
mainfrom
fix-klarna-response-deserialization
Open

fix(connectors): graceful response deserialization for klarna#12726
sai-harsha-vardhan wants to merge 1 commit into
mainfrom
fix-klarna-response-deserialization

Conversation

@sai-harsha-vardhan

Copy link
Copy Markdown
Contributor

Summary

Adds graceful response deserialization fixes for the Klarna connector:

Changes

  • Added #[serde(other)] Unknown variant to KlarnaFraudStatus enum (used in authorize response for SDK payments)
  • Added #[serde(other)] Unknown variant to KlarnaCheckoutStatus enum (used in authorize response for redirect payments)
  • Added #[serde(other)] Unknown variant to KlarnaPaymentStatus enum (used in payment sync response)
  • Each Unknown match arm logs a warning and returns Pending status (preserves existing state rather than failing)

Notes

  • No #[serde(deny_unknown_fields)] attributes existed on any Klarna response structs — no Fix 1 changes needed
  • All response enum fields are used in business logic — no Fix 3 changes needed
  • Compilation was blocked by a pre-existing issue in hyperswitch_interfaces unrelated to Klarna

@sai-harsha-vardhan sai-harsha-vardhan requested a review from a team as a code owner June 11, 2026 15:33
@semanticdiff-com

semanticdiff-com Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/hyperswitch_connectors/src/connectors/klarna/transformers.rs  0% smaller

@XyneSpaces XyneSpaces left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: Graceful Response Deserialization for Klarna

✅ Approved

This PR applies the standard graceful deserialization fixes to the Klarna connector:

  1. Fix 2 (Enum catch-alls): Added #[serde(other)] Unknown variants to:

    • KlarnaFraudStatus (used in SDK authorize response)
    • KlarnaCheckoutStatus (used in redirect authorize response)
    • KlarnaPaymentStatus (used in PSync response)
  2. Warning logs and state preservation: All Unknown variants log warnings and return Pending status to preserve existing payment state rather than failing.

💡 Findings

1. Clean separation of concerns
Each enum has its own handler function (get_fraud_status, get_checkout_status, From<KlarnaPaymentStatus>) with consistent warning log patterns.

2. Appropriate fallback choice
Pending is the correct fallback for all Unknown variants — we don't know the actual state and shouldn't mark payments as failed/charged incorrectly.

🔍 Nit

The warning log messages vary slightly in format between the three handlers. Consider standardizing to a consistent pattern for easier log parsing:

  • "Unknown Klarna {fraud/checkout/payment} status received, preserving current state"

Verdict: Clean implementation following established patterns. Ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants