Skip to content

Conversation

Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Jul 24, 2025

Type of Change

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

Description

This pull request focuses on ensuring consistency and correctness when handling the routing_approach field across various modules in the codebase. The most significant changes involve adding .clone() to prevent ownership issues, updating the RoutingApproach enum to support additional serialization formats, and improving hashing logic.

Consistency and correctness improvements:

  • Cloning routing_approach values: Updated multiple files to ensure routing_approach values are cloned before being processed. This change avoids ownership issues and ensures data integrity. Affected files include:

    • crates/analytics/src/payments/distribution/payment_error_message.rs
    • crates/analytics/src/payments/metrics/*.rs (e.g., [1] [2] [3] etc.)
    • crates/analytics/src/payments/metrics/sessionized_metrics/*.rs (e.g., [1] [2] [3] etc.)
    • crates/router/src/services/kafka/payment_attempt.rs
  • Hashing logic update: Modified the impl Hash for PaymentMetricsBucketIdentifier to clone the routing_approach field before hashing, ensuring no ownership issues arise during the hashing process. (crates/api_models/src/analytics/payments.rs, crates/api_models/src/analytics/payments.rsL277-R280)

Enum enhancements:

  • RoutingApproach enum update: Added support for untagged serialization and a default fallback for unknown values using #[serde(untagged)] and #[strum(default)]. This ensures better compatibility with external data formats. (crates/common_enums/src/enums.rs, crates/common_enums/src/enums.rsR8562-R8564)

Minor changes:

  • Removed Copy trait from TokenDataType: This change likely reflects that the enum now includes non-Copy types or is being prepared for future modifications. (crates/common_enums/src/enums.rs, crates/common_enums/src/enums.rsL8536)

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?

  1. create a straight through payment
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_BNOaWRzwyZ3hMAbhRNtp9t6Mx7ZSVyK5gPvd1bavl0FWehvrHlre1eMifYA244TE' \
--data-raw '{
  "amount": 6540,
  "currency": "USD",
  "confirm": true,
  "capture_method": "automatic",
  "capture_on": "2022-09-10T10:11:12Z",
  "amount_to_capture": 6540,
  "customer_id": "StripeCustomer",
  "profile_id": "pro_EfD8EtQQSPZxXStG6B7x",
  "email": "guest@example.com",
  "name": "John Doe",
  "phone": "999999999",
   "routing": {
    "type": "single",
    "data": {"connector": "stripe", "merchant_connector_id": "mca_SdftCCtpClu32qA6oijC"}
  },
  "phone_country_code": "+1",
  "description": "Its my first payment request",
  "authentication_type": "three_ds",
  "return_url": "https://google.com",
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_data": {
    "card": {
      "card_number": "4242424242424242",
      "card_exp_month": "03",
      "card_exp_year": "30",
      "card_holder_name": "joseph Doe",
      "card_cvc": "737"
    }
  },
  "billing": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "NL",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "shipping": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "US",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "statement_descriptor_name": "joseph",
  "statement_descriptor_suffix": "JS",
  "metadata": {
    "udf1": "value1",
    "new_customer": "true",
    "login_date": "2019-09-10T10:11:12Z"
  },
   "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "127.0.0.1"
    }
}'

DB -
image

Clickhouse -
image

Stagger case -

  1. 3DS payment goes through older build -
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_BNOaWRzwyZ3hMAbhRNtp9t6Mx7ZSVyK5gPvd1bavl0FWehvrHlre1eMifYA244TE' \
--data-raw '{
  "amount": 6540,
  "currency": "USD",
  "confirm": true,
  "capture_method": "automatic",
  "capture_on": "2022-09-10T10:11:12Z",
  "amount_to_capture": 6540,
  "customer_id": "StripeCustomer",
  "profile_id": "pro_EfD8EtQQSPZxXStG6B7x",
  "email": "guest@example.com",
  "name": "John Doe",
  "phone": "999999999",
   "routing": {
    "type": "single",
    "data": {"connector": "stripe", "merchant_connector_id": "mca_SdftCCtpClu32qA6oijC"}
  },
  "phone_country_code": "+1",
  "description": "Its my first payment request",
  "authentication_type": "three_ds",
  "return_url": "https://google.com",
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_data": {
    "card": {
      "card_number": "4242424242424242",
      "card_exp_month": "03",
      "card_exp_year": "30",
      "card_holder_name": "joseph Doe",
      "card_cvc": "737"
    }
  },
  "billing": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "NL",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "shipping": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "US",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "statement_descriptor_name": "joseph",
  "statement_descriptor_suffix": "JS",
  "metadata": {
    "udf1": "value1",
    "new_customer": "true",
    "login_date": "2019-09-10T10:11:12Z"
  },
   "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "127.0.0.1"
    }
}'

DB -
image

  1. Redirection happens via newer build
    Clickhouse -
image

When adding new variants in the enum (example use case)-

  1. Make 3DS payment -
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_BNOaWRzwyZ3hMAbhRNtp9t6Mx7ZSVyK5gPvd1bavl0FWehvrHlre1eMifYA244TE' \
--data-raw '{
  "amount": 6540,
  "currency": "USD",
  "confirm": true,
  "capture_method": "automatic",
  "capture_on": "2022-09-10T10:11:12Z",
  "amount_to_capture": 6540,
  "customer_id": "StripeCustomer",
  "profile_id": "pro_EfD8EtQQSPZxXStG6B7x",
  "email": "guest@example.com",
  "name": "John Doe",
  "phone": "999999999",
   "routing": {
    "type": "single",
    "data": {"connector": "stripe", "merchant_connector_id": "mca_SdftCCtpClu32qA6oijC"}
  },
  "phone_country_code": "+1",
  "description": "Its my first payment request",
  "authentication_type": "three_ds",
  "return_url": "https://google.com",
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_data": {
    "card": {
      "card_number": "4242424242424242",
      "card_exp_month": "03",
      "card_exp_year": "30",
      "card_holder_name": "joseph Doe",
      "card_cvc": "737"
    }
  },
  "billing": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "NL",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "shipping": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "US",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "statement_descriptor_name": "joseph",
  "statement_descriptor_suffix": "JS",
  "metadata": {
    "udf1": "value1",
    "new_customer": "true",
    "login_date": "2019-09-10T10:11:12Z"
  },
   "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "127.0.0.1"
    }
}'
  • An new unknown DB enum variant written by new application (composite_routing) -
image
  • The Application maps it to the other variant (kafka log for the same) -
image - Application pushes the new variant to kafka, which is picked by clickhouse. image
  1. Sync for the same payment succeeds -
curl --location 'http://localhost:8080/payments/pay_6jXoHSKmcESyJ9vWZUIo' \
--header 'Accept: application/json' \
--header 'api-key: dev_BNOaWRzwyZ3hMAbhRNtp9t6Mx7ZSVyK5gPvd1bavl0FWehvrHlre1eMifYA244TE'
{"payment_id":"pay_6jXoHSKmcESyJ9vWZUIo","merchant_id":"merchant_1749723893","status":"succeeded","amount":6540,"net_amount":6540,"shipping_cost":null,"amount_capturable":0,"amount_received":6540,"connector":"stripe","client_secret":"pay_6jXoHSKmcESyJ9vWZUIo_secret_fxLf6seO9OfTw9C89bJH","created":"2025-07-25T09:45:06.719Z","currency":"USD","customer_id":"StripeCustomer","customer":{"id":"StripeCustomer","name":"John Doe","email":"guest@example.com","phone":"999999999","phone_country_code":"+1"},"description":"Its my first payment request","refunds":null,"disputes":null,"mandate_id":null,"mandate_data":null,"setup_future_usage":null,"off_session":null,"capture_on":null,"capture_method":"automatic","payment_method":"card","payment_method_data":{"card":{"last4":"4242","card_type":null,"card_network":null,"card_issuer":null,"card_issuing_country":null,"card_isin":"424242","card_extended_bin":null,"card_exp_month":"03","card_exp_year":"30","card_holder_name":"joseph Doe","payment_checks":null,"authentication_data":null},"billing":null},"payment_token":null,"shipping":{"address":{"city":"San Fransico","country":"US","line1":"1467","line2":"Harrison Street","line3":"Harrison Street","zip":"94122","state":"California","first_name":"joseph","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":null},"billing":{"address":{"city":"San Fransico","country":"NL","line1":"1467","line2":"Harrison Street","line3":"Harrison Street","zip":"94122","state":"California","first_name":"joseph","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":null},"order_details":null,"email":"guest@example.com","name":"John Doe","phone":"999999999","return_url":"https://google.com/","authentication_type":"three_ds","statement_descriptor_name":"joseph","statement_descriptor_suffix":"JS","next_action":null,"cancellation_reason":null,"error_code":null,"error_message":null,"unified_code":null,"unified_message":null,"payment_experience":null,"payment_method_type":"credit","connector_label":null,"business_country":null,"business_label":"default","business_sub_label":null,"allowed_payment_method_types":null,"ephemeral_key":null,"manual_retry_allowed":false,"connector_transaction_id":"pi_3RoiBbD5R7gDAGff0Aj7Gibb","frm_message":null,"metadata":{"udf1":"value1","login_date":"2019-09-10T10:11:12Z","new_customer":"true"},"connector_metadata":null,"feature_metadata":null,"reference_id":"pi_3RoiBbD5R7gDAGff0Aj7Gibb","payment_link":null,"profile_id":"pro_EfD8EtQQSPZxXStG6B7x","surcharge_details":null,"attempt_count":1,"merchant_decision":null,"merchant_connector_id":"mca_SdftCCtpClu32qA6oijC","incremental_authorization_allowed":null,"authorization_count":null,"incremental_authorizations":null,"external_authentication_details":null,"external_3ds_authentication_attempted":false,"expires_on":"2025-07-25T10:00:06.719Z","fingerprint":null,"browser_info":{"language":"nl-NL","time_zone":0,"ip_address":"127.0.0.1","user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","color_depth":24,"java_enabled":true,"screen_width":1536,"accept_header":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","screen_height":723,"java_script_enabled":true},"payment_method_id":null,"payment_method_status":null,"updated":"2025-07-25T09:47:47.820Z","split_payments":null,"frm_metadata":null,"extended_authorization_applied":null,"capture_before":null,"merchant_order_reference_id":null,"order_tax_amount":null,"connector_mandate_id":null,"card_discovery":"manual","force_3ds_challenge":false,"force_3ds_challenge_trigger":false,"issuer_error_code":null,"issuer_error_message":null,"is_iframe_redirection_enabled":null,"whole_connector_response":null}

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

@Sarthak1799 Sarthak1799 self-assigned this Jul 24, 2025
@Sarthak1799 Sarthak1799 requested review from a team as code owners July 24, 2025 12:56
Copy link

semanticdiff-com bot commented Jul 24, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/routing.rs  83% smaller
  crates/api_models/src/analytics/payments.rs  80% smaller
  crates/hyperswitch_domain_models/src/payments/payment_attempt.rs  26% smaller
  crates/analytics/src/payments/distribution/payment_error_message.rs  0% smaller
  crates/analytics/src/payments/metrics/avg_ticket_size.rs  0% smaller
  crates/analytics/src/payments/metrics/connector_success_rate.rs  0% smaller
  crates/analytics/src/payments/metrics/debit_routing.rs  0% smaller
  crates/analytics/src/payments/metrics/payment_count.rs  0% smaller
  crates/analytics/src/payments/metrics/payment_processed_amount.rs  0% smaller
  crates/analytics/src/payments/metrics/payment_success_count.rs  0% smaller
  crates/analytics/src/payments/metrics/retries_count.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/avg_ticket_size.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/connector_success_rate.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/debit_routing.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/failure_reasons.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/payment_count.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/payment_processed_amount.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/payment_success_count.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/payments_distribution.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/retries_count.rs  0% smaller
  crates/analytics/src/payments/metrics/sessionized_metrics/success_rate.rs  0% smaller
  crates/analytics/src/payments/metrics/success_rate.rs  0% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/router/src/core/payments.rs  0% smaller
  crates/router/src/core/payments/operations/payment_create.rs  0% smaller
  crates/router/src/services/kafka/payment_attempt.rs  0% smaller
  crates/router/src/services/kafka/payment_attempt_event.rs  0% smaller
  crates/storage_impl/src/payments/payment_attempt.rs  0% smaller

@Sarthak1799 Sarthak1799 linked an issue Jul 24, 2025 that may be closed by this pull request
2 tasks
@Sarthak1799 Sarthak1799 requested review from a team as code owners July 24, 2025 14:53
jagan-jaya
jagan-jaya previously approved these changes Jul 25, 2025
tsdk02
tsdk02 previously approved these changes Jul 25, 2025
@Sarthak1799 Sarthak1799 dismissed stale reviews from tsdk02 and jagan-jaya via 95c6d34 July 25, 2025 09:16
@likhinbopanna likhinbopanna added this pull request to the merge queue Jul 28, 2025
Merged via the queue into main with commit 7682cd4 Jul 28, 2025
15 of 20 checks passed
@likhinbopanna likhinbopanna deleted the routing-approach-other-variant branch July 28, 2025 07:43
pixincreate added a commit that referenced this pull request Jul 28, 2025
…rver

* 'main' of github.com:juspay/hyperswitch: (24 commits)
  chore(version): 2025.07.28.1
  feat(core): Hyperswitch <|> UCS Mandate flow integration (#8738)
  feat(themes): Create user APIs for managing themes (#8387)
  chore: update devDependencies for cypress (#8735)
  refactor: Add routing_approach other variant to handle unknown data (#8754)
  chore(version): 2025.07.28.0
  refactor(connector): [facilitapay] move destination bank account number to connector metadata (#8704)
  feat(recovery-events): add revenue recovery topic and vector config to push these events to s3 (#8285)
  ci(cypress): add authorizedotnet connector (#8688)
  refactor(schema): add a new column for storing large customer user agents in mandate table (#8616)
  feat(authentication): add authentication api for modular authentication (#8459)
  feat(connector): [MPGS] template code (#8544)
  fix(chat): append request id to headers for chat request (#8680)
  feat(connector): [Flexiti]template code for flexiti connector (#8714)
  chore(version): 2025.07.25.0
  feat(core): Consuming locale in PaymentsAuthorizeData from SessionState (#8731)
  fix(payment-methods): fetch payment method details in payouts flow (#8729)
  refactor(core): remove hardcoded timeout limit of 5s for outgoing webhook requests (#8725)
  feat(connector): [Breadpay]Add support for Breadpay connector (#8676)
  fix(feature_matrix): refunds are supported by jpmorgan (#8699)
  ...
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.

[REFACTOR] Add new variant for routing approach
5 participants