Skip to content

feat(router): Add v2 endpoint to list payment attempts by intent_id#8368

Merged
likhinbopanna merged 7 commits intomainfrom
payment_attempt_list
Jun 20, 2025
Merged

feat(router): Add v2 endpoint to list payment attempts by intent_id#8368
likhinbopanna merged 7 commits intomainfrom
payment_attempt_list

Conversation

@aniketburman014
Copy link
Contributor

@aniketburman014 aniketburman014 commented Jun 17, 2025

Type of Change

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

Description

This PR introduces an API to list all payment attempts associated with a given intent_id.

Why this is needed:

In payment flows that involve retries—such as smart , cascading retires —a single payment intent may result in multiple attempts. Previously, there was no clean way to retrieve all these attempts together.

Implemented API Flow:

  • Adds a new endpoint: GET /v2/payments/{intent_id}/list_attempts
  • Validates the request and ensures merchant authorization
  • Retrieves all associated payment attempts linked to that intent_id

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?

I inserted two payment attempts for a payment intent as part of testing.

Curl

curl --location 'http://localhost:8080/v2/payments/12345_pay_01978809316e7850b05ab92288ed7746/list_attempts' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_pF6sS2TBfhg0Vdp6N04E' \
--header 'api-key: dev_bzJEoDI7SlTyV0M7Vq6VdtCtbKGwOPphw39wD1mYdu8rY3GoydtnymDbkkMxDopB' \
--header 'Authorization: api-key=dev_bzJEoDI7SlTyV0M7Vq6VdtCtbKGwOPphw39wD1mYdu8rY3GoydtnymDbkkMxDopB'

Response

{
    "payment_attempts": [
        {
            "id": "12345_att_01975ae7bf32760282f479794fbf810c",
            "status": "failure",
            "amount": {
                "net_amount": 10000,
                "amount_to_capture": null,
                "surcharge_amount": null,
                "tax_on_surcharge": null,
                "amount_capturable": 10000,
                "shipping_cost": null,
                "order_tax_amount": null
            },
            "connector": "stripe",
            "error": null,
            "authentication_type": "no_three_ds",
            "created_at": "2025-06-17T13:50:49.173Z",
            "modified_at": "2025-06-17T13:50:49.173Z",
            "cancellation_reason": null,
            "payment_token": null,
            "connector_metadata": null,
            "payment_experience": null,
            "payment_method_type": "card",
            "connector_reference_id": null,
            "payment_method_subtype": "credit",
            "connector_payment_id": {
                "TxnId": "ch_3RYW3N06IkU6uKNZ01mrX2tD"
            },
            "payment_method_id": null,
            "client_source": null,
            "client_version": null,
            "feature_metadata": {
                "revenue_recovery": {
                    "attempt_triggered_by": "external"
                }
            }
        },
        {
            "id": "12345_att_01975ae7bf32760282f479794fbf810d",
            "status": "failure",
            "amount": {
                "net_amount": 10000,
                "amount_to_capture": null,
                "surcharge_amount": null,
                "tax_on_surcharge": null,
                "amount_capturable": 10000,
                "shipping_cost": null,
                "order_tax_amount": null
            },
            "connector": "stripe",
            "error": null,
            "authentication_type": "no_three_ds",
            "created_at": "2025-06-17T13:51:16.812Z",
            "modified_at": "2025-06-17T13:51:16.812Z",
            "cancellation_reason": null,
            "payment_token": null,
            "connector_metadata": null,
            "payment_experience": null,
            "payment_method_type": "card",
            "connector_reference_id": null,
            "payment_method_subtype": "credit",
            "connector_payment_id": {
                "TxnId": "ch_3RYW3N06IkU6uKNZ01mrX2tD"
            },
            "payment_method_id": null,
            "client_source": null,
            "client_version": null,
            "feature_metadata": {
                "revenue_recovery": {
                    "attempt_triggered_by": "external"
                }
            }
        }
    ]
}

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

@aniketburman014 aniketburman014 requested review from a team as code owners June 17, 2025 15:08
@semanticdiff-com
Copy link

semanticdiff-com bot commented Jun 17, 2025

@aniketburman014 aniketburman014 self-assigned this Jun 18, 2025
@aniketburman014 aniketburman014 changed the title attempt list api feat(router): Add v2 endpoint to list payment attempts by intent_id Jun 18, 2025
@srujanchikke
Copy link
Contributor

We need add get attempt list fetch in revenue recovery incoming webhooks flow instead of fetching attempt list via payment get.

srujanchikke
srujanchikke previously approved these changes Jun 19, 2025
maverox
maverox previously approved these changes Jun 19, 2025
tsdk02
tsdk02 previously approved these changes Jun 19, 2025
web::resource("/confirm-intent")
.route(web::post().to(payments::payment_confirm_intent)),
)
.service(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please generate open-api spec for this endpoint and validate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generated

Copy link
Member

Choose a reason for hiding this comment

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

Nit: If you want the endpoint included in the API reference, then you'd have to update the Mintlify docs / config file as well.

@aniketburman014 aniketburman014 dismissed stale reviews from tsdk02, maverox, and srujanchikke via 54bffa9 June 19, 2025 16:53
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jun 19, 2025
Copy link
Member

@SanchithHegde SanchithHegde left a comment

Choose a reason for hiding this comment

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

Other than that, looks good to me!

}
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct PaymentAttemptListRequest {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Would appreciate documentation comments being added.

#[cfg(feature = "v2")]
pub mod payment_update_intent;
#[cfg(feature = "v2")]
pub mod proxy_payments_intent;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: We should consider renaming the module to be proxy_payment_intent instead (not payments intent).

web::resource("/confirm-intent")
.route(web::post().to(payments::payment_confirm_intent)),
)
.service(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: If you want the endpoint included in the API reference, then you'd have to update the Mintlify docs / config file as well.

/// Payments create and confirm intent flow
PaymentsCreateAndConfirmIntent,
/// Payment attempt list flow
PaymentAttemptsList,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: We might want to consider naming this as PaymentsAttemptsList, to maintain consistency with the other payments related enum variants.

@likhinbopanna likhinbopanna added this pull request to the merge queue Jun 20, 2025
Merged via the queue into main with commit 7943fb4 Jun 20, 2025
15 of 20 checks passed
@likhinbopanna likhinbopanna deleted the payment_attempt_list branch June 20, 2025 06:58
Aishwariyaa-Anand pushed a commit that referenced this pull request Jun 22, 2025
…8368)

Co-authored-by: Aniket Burman <aniket.burman@Aniket-Burman-JDXHW2PH34.local>
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

api-v2 M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(router): Add v2 endpoint to list payment attempts by intent_id

7 participants