Skip to content

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Jun 3, 2025

Type of Change

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

Description

In the case of debit routing flow, the routing output (CallConnectorType) will include both the connector and its associated card network. In our current implementation, we simply iterate over the connector list and pass the connector. With the updated requirement, we will also need to pass the corresponding card network for each connector in the case of debit routing.

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?

Create a business profile and enable debit routing for it

curl --location 'http://localhost:8080/account/merchant_1748851578/business_profile/pro_gEwS6ve9KVqywWL0hmAq' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: ' \
--data '{
    "is_debit_routing_enabled": true
}'

-> Create a adyen connector
-> I have created a db entry that contains the wrong card network so that the payment can be retried

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-feature: router-custom' \
--header 'x-tenant-id: hyperswitch' \
--header 'api-key: ' \
--data-raw '{
    "amount": 10000,
    "amount_to_capture": 10000,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "setup_future_usage": "on_session",
    "capture_on": "2022-09-10T10:11:12Z",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "customer_id": "cu_1748948839",
    "return_url": "http://127.0.0.1:4040",
    "payment_method": "card",
    "payment_method_type": "debit",
    "payment_method_data": {
        "card": {
            "card_number": "4000033003300335",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "737"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "email": "[email protected]"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        }
    },
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "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": "125.0.0.1"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
{
    "payment_id": "pay_JMfKcXwsfYNl06UWsCc0",
    "merchant_id": "merchant_1748851578",
    "status": "succeeded",
    "amount": 10000,
    "net_amount": 10000,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 10000,
    "connector": "adyen",
    "client_secret": "pay_JMfKcXwsfYNl06UWsCc0_secret_IHW3HhesmOpMBaUyGd8l",
    "created": "2025-06-03T11:07:12.121Z",
    "currency": "USD",
    "customer_id": "cu_1748948832",
    "customer": {
        "id": "cu_1748948832",
        "name": "John Doe",
        "email": "[email protected]",
        "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": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "0335",
            "card_type": "DEBIT",
            "card_network": "Visa",
            "card_issuer": "VISA U.S.A. INC.",
            "card_issuing_country": "UNITEDSTATES",
            "card_isin": "400003",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "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": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "http://127.0.0.1:4040/",
    "authentication_type": "no_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": "debit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cu_1748948832",
        "created_at": 1748948832,
        "expires": 1748952432,
        "secret": "epk_caf2195bee8848358df1077b25cf2a73"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "DF4NDC3W8WH68775",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_JMfKcXwsfYNl06UWsCc0_2",
    "payment_link": null,
    "profile_id": "pro_gEwS6ve9KVqywWL0hmAq",
    "surcharge_details": null,
    "attempt_count": 2,
    "merchant_decision": null,
    "merchant_connector_id": "mca_zMyPaKk9qUVauLL7wFrV",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-06-03T11:22:12.120Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "125.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-06-03T11:07:15.083Z",
    "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
}

-> the payment response contains two attempts
-> List all the attempts for a payments

curl --location 'http://localhost:8080/payments/pay_JMfKcXwsfYNl06UWsCc0?force_sync=true&expand_attempts=true' \
--header 'Accept: application/json' \
--header 'api-key: '
{
    "payment_id": "pay_JMfKcXwsfYNl06UWsCc0",
    "merchant_id": "merchant_1748851578",
    "status": "succeeded",
    "amount": 10000,
    "net_amount": 10000,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 10000,
    "connector": "adyen",
    "client_secret": "pay_JMfKcXwsfYNl06UWsCc0_secret_IHW3HhesmOpMBaUyGd8l",
    "created": "2025-06-03T11:07:12.121Z",
    "currency": "USD",
    "customer_id": "cu_1748948832",
    "customer": {
        "id": "cu_1748948832",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "attempts": [
        {
            "attempt_id": "pay_JMfKcXwsfYNl06UWsCc0_2",
            "status": "charged",
            "amount": 10000,
            "order_tax_amount": null,
            "currency": "USD",
            "connector": "adyen",
            "error_message": null,
            "payment_method": "card",
            "connector_transaction_id": "DF4NDC3W8WH68775",
            "capture_method": "automatic",
            "authentication_type": "no_three_ds",
            "created_at": "2025-06-03T11:07:14.071Z",
            "modified_at": "2025-06-03T11:07:15.143Z",
            "cancellation_reason": null,
            "mandate_id": null,
            "error_code": null,
            "payment_token": null,
            "connector_metadata": null,
            "payment_experience": null,
            "payment_method_type": "debit",
            "reference_id": "pay_JMfKcXwsfYNl06UWsCc0_2",
            "unified_code": null,
            "unified_message": null,
            "client_source": null,
            "client_version": null
        },
        {
            "attempt_id": "pay_JMfKcXwsfYNl06UWsCc0_1",
            "status": "failure",
            "amount": 10000,
            "order_tax_amount": null,
            "currency": "USD",
            "connector": "adyen",
            "error_message": "Invalid variant",
            "payment_method": "card",
            "connector_transaction_id": "ZBRJ4V4RGLQD2HV5",
            "capture_method": "automatic",
            "authentication_type": "no_three_ds",
            "created_at": "2025-06-03T11:07:12.121Z",
            "modified_at": "2025-06-03T11:07:14.075Z",
            "cancellation_reason": null,
            "mandate_id": null,
            "error_code": "109",
            "payment_token": null,
            "connector_metadata": null,
            "payment_experience": null,
            "payment_method_type": "debit",
            "reference_id": null,
            "unified_code": null,
            "unified_message": null,
            "client_source": null,
            "client_version": null
        }
    ],
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "0335",
            "card_type": "DEBIT",
            "card_network": "Visa",
            "card_issuer": "VISA U.S.A. INC.",
            "card_issuing_country": "UNITEDSTATES",
            "card_isin": "400003",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "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": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "http://127.0.0.1:4040/",
    "authentication_type": "no_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": "debit",
    "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": "DF4NDC3W8WH68775",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_JMfKcXwsfYNl06UWsCc0_2",
    "payment_link": null,
    "profile_id": "pro_gEwS6ve9KVqywWL0hmAq",
    "surcharge_details": null,
    "attempt_count": 2,
    "merchant_decision": null,
    "merchant_connector_id": "mca_zMyPaKk9qUVauLL7wFrV",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-06-03T11:22:12.120Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "125.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": "pm_d6OTFivsWBpZpC9u53Hh",
    "payment_method_status": "active",
    "updated": "2025-06-03T11:07:15.083Z",
    "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
}

-> The payment was first tried with star card network and then with the visa
image
image

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

@ShankarSinghC ShankarSinghC self-assigned this Jun 3, 2025
@ShankarSinghC ShankarSinghC requested review from a team as code owners June 3, 2025 09:48
@ShankarSinghC ShankarSinghC added A-core Area: Core flows C-feature Category: Feature request or enhancement A-payments Area: payments A-routing Area: Routing labels Jun 3, 2025
Copy link

semanticdiff-com bot commented Jun 3, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/routing/helpers.rs  34% smaller
  crates/router/src/core/payments/retry.rs  11% smaller
  crates/router/src/core/payments.rs  0% smaller

@ShankarSinghC ShankarSinghC linked an issue Jun 3, 2025 that may be closed by this pull request
Copy link
Member

@prajjwalkumar17 prajjwalkumar17 left a comment

Choose a reason for hiding this comment

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

Routing changes seems fine!

@likhinbopanna likhinbopanna added this pull request to the merge queue Jun 16, 2025
Merged via the queue into main with commit b5b7cfa Jun 16, 2025
22 of 28 checks passed
@likhinbopanna likhinbopanna deleted the debit-routing/retries branch June 16, 2025 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-payments Area: payments A-routing Area: Routing C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add retry support for debit routing
4 participants