Skip to content

Conversation

@hrithikesh026
Copy link
Contributor

@hrithikesh026 hrithikesh026 commented Nov 2, 2025

feat: Enhance UCS integration with improved authentication flow and proxy selection logic

Type of Change

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

Description

This PR introduces significant enhancements to the Unified Connector Service (UCS) integration, focusing on authentication flow improvements and comprehensive data handling updates.

Key Changes:

  1. Enhanced Authentication Flow:

    • Added support for payment_method_type in PaymentsAuthenticateData and PaymentsPostAuthenticateData
    • Implemented authentication data propagation in complete authorize flow
    • Added new fields to AuthenticationData including trans_status and transaction_id
    • Improved authentication data conversion between domain and gRPC models
  2. UCS Integration Improvements:

    • Updated connector-service dependency to revision 13c6e387c81c4573d382677d19ad91e3605ba9af
    • Added complete authorize flow support in UCS
    • Enhanced preprocessing flow handling with authentication result storage
    • Improved error handling and response transformation
  3. Data Model Enhancements:

    • Added authentication_data and payment_method_type to CompleteAuthorizeData
    • Removed deprecated CompleteAuthorizeRedirectResponse struct
    • Enhanced payment method handling in UCS transformers
    • Improved merchant account metadata processing
  4. Logging and Monitoring:

    • Enhanced ucs_logging_wrapper to support flow output data
    • Improved error tracking and metrics for UCS calls
    • Better debugging information for proxy selection

Additional Changes

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

Motivation and Context

This change addresses several critical improvements in the UCS integration:

  1. Authentication Flow Enhancement: The previous implementation lacked proper authentication data propagation in complete authorize flows, leading to incomplete payment processing for 3DS transactions.

  2. Performance Optimization: The proxy selection logic was making redundant database calls and had complex decision-making logic that could be simplified for better maintainability and performance.

  3. Data Consistency: Missing fields in authentication data structures were causing issues with proper 3DS flow handling and response processing.

  4. Dependency Updates: Updated to the latest connector-service revision to leverage new features and bug fixes.

How did you test it?

  1. Create merchant account, MCA, and cybersource connector.
  2. Enable UCS for cybersource. using below curls.
curl --location 'http://localhost:8080/configs/' \
--header 'Content-Type: application/json' \
--header 'x-tenant-id: public' \
--header 'authorization: admin-api-key=test_admin' \
--header 'api-key: test_admin' \
--data '
{
    "key": "ucs_rollout_config_{merchant_id}_cybersource_card_Authorize",
    "value": "{\"rollout_percent\": 1.0}"
}
'
curl --location 'http://localhost:8080/configs/' \
--header 'Content-Type: application/json' \
--header 'x-tenant-id: public' \
--header 'authorization: admin-api-key=test_admin' \
--header 'api-key: test_admin' \
--data '
{
    "key": "ucs_rollout_config_{merchant_id}_cybersource_card_CompleteAuthorize",
    "value": "{\"rollout_percent\": 1.0}"
}
'
  1. Make a 3ds payment.
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_3PqW18IEFGhqTmD1sfyvX4Z1ExVJmUIUVUDh0TCwRyj2pLUfdZO5u2mydrpxf10Y' \
--header 'x-reference-id: merchant_1758644770_payment_1' \
--data-raw '{
    "amount": 1000,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "StripeCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "three_ds",
    "return_url": "https://google.com",
    "merchant_order_reference_id": "Payment_reference_1000",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "5200000000002151",
            "card_exp_month": "01",
            "card_exp_year": "2028",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
            
        }
    },
    "billing": {
        "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"
}'

Response:

{
    "payment_id": "pay_uCWksYmUt19asmAgaSG2",
    "merchant_id": "merchant_1762157899",
    "status": "requires_customer_action",
    "amount": 1000,
    "net_amount": 1000,
    "shipping_cost": null,
    "amount_capturable": 1000,
    "amount_received": null,
    "connector": "cybersource",
    "client_secret": "pay_uCWksYmUt19asmAgaSG2_secret_1g4dDqdVVpXQihahuXR0",
    "created": "2025-11-03T10:12:20.663Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "customer": {
        "id": "StripeCustomer",
        "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": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "2151",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "520000",
            "card_extended_bin": null,
            "card_exp_month": "01",
            "card_exp_year": "2028",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_trsiX1X1HNAK7poz9jtO",
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe",
            "origin_zip": null
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_uCWksYmUt19asmAgaSG2/merchant_1762157899/pay_uCWksYmUt19asmAgaSG2_1"
    },
    "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": {
        "customer_id": "StripeCustomer",
        "created_at": 1762164739,
        "expires": 1762168339,
        "secret": "epk_13ebbd353e144057b6a2ccfbf35a5636"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": null,
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": null,
        "apple_pay_recurring_details": null,
        "gateway_system": "unified_connector_service"
    },
    "reference_id": "pay_uCWksYmUt19asmAgaSG2_1",
    "payment_link": null,
    "profile_id": "pro_aI3SYpyPOvNnwVxWAhMg",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_Q25hV2RKehYlDxOj2Bzw",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-11-03T10:27:20.663Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_channel": null,
    "payment_method_id": null,
    "network_transaction_id": null,
    "payment_method_status": null,
    "updated": "2025-11-03T10:12:24.333Z",
    "split_payments": null,
    "frm_metadata": null,
    "extended_authorization_applied": null,
    "request_extended_authorization": null,
    "capture_before": null,
    "merchant_order_reference_id": "Payment_reference_1000",
    "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": "{\"clientReferenceInformation\":{\"code\":\"pay_uCWksYmUt19asmAgaSG2_1\"},\"consumerAuthenticationInformation\":{\"accessToken\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIwZDVlZTIwYy0yZGFiLTQ3MGUtOTNkYS1lMmUyZTRmZDhmODUiLCJpYXQiOjE3NjIxNjQ3NDQsImlzcyI6IjVkZDgzYmYwMGU0MjNkMTQ5OGRjYmFjYSIsImV4cCI6MTc2MjE2ODM0NCwiT3JnVW5pdElkIjoiNjQxMDNkYTQxY2ZiOTM1ODcxMWQ3OTBmIiwiUmVmZXJlbmNlSWQiOiJkODlhZTY0Yi03NzM2LTRiYWEtYjRjYy00OTY2MTM0YjBkNTQifQ.QqhbG4QqkyY-wI4EDplHXSK2tB3C5w6L1mFOLnr5d7I\",\"deviceDataCollectionUrl\":\"https://centinelapistag.cardinalcommerce.com/V1/Cruise/Collect\",\"referenceId\":\"d89ae64b-7736-4baa-b4cc-4966134b0d54\",\"token\":\"AxizbwSTnSubHWK0F2xmAEMCT36P7wV4ApdwyaSZejFrdyoAgAAA3wgr\"},\"id\":\"7621647439916831304806\",\"status\":\"COMPLETED\",\"submitTimeUtc\":\"2025-11-03T10:12:24Z\"}",
    "enable_partial_authorization": null,
    "enable_overcapture": null,
    "is_overcapture_enabled": null,
    "network_details": null,
    "is_stored_credential": null,
    "mit_category": null
}
  1. Copy paste next_action.redirect_to_url on a browser and complete redirection step.
  2. Do a PSync. Payment should be succeeded.
  3. To verify the payment actually went through UCS, search for this log line in Hyperswitch logs. Payment gateway decision: gateway=UnifiedConnectorService

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

@hrithikesh026 hrithikesh026 self-assigned this Nov 2, 2025
@hrithikesh026 hrithikesh026 requested review from a team as code owners November 2, 2025 13:25
@semanticdiff-com
Copy link

semanticdiff-com bot commented Nov 2, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/flows/authorize_flow.rs  97% smaller
  crates/router/src/core/payments/flows/setup_mandate_flow.rs  84% smaller
  crates/router/src/core/payments/flows/capture_flow.rs  84% smaller
  crates/router/src/core/payments/flows/cancel_flow.rs  83% smaller
  crates/router/src/core/payments/flows/psync_flow.rs  83% smaller
  crates/router/src/core/unified_connector_service.rs  74% smaller
  crates/router/src/core/payments/flows/external_proxy_flow.rs  62% smaller
  crates/router/src/core/payments/flows/complete_authorize_flow.rs  39% smaller
  crates/router/src/core/payments/types.rs  18% smaller
  crates/router/src/core/unified_connector_service/transformers.rs  4% smaller
  Cargo.lock Unsupported file format
  crates/external_services/Cargo.toml Unsupported file format
  crates/external_services/src/grpc_client/unified_connector_service.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_request_types.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_response_types.rs  0% smaller
  crates/hyperswitch_interfaces/Cargo.toml Unsupported file format
  crates/hyperswitch_interfaces/src/connector_integration_interface.rs Unsupported file format
  crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs  0% smaller
  crates/router/Cargo.toml Unsupported file format
  crates/router/src/core/payments/transformers.rs  0% smaller

@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

❌ Patch coverage is 0% with 581 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@a81af9d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...src/core/unified_connector_service/transformers.rs 0.00% 318 Missing ⚠️
...src/core/payments/flows/complete_authorize_flow.rs 0.00% 184 Missing ⚠️
crates/router/src/core/payments/types.rs 0.00% 28 Missing ⚠️
..._interfaces/src/connector_integration_interface.rs 0.00% 16 Missing ⚠️
...s/router/src/core/payments/flows/authorize_flow.rs 0.00% 14 Missing ⚠️
...ter/src/core/payments/flows/external_proxy_flow.rs 0.00% 4 Missing ⚠️
...rates/router/src/core/unified_connector_service.rs 0.00% 4 Missing ⚠️
...erswitch_domain_models/src/router_request_types.rs 0.00% 3 Missing ⚠️
...ates/router/src/core/payments/flows/cancel_flow.rs 0.00% 2 Missing ⚠️
...tes/router/src/core/payments/flows/capture_flow.rs 0.00% 2 Missing ⚠️
... and 4 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10091   +/-   ##
=======================================
  Coverage        ?    3.90%           
=======================================
  Files           ?     1224           
  Lines           ?   302667           
  Branches        ?        0           
=======================================
  Hits            ?    11804           
  Misses          ?   290863           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

jarnura
jarnura previously approved these changes Nov 4, 2025
@bernard-eugine bernard-eugine added this pull request to the merge queue Nov 5, 2025
Merged via the queue into main with commit 1d3def3 Nov 5, 2025
27 of 30 checks passed
@bernard-eugine bernard-eugine deleted the call-ucs-for-authorize-in-complete-authorize branch November 5, 2025 09:26
aadityaguptaa pushed a commit that referenced this pull request Nov 10, 2025
…orize (#10091)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
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.

5 participants