Skip to content

fix(framework): Store Card Network In DB For Network Token Passthrough Request#13077

Open
Anurag-05-prog wants to merge 1 commit into
mainfrom
fix/populate-nt-card-network
Open

fix(framework): Store Card Network In DB For Network Token Passthrough Request#13077
Anurag-05-prog wants to merge 1 commit into
mainfrom
fix/populate-nt-card-network

Conversation

@Anurag-05-prog

Copy link
Copy Markdown
Contributor

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Storing card network in DB for network token passthrough request

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@Anurag-05-prog Anurag-05-prog self-assigned this Jun 30, 2026
@Anurag-05-prog Anurag-05-prog added the S-test-ready Status: This PR is ready for cypress-tests label Jun 30, 2026
@Anurag-05-prog Anurag-05-prog requested a review from a team as a code owner June 30, 2026 08:32
@semanticdiff-com

semanticdiff-com Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/api_models/src/payments.rs  47% smaller
  crates/hyperswitch_domain_models/src/payments/payment_attempt.rs  31% smaller

@github-actions github-actions Bot removed the S-test-ready Status: This PR is ready for cypress-tests label Jun 30, 2026
@XyneSpaces

Copy link
Copy Markdown

💡 Consider using Option flattening for cleaner card network extraction

The current implementation uses nested and_then with or_else. Consider using Option::or for cleaner code:

.and_then(|obj| {
    obj.get("card")
        .and_then(|card| card.as_object())
        .and_then(|card_data| card_data.get("card_network"))
        .or_else(|| {
            obj.get("network_token")
                .and_then(|nt| nt.as_object())
                .and_then(|nt_data| nt_data.get("card_network"))
        })
})

This is a minor style suggestion - the current code is functionally correct.

@XyneSpaces

Copy link
Copy Markdown

💡 Nested JSON access pattern could be more robust

In payment_attempt.rs, the nested and_then chains for accessing card_network from both card and network_token paths work but are verbose. Consider extracting a helper function:

fn extract_card_network_from_payment_method_data(
    obj: &serde_json::Map<String, Value>
) -> Option<String> {
    ["card", "network_token"]
        .iter()
        .find_map(|key| {
            obj.get(key)
                .and_then(|v| v.as_object())
                .and_then(|data| data.get("card_network"))
                .and_then(|v| v.as_str())
                .map(String::from)
        })
}

This reduces duplication and makes the intent clearer. Same pattern applies to both locations (~lines 2915 and ~lines 3178).

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