Skip to content

Conversation

srujanchikke
Copy link
Contributor

Type of Change

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

Description

Previously there was no restriction in confirmData to connector request reference id to be mandatory. Recovery internally uses proxy flow, which internally uses confirmData where connector request reference id was hardcoded to none. This Pr adds supports to generate connector request reference to merchant reference id.

This Pr also has changes of adding support for jwt auth to payment get for dashboard use case. Previously payment sync was used in dashboard to retrieve payment details, but this would fail now in v2 because if there are no attempts created payment get would return 4xx since active attempt is mandotory. To solve this now dashboard is relying on payment get and payment get attempt list api's .

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?

Test case 1 :
step 1 : create a profile in hyperswitch and wait for 8 mins to move it from monitering to cascading , this would only get updated when webhooks are triggered .
step 2 : create payment mca

curl --location 'http://localhost:8080/v2/connector-accounts' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-merchant-id: test_seller_AGZCJiHwUNV1seyoepOE' \
--header 'x-profile-id: pro_kYmv4lQjIZFbAqoOVY4M' \
--header 'Authorization: admin-api-key=test_admin' \
--data '{
  "connector_type": "payment_processor",
  "connector_name": "stripe",
  "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "stripe-api-key"
    },
  "profile_id": "pro_kYmv4lQjIZFbAqoOVY4M"
}'

**step 4 : ** configure stripe billing connector.

curl --location 'http://localhost:8080/v2/connector-accounts' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-merchant-id: test_seller_AGZCJiHwUNV1seyoepOE' \
--header 'x-profile-id: pro_kYmv4lQjIZFbAqoOVY4M' \
--header 'Authorization: admin-api-key=test_admin' \
--data '{
    "connector_type": "billing_processor",
    "connector_name": "stripebilling",
    "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "{{stripe-api-key}}"
    },
    "connector_webhook_details": {
        "merchant_secret": "{{stripe-webhook-key}}",
        "additional_secret": "password"
    },
    "feature_metadata": {
        "revenue_recovery": {
            "max_retry_count": 7,
            "billing_connector_retry_threshold": 2,
            "billing_account_reference": {
                "{{payment_connector_mca_created_in_last_step}}": "stripebilling"
            }
        }
    },
    "profile_id": "pro_kYmv4lQjIZFbAqoOVY4M"
}'

step 5 : Trigger failed invoice from stripe billing by creating new subscription and move the test clock to 1 week.
This would trigger few external payments. once it exhausts retry threshold it will create process tracker entry. Follwed by 2 mins it would create all retries by hyperswitch as shown below.

Screenshot 2025-06-23 at 7 00 57 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

@srujanchikke srujanchikke self-assigned this Jun 23, 2025
@srujanchikke srujanchikke requested a review from a team as a code owner June 23, 2025 13:31
@srujanchikke srujanchikke requested review from a team as code owners June 23, 2025 13:31
Copy link

semanticdiff-com bot commented Jun 23, 2025

@srujanchikke srujanchikke changed the title Fix recovery fix(recovery) : Populate connector request reference id in revenue recovery record attempt flow. Jun 24, 2025
@srujanchikke srujanchikke changed the title fix(recovery) : Populate connector request reference id in revenue recovery record attempt flow. fix(recovery): Populate connector request reference id in revenue recovery record attempt flow. Jun 24, 2025
where
{
if let Ok(val) = HeaderMapStruct::new(headers).get_auth_string_from_header() {
if val.trim().starts_with("api-key=") {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "api-key=" can be a const.

Comment on lines +2701 to +2721
#[cfg(feature = "v2")]
pub fn api_or_client_or_jwt_auth<'a, T, A>(
api_auth: &'a dyn AuthenticateAndFetch<T, A>,
client_auth: &'a dyn AuthenticateAndFetch<T, A>,
jwt_auth: &'a dyn AuthenticateAndFetch<T, A>,
headers: &HeaderMap,
) -> &'a dyn AuthenticateAndFetch<T, A>
where
{
if let Ok(val) = HeaderMapStruct::new(headers).get_auth_string_from_header() {
if val.trim().starts_with("api-key=") {
api_auth
} else if is_jwt_auth(headers) {
jwt_auth
} else {
client_auth
}
} else {
api_auth
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you giving the highest priority to api-key?
What if both JWT and api-key headers are present in the request body? Which authentication type should be considered in that case?

Or is it the same header used for all authentications in v2?

Copy link
Contributor

Choose a reason for hiding this comment

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

This can never happen right.
Value for Authorization header cannot start with Both Bearer_ and api-key=

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, so unlike v1, where there are different headers for different authentication types, in v2 there is just one Authorization header with different values for different types of authentication, correct?

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jun 26, 2025
Merged via the queue into main with commit f1c5336 Jun 26, 2025
17 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the fix_recovery branch June 26, 2025 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix(recovery) : Populate connector request reference id in revenue recovery record attempt flow.
6 participants