Skip to content

feat(core): Add network_transaction_id in payments Response #9032

Merged
likhinbopanna merged 3 commits intomainfrom
ntid-return
Aug 24, 2025
Merged

feat(core): Add network_transaction_id in payments Response #9032
likhinbopanna merged 3 commits intomainfrom
ntid-return

Conversation

@awasthi21
Copy link
Contributor

@awasthi21 awasthi21 commented Aug 22, 2025

Type of Change

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

Description

Database Changes:

Added network_transaction_id column (VARCHAR(255), nullable) to the payment_attempt table via migration 2025-08-20-095434_add_ntid_in_attempt_table.

Added get_network_transaction_id method to PaymentsResponseData in crates/hyperswitch_domain_models/src/router_response_types.rs to extract network_transaction_id from transaction responses.

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?

For CIT Transaction:
Request:

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_DD2unr7vk4xDt33fxLlCT7JRyc5lX0ffC5fSLUo8Qrwcz4MLzt55T8jnBzveIgLs' \
--data-raw '{
    "amount": 1000,
    "currency": "USD",
    "amount_to_capture": 1000,
    "customer_id":"131123",
    "confirm": true,
    "capture_method": "automatic",
    "setup_future_usage": "off_session",
    "authentication_type": "no_three_ds",
    "payment_method": "card",
    "payment_method_type": "credit",
    
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "email": "guest@example.com",
    "payment_method_data": {
        "card": {
            "card_number": "5404000000000001",
            "card_exp_month": "09",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "Zurich",
            "state": "asd",
            "zip": "8008",
            "country": "CH",
            "first_name": "joseph",
            "last_name": "Doe",
            "origin_zip":"43234"
        }
    }
}'

Response

{
    "payment_id": "pay_SdL4iUqO5d7j0FzJYU65",
    "merchant_id": "merchant_1755880712",
    "status": "processing",
    "amount": 1000,
    "net_amount": 1000,
    "shipping_cost": null,
    "amount_capturable": 1000,
    "amount_received": null,
    "connector": "worldpayvantiv",
    "client_secret": "pay_SdL4iUqO5d7j0FzJYU65_secret_yKgYTJrT0zHhYi5JruGO",
    "created": "2025-08-22T16:44:09.334Z",
    "currency": "USD",
    "customer_id": "131123",
    "customer": {
        "id": "131123",
        "name": null,
        "email": "guest@example.com",
        "phone": null,
        "phone_country_code": null
    },
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "0001",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "540400",
            "card_extended_bin": null,
            "card_exp_month": "09",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "payment_checks": {
                "avs_result": "00",
                "advanced_a_v_s_result": null,
                "authentication_result": null,
                "card_validation_result": "M"
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "Zurich",
            "country": "CH",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "8008",
            "state": "asd",
            "first_name": "joseph",
            "last_name": "Doe",
            "origin_zip": "43234"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": null,
    "phone": null,
    "return_url": null,
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "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": {
        "customer_id": "131123",
        "created_at": 1755881049,
        "expires": 1755884649,
        "secret": "epk_9348e3aa032c4d098bbfd192de70ef12"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "83997485375813577",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": null,
        "apple_pay_recurring_details": null,
        "gateway_system": "direct"
    },
    "reference_id": "pay_SdL4iUqO5d7j0FzJYU65_1",
    "payment_link": null,
    "profile_id": "pro_hu1z8tTKASkmCSAzpgrG",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_lWpk5Il3XuhAhU9yZCYv",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-08-22T16:59:09.334Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_channel": null,
    "payment_method_id": "pm_g1hGld5oStSlL23yZMU7",
    "network_transaction_id": "1096408000822",
    "payment_method_status": "inactive",
    "updated": "2025-08-22T16:44:10.187Z",
    "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": "2592937072890001",
    "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,
    "enable_partial_authorization": null
}

Payments Method table:
Screenshot 2025-08-22 at 10 19 32 PM

Payments Attempt Table:
Screenshot 2025-08-22 at 10 20 02 PM

Normal Card's Flow
Request

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_DD2unr7vk4xDt33fxLlCT7JRyc5lX0ffC5fSLUo8Qrwcz4MLzt55T8jnBzveIgLs' \
--data-raw '{
    "amount": 1000,
    "currency": "USD",
    "amount_to_capture": 1000,
    "customer_id":"131123",
    "confirm": true,
    "capture_method": "automatic",
    
    "authentication_type": "no_three_ds",
    "payment_method": "card",
    "payment_method_type": "credit",
   
    "email": "guest@example.com",
    "payment_method_data": {
        "card": {
            "card_number": "5404000000000001",
            "card_exp_month": "09",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "Zurich",
            "state": "asd",
            "zip": "8008",
            "country": "CH",
            "first_name": "joseph",
            "last_name": "Doe",
            "origin_zip":"43234"
        }
    }
}'

Response

{
    "payment_id": "pay_6nYH976LGZjIxtPDiPBH",
    "merchant_id": "merchant_1755880712",
    "status": "processing",
    "amount": 1000,
    "net_amount": 1000,
    "shipping_cost": null,
    "amount_capturable": 1000,
    "amount_received": null,
    "connector": "worldpayvantiv",
    "client_secret": "pay_6nYH976LGZjIxtPDiPBH_secret_xEhb0OgmGKkfmggg9aXW",
    "created": "2025-08-22T16:55:44.705Z",
    "currency": "USD",
    "customer_id": "131123",
    "customer": {
        "id": "131123",
        "name": null,
        "email": "guest@example.com",
        "phone": null,
        "phone_country_code": null
    },
    "description": null,
    "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": "0001",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "540400",
            "card_extended_bin": null,
            "card_exp_month": "09",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "payment_checks": {
                "avs_result": "00",
                "advanced_a_v_s_result": null,
                "authentication_result": null,
                "card_validation_result": "M"
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "Zurich",
            "country": "CH",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "8008",
            "state": "asd",
            "first_name": "joseph",
            "last_name": "Doe",
            "origin_zip": "43234"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": null,
    "phone": null,
    "return_url": null,
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "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": {
        "customer_id": "131123",
        "created_at": 1755881744,
        "expires": 1755885344,
        "secret": "epk_e922a4645c01494495dc217f2edab3ef"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "83997485380421630",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": null,
        "apple_pay_recurring_details": null,
        "gateway_system": "direct"
    },
    "reference_id": "pay_6nYH976LGZjIxtPDiPBH_1",
    "payment_link": null,
    "profile_id": "pro_hu1z8tTKASkmCSAzpgrG",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_lWpk5Il3XuhAhU9yZCYv",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-08-22T17:10:44.705Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_channel": null,
    "payment_method_id": null,
    "network_transaction_id": "3614028940822",
    "payment_method_status": null,
    "updated": "2025-08-22T16:55:45.233Z",
    "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,
    "enable_partial_authorization": null
}

Payments Attempt
Screenshot 2025-08-22 at 10 27 16 PM

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

@awasthi21 awasthi21 self-assigned this Aug 22, 2025
@awasthi21 awasthi21 requested review from a team as code owners August 22, 2025 09:46
@semanticdiff-com
Copy link

semanticdiff-com bot commented Aug 22, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/transformers.rs  54% smaller
  crates/diesel_models/src/payment_attempt.rs  0% smaller
  crates/diesel_models/src/schema.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/diesel_models/src/user/sample_data.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_attempt.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_response_types.rs  0% smaller
  crates/router/src/core/payments/helpers.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm.rs  0% smaller
  crates/router/src/core/payments/operations/payment_create.rs  0% smaller
  crates/router/src/core/payments/operations/payment_response.rs  0% smaller
  crates/router/src/core/payments/operations/payment_update.rs  0% smaller
  crates/router/src/core/payments/retry.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/router/src/types/storage/payment_attempt.rs  0% smaller
  crates/router/src/utils/user/sample_data.rs  0% smaller
  crates/storage_impl/src/mock_db/payment_attempt.rs  0% smaller
  crates/storage_impl/src/payments/payment_attempt.rs  0% smaller
  migrations/2025-08-20-095434_add_ntid_in_attempt_table/down.sql Unsupported file format
  migrations/2025-08-20-095434_add_ntid_in_attempt_table/up.sql Unsupported file format

@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Aug 22, 2025
@awasthi21 awasthi21 changed the title Initial commit feat(core) : Add network_transaction_id in payments Response Aug 22, 2025
@awasthi21 awasthi21 force-pushed the ntid-return branch 2 times, most recently from bcdbdc2 to 0ce915c Compare August 22, 2025 16:37
@awasthi21 awasthi21 changed the title feat(core) : Add network_transaction_id in payments Response feat(core) :Add network_transaction_id in payments Response Aug 22, 2025
@awasthi21 awasthi21 changed the title feat(core) :Add network_transaction_id in payments Response feat(core): Add network_transaction_id in payments Response Aug 22, 2025
processor_merchant_id,
created_by,
connector_request_reference_id,
network_transaction_id: _,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we include network_transaction_id in KafkaPaymentAttemptEvent ?

Copy link
Contributor

@ThisIsMani ThisIsMani left a comment

Choose a reason for hiding this comment

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

Dashboard specific changes look fine.

@likhinbopanna likhinbopanna added this pull request to the merge queue Aug 24, 2025
Merged via the queue into main with commit 7047c3f Aug 24, 2025
21 of 25 checks passed
@likhinbopanna likhinbopanna deleted the ntid-return branch August 24, 2025 17:00
Pradesh-S pushed a commit that referenced this pull request Aug 26, 2025
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

M-database-changes Metadata: This PR involves database schema changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants