Skip to content

feat(core): populate connector raw response and connector_response_reference_id for razorpay#8499

Merged
Gnanasundari24 merged 9 commits intomainfrom
psync-razorpay
Jul 3, 2025
Merged

feat(core): populate connector raw response and connector_response_reference_id for razorpay#8499
Gnanasundari24 merged 9 commits intomainfrom
psync-razorpay

Conversation

@Aishwariyaa-Anand
Copy link
Contributor

@Aishwariyaa-Anand Aishwariyaa-Anand commented Jun 30, 2025

Type of Change

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

Description

This PR populates raw_connector_response for Payments when return_raw_connector_response is set to True. It also changes Payments Create and Psync endpoint for Razorpay connector.

Additional Changes:

  • Introduces a struct ConnectorResponseData which sends raw_connector_response at core flows instead of it being in PaymentData (changed only in v2)
  • Rename all_keys_required as return_raw_connector_response, get_all_keys_required() as should_return_raw_response() , whole_connector_response as raw_connector_response. This rename is applied only on v2 Api and core flows to retain backward compatibility at v1.
  • get_whole_connector_response() and get_all_keys_required() at OperationSessionGetters are marked under v1 feature
  • connector_response_reference_id is updated in Payment_attempt at both update_trackers and post_update_trackers for v2. This is included in update_trackers in cases where Authorize flow is not performed at Connector End
  • Also marked this PaymentRetrieveBody, PaymentRetrieveBodyWithCredentials under v1 feature as it is not required in v2 flows

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?

  • Payments - Create
curl --location 'http://localhost:8080/v2/payments' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_L5WeuuGWl0EUYBhEEME1' \
--header 'Authorization: api-key=_' \
--data-raw '{
    "amount_details": {
        "order_amount": 100,
        "currency": "INR"
    },
    "capture_method":"automatic",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "payment_method_data": {
        "upi": {
            "upi_collect": {
                "vpa_id": "success@razorpay"
            }
        },
        "billing": {
            "address": {
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "city": "San Fransico",
                "state": "California",
                "zip": "94122",
                "country": "IN",
                "first_name": "Swangi",
                "last_name": "Kumari"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            },
            "email": "swangi.kumari@juspay.in"
        }
    },
    "payment_method_subtype": "upi_collect",
    "payment_method_type": "upi",
    "return_raw_connector_response": true
}'

Response

{
    "id": "12345_pay_0197c4e2b8087181963fdaae32be36b3",
    "status": "requires_customer_action",
    "amount": {
        "order_amount": 100,
        "currency": "INR",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 100,
        "amount_to_capture": null,
        "amount_capturable": 0,
        "amount_captured": null
    },
    "customer_id": null,
    "connector": "razorpay",
    "created": "2025-07-01T07:28:02.057Z",
    "payment_method_data": {
        "billing": {
            "address": {
                "city": "San Fransico",
                "country": "IN",
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "zip": "94122",
                "state": "California",
                "first_name": "Swangi",
                "last_name": "Kumari"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            },
            "email": "swangi.kumari@juspay.in"
        }
    },
    "payment_method_type": "upi",
    "payment_method_subtype": "upi_collect",
    "connector_transaction_id": "pay_Qnik5RSCB4oVjf",
    "connector_reference_id": "order_Qnik4SrNFCdv8H",
    "merchant_connector_id": "mca_GWx9LT38SlIQ1qNFfw1p",
    "browser_info": null,
    "error": null,
    "shipping": null,
    "billing": null,
    "attempts": null,
    "connector_token_details": null,
    "payment_method_id": null,
    "next_action": {
        "type": "wait_screen_information",
        "display_from_timestamp": 1751354885589516000,
        "display_to_timestamp": 1751355185589516000,
        "poll_config": {
            "delay_in_secs": 5,
            "frequency": 5
        }
    },
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "authentication_type_applied": "no_three_ds",
    "is_iframe_redirection_enabled": null,
    "merchant_reference_id": null,
    "raw_connector_response": "{\"razorpay_payment_id\":\"pay_Qnik5RSCB4oVjf\"}"
}
  • Payments - Retrieve
curl --location 'http://localhost:8080/v2/payments/12345_pay_0197c4e2b8087181963fdaae32be36b3?force_sync=true&return_raw_connector_response=true' \
--header 'x-profile-id: pro_L5WeuuGWl0EUYBhEEME1' \
--header 'Authorization: api-key=_' \
--data ''

Response

{
    "id": "12345_pay_0197c4e2b8087181963fdaae32be36b3",
    "status": "requires_capture",
    "amount": {
        "order_amount": 100,
        "currency": "INR",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 100,
        "amount_to_capture": null,
        "amount_capturable": 100,
        "amount_captured": 100
    },
    "customer_id": null,
    "connector": "razorpay",
    "created": "2025-07-01T07:36:11.733Z",
    "payment_method_data": {
        "billing": {
            "address": {
                "city": "San Fransico",
                "country": "IN",
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "zip": "94122",
                "state": "California",
                "first_name": "Swangi",
                "last_name": "Kumari"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            },
            "email": "swangi.kumari@juspay.in"
        }
    },
    "payment_method_type": "upi",
    "payment_method_subtype": "upi_collect",
    "connector_transaction_id": "pay_Qnik5RSCB4oVjf",
    "connector_reference_id": "order_Qnik4SrNFCdv8H",
    "merchant_connector_id": "mca_GWx9LT38SlIQ1qNFfw1p",
    "browser_info": null,
    "error": null,
    "shipping": null,
    "billing": null,
    "attempts": null,
    "connector_token_details": null,
    "payment_method_id": null,
    "next_action": null,
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "authentication_type_applied": null,
    "is_iframe_redirection_enabled": null,
    "merchant_reference_id": null,
    "raw_connector_response": "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"pay_QnishOLxdHvKJ6\",\"entity\":\"payment\",\"amount\":100,\"currency\":\"INR\",\"status\":\"authorized\",\"order_id\":\"order_QnisgYZGQHtI92\",\"invoice_id\":null,\"international\":false,\"method\":\"upi\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":false,\"description\":null,\"card_id\":null,\"bank\":null,\"wallet\":null,\"vpa\":\"success@razorpay\",\"email\":\"swangi.kumari@juspay.in\",\"contact\":\"+918056594427\",\"notes\":{\"optimizer_provider_name\":\"razorpay\"},\"fee\":null,\"tax\":null,\"error_code\":null,\"error_description\":null,\"error_source\":null,\"error_step\":null,\"error_reason\":null,\"acquirer_data\":{\"rrn\":\"216013077213\",\"upi_transaction_id\":\"614E93092FDA8E2A9FA28264CF769689\"},\"gateway_provider\":\"Razorpay\",\"created_at\":1751355374,\"upi\":{\"vpa\":\"success@razorpay\"}}]}"
}

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

@Aishwariyaa-Anand Aishwariyaa-Anand self-assigned this Jun 30, 2025
@Aishwariyaa-Anand Aishwariyaa-Anand requested review from a team as code owners June 30, 2025 11:36
@Aishwariyaa-Anand Aishwariyaa-Anand added the A-payments Area: payments label Jun 30, 2025
@Aishwariyaa-Anand Aishwariyaa-Anand requested a review from a team as a code owner June 30, 2025 11:36
@semanticdiff-com
Copy link

semanticdiff-com bot commented Jun 30, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/webhooks/incoming_v2.rs  95% smaller
  crates/router/src/types/api/payments.rs  94% smaller
  crates/hyperswitch_connectors/src/connectors/razorpay/transformers.rs  49% smaller
  crates/router/src/core/payments/flows/authorize_flow.rs  47% smaller
  crates/router/src/core/payments.rs  45% smaller
  crates/router/src/routes/payments.rs  31% smaller
  crates/router/src/services/api.rs  25% smaller
  crates/api_models/src/payments.rs  22% smaller
  crates/openapi/src/openapi_v2.rs  20% smaller
  crates/diesel_models/src/payment_attempt.rs  15% smaller
  crates/hyperswitch_domain_models/src/router_data.rs  7% smaller
  crates/hyperswitch_connectors/src/connectors/razorpay.rs  7% smaller
  api-reference/v2/openapi_spec_v2.json  0% smaller
  crates/common_types/src/domain.rs  0% smaller
  crates/hyperswitch_connectors/src/utils.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_attempt.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_request_types.rs  0% smaller
  crates/hyperswitch_interfaces/src/conversion_impls.rs  0% smaller
  crates/router/src/core/authentication/transformers.rs  0% smaller
  crates/router/src/core/fraud_check/flows/checkout_flow.rs  0% smaller
  crates/router/src/core/fraud_check/flows/fulfillment_flow.rs  0% smaller
  crates/router/src/core/fraud_check/flows/record_return.rs  0% smaller
  crates/router/src/core/fraud_check/flows/sale_flow.rs  0% smaller
  crates/router/src/core/fraud_check/flows/transaction_flow.rs  0% smaller
  crates/router/src/core/mandate/utils.rs  0% smaller
  crates/router/src/core/payment_methods.rs  0% smaller
  crates/router/src/core/payments/flows.rs  0% smaller
  crates/router/src/core/payments/flows/approve_flow.rs  0% smaller
  crates/router/src/core/payments/flows/cancel_flow.rs  0% smaller
  crates/router/src/core/payments/flows/capture_flow.rs  0% smaller
  crates/router/src/core/payments/flows/complete_authorize_flow.rs  0% smaller
  crates/router/src/core/payments/flows/incremental_authorization_flow.rs  0% smaller
  crates/router/src/core/payments/flows/post_session_tokens_flow.rs  0% smaller
  crates/router/src/core/payments/flows/psync_flow.rs  0% smaller
  crates/router/src/core/payments/flows/reject_flow.rs  0% smaller
  crates/router/src/core/payments/flows/session_flow.rs  0% smaller
  crates/router/src/core/payments/flows/session_update_flow.rs  0% smaller
  crates/router/src/core/payments/flows/setup_mandate_flow.rs  0% smaller
  crates/router/src/core/payments/flows/update_metadata_flow.rs  0% smaller
  crates/router/src/core/payments/helpers.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_response.rs  0% smaller
  crates/router/src/core/payments/operations/proxy_payments_intent.rs  0% smaller
  crates/router/src/core/payments/transformers.rs  0% smaller
  crates/router/src/core/relay/utils.rs  0% smaller
  crates/router/src/core/revenue_recovery/api.rs  0% smaller
  crates/router/src/core/unified_authentication_service/utils.rs Unsupported file format
  crates/router/src/core/utils.rs  0% smaller
  crates/router/src/core/webhooks/utils.rs  0% smaller
  crates/router/src/types.rs  0% smaller
  crates/router/src/types/api/verify_connector.rs  0% smaller
  crates/router/tests/connectors/aci.rs  0% smaller
  crates/router/tests/connectors/utils.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jun 30, 2025
pub merchant_reference_id: Option<id_type::PaymentReferenceId>,

/// Contains whole connector response
pub whole_connector_response: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't raw_connector_response be more appropriate name for this?

Copy link
Member

Choose a reason for hiding this comment

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

Can we change this to be a Secret, if this would contain sensitive information?

pub merchant_reference_id: Option<id_type::PaymentReferenceId>,

/// Contains whole connector response
pub whole_connector_response: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this to be a Secret, if this would contain sensitive information?

@Aishwariyaa-Anand Aishwariyaa-Anand requested a review from a team as a code owner July 3, 2025 08:00
Copy link
Contributor

@AnuthaDev AnuthaDev left a comment

Choose a reason for hiding this comment

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

payment_method specific changes look fine

pub merchant_connector_creds: common_utils::pii::SecretSerdeValue,
}

/// Connector Response Data that are required to be populated in response
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Connector Response Data that are required to be populated in response
/// Connector Response Data that are required to be populated in response, but not persisted in DB.

token_details.get_connector_token_request_reference_id()
}),
),

Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we populating this in setup mandate flow?

business_profile: &domain::Profile,
header_payload: hyperswitch_domain_models::payments::HeaderPayload,
all_keys_required: Option<bool>,
return_raw_connector_response: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get this value from RouterData. ie Self.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can be taken up in a separate PR.

.connector_request_reference_id
.clone();

let connector_response_reference_id = payment_data
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a comment over this as to why this is being done.

Copy link
Contributor Author

@Aishwariyaa-Anand Aishwariyaa-Anand Jul 3, 2025

Choose a reason for hiding this comment

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

All these unresolved comments will be taken up in a separate PR.
#8565

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jul 3, 2025
Merged via the queue into main with commit 2253d98 Jul 3, 2025
17 of 20 checks passed
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 M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] populate connector raw response and connector_response_reference_id in v2

8 participants