Skip to content

Conversation

AmeyWale
Copy link
Contributor

@AmeyWale AmeyWale commented Apr 17, 2025

Type of Change

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

Description

This PR introduces support for Refunds Retrieve flow and Refunds Sync flow (Rsync) in V2 apis.

Additional Changes

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

Motivation and Context

Upon merging this PR, users can be able to fetch a particular refund. Whether to check its status or fetch it from the gateway using force_sync query parameter.

How did you test it?

  • Create Payment Intent API call
curl --location 'http://localhost:8080/v2/payments/create-intent' \
--header 'api-key: dev_Oce2SOCaD6B7eTuE6o7fAoS0dJIOucG97Y1sS0O94JCzHg1Qh1emDSasTiFvVkIp' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_OIQz3QuZDrhyUteOS41r' \
--header 'Authorization: api-key=dev_Oce2SOCaD6B7eTuE6o7fAoS0dJIOucG97Y1sS0O94JCzHg1Qh1emDSasTiFvVkIp' \
--data-raw '{
    "amount_details": {
        "order_amount": 100,
        "currency": "USD"
    },
    "capture_method":"automatic",
    "authentication_type": "no_three_ds",
    "billing": {
        "address": {
            "first_name": "John",
            "last_name": "Dough"
        },
        "email": "[email protected]"
    },
    "shipping": {
        "address": {
            "first_name": "John",
            "last_name": "Dough",
            "city": "Karwar",
            "zip": "581301",
            "state": "Karnataka"
        },
        "email": "[email protected]"
    }
}'
  • Response from the above call
{
   "id":"12345_pay_019642a2b1bb7653ae08d3a9c5559177",
   "status":"requires_payment_method",
   "amount_details":{
      "order_amount":100,
      "currency":"USD",
      "shipping_cost":null,
      "order_tax_amount":null,
      "external_tax_calculation":"skip",
      "surcharge_calculation":"skip",
      "surcharge_amount":null,
      "tax_on_surcharge":null
   },
   "client_secret":"cs_019642a2b25a7301962eaf25dbdb22fd",
   "profile_id":"pro_OIQz3QuZDrhyUteOS41r",
   "merchant_reference_id":null,
   "routing_algorithm_id":null,
   "capture_method":"automatic",
   "authentication_type":"no_three_ds",
   "billing":{
      "address":{
         "city":null,
         "country":null,
         "line1":null,
         "line2":null,
         "line3":null,
         "zip":null,
         "state":null,
         "first_name":"John",
         "last_name":"Dough"
      },
      "phone":null,
      "email":"[email protected]"
   },
   "shipping":{
      "address":{
         "city":"Karwar",
         "country":null,
         "line1":null,
         "line2":null,
         "line3":null,
         "zip":"581301",
         "state":"Karnataka",
         "first_name":"John",
         "last_name":"Dough"
      },
      "phone":null,
      "email":"[email protected]"
   },
   "customer_id":null,
   "customer_present":"present",
   "description":null,
   "return_url":null,
   "setup_future_usage":"on_session",
   "apply_mit_exemption":"Skip",
   "statement_descriptor":null,
   "order_details":null,
   "allowed_payment_method_types":null,
   "metadata":null,
   "connector_metadata":null,
   "feature_metadata":null,
   "payment_link_enabled":"Skip",
   "payment_link_config":null,
   "request_incremental_authorization":"default",
   "expires_on":"2025-04-17T07:39:40.883Z",
   "frm_metadata":null,
   "request_external_three_ds_authentication":"Skip"
}
  • Confirm Intent API Call
curl --location 'http://localhost:8080/v2/payments/12345_pay_019642a2b1bb7653ae08d3a9c5559177/confirm-intent' \
--header 'x-client-secret: cs_019642a2b25a7301962eaf25dbdb22fd' \
--header 'x-profile-id: pro_OIQz3QuZDrhyUteOS41r' \
--header 'Content-Type: application/json' \
--header 'Authorization: publishable-key=pk_dev_ed28381f289249908a9fc946f11bf871,client-secret=cs_01963eaad7087700a02f86c215139747' \
--data '{
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "05",
            "card_exp_year": "25",
            "card_holder_name": "John Doe",
            "card_cvc": "100"
        }
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "1x.x.x.31"
    }
}'
  • Response from the above call
{
   "id":"12345_pay_019642a2b1bb7653ae08d3a9c5559177",
   "status":"succeeded",
   "amount":{
      "order_amount":100,
      "currency":"USD",
      "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":100
   },
   "customer_id":null,
   "connector":"stripe",
   "created":"2025-04-17T07:24:40.884Z",
   "payment_method_data":{
      "billing":null
   },
   "payment_method_type":"card",
   "payment_method_subtype":"credit",
   "connector_transaction_id":"pi_3REmpOD5R7gDAGff0MLPnmeN",
   "connector_reference_id":null,
   "merchant_connector_id":"mca_sank3uwIE62b8Fzr90a6",
   "browser_info":null,
   "error":null,
   "shipping":null,
   "billing":null,
   "attempts":null,
   "connector_token_details":{
      "token":"pm_1REmpOD5R7gDAGffAT3f1rIN",
      "connector_token_request_reference_id":"Ow8Jd6RrV0u6t2qyST"
   },
   "payment_method_id":null,
   "next_action":null,
   "return_url":"https://google.com/success",
   "authentication_type":"no_three_ds",
   "authentication_type_applied":"no_three_ds"
}
  • Refunds Create API call
curl --location 'http://localhost:8080/v2/refunds' \
--header 'X-Profile-Id: pro_OIQz3QuZDrhyUteOS41r' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_Oce2SOCaD6B7eTuE6o7fAoS0dJIOucG97Y1sS0O94JCzHg1Qh1emDSasTiFvVkIp' \
--data '{
    "payment_id":"12345_pay_019642a2b1bb7653ae08d3a9c5559177",
    "merchant_reference_id":"1744874778",
    "reason":"Paid by mistake",
    "metadata":{
        "foo":"bar"
    }
}'
  • Response from the above call
{
    "id": "12345_ref_019642a487767f20bb8fa4a34d70da4a",
    "payment_id": "12345_pay_019642a2b1bb7653ae08d3a9c5559177",
    "merchant_reference_id": "1744874801",
    "amount": 100,
    "currency": "USD",
    "status": "succeeded",
    "reason": "Paid by mistake",
    "metadata": {
        "foo": "bar"
    },
    "error_details": {
        "code": "",
        "message": ""
    },
    "created_at": "2025-04-17T07:26:41.030Z",
    "updated_at": "2025-04-17T07:26:42.057Z",
    "connector": "stripe",
    "profile_id": "pro_OIQz3QuZDrhyUteOS41r",
    "merchant_connector_id": "mca_sank3uwIE62b8Fzr90a6",
    "connector_refund_reference_id": null
}
  • Refunds Retrieve API call
curl --location 'http://localhost:8080/v2/refunds/12345_ref_019642a487767f20bb8fa4a34d70da4a' \
--header 'x-profile-id: pro_OIQz3QuZDrhyUteOS41r' \
--header 'api-key: dev_Oce2SOCaD6B7eTuE6o7fAoS0dJIOucG97Y1sS0O94JCzHg1Qh1emDSasTiFvVkIp'
  • Response from the above call
{
    "id": "12345_ref_019642a487767f20bb8fa4a34d70da4a",
    "payment_id": "12345_pay_019642a2b1bb7653ae08d3a9c5559177",
    "merchant_reference_id": "1744874801",
    "amount": 100,
    "currency": "USD",
    "status": "succeeded",
    "reason": "Paid by mistake",
    "metadata": {
        "foo": "bar"
    },
    "error_details": {
        "code": "",
        "message": ""
    },
    "created_at": "2025-04-17T07:26:41.030Z",
    "updated_at": "2025-04-17T07:26:42.057Z",
    "connector": "stripe",
    "profile_id": "pro_OIQz3QuZDrhyUteOS41r",
    "merchant_connector_id": "mca_sank3uwIE62b8Fzr90a6",
    "connector_refund_reference_id": null
}
  • Refunds Retrieve api call with force_sync=True in query
curl --location 'http://localhost:8080/v2/refunds/12345_ref_019642a487767f20bb8fa4a34d70da4a?force_sync=true' \
--header 'x-profile-id: pro_OIQz3QuZDrhyUteOS41r' \
--header 'api-key: dev_Oce2SOCaD6B7eTuE6o7fAoS0dJIOucG97Y1sS0O94JCzHg1Qh1emDSasTiFvVkIp' \
--data ''
  • Response from the above call
{
    "id": "12345_ref_019642a487767f20bb8fa4a34d70da4a",
    "payment_id": "12345_pay_019642a2b1bb7653ae08d3a9c5559177",
    "merchant_reference_id": "1744874801",
    "amount": 100,
    "currency": "USD",
    "status": "succeeded",
    "reason": "Paid by mistake",
    "metadata": {
        "foo": "bar"
    },
    "error_details": {
        "code": "",
        "message": ""
    },
    "created_at": "2025-04-17T07:26:41.030Z",
    "updated_at": "2025-04-17T08:38:46.639Z",
    "connector": "stripe",
    "profile_id": "pro_OIQz3QuZDrhyUteOS41r",
    "merchant_connector_id": "mca_sank3uwIE62b8Fzr90a6",
    "connector_refund_reference_id": null
}

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

@AmeyWale AmeyWale requested review from a team as code owners April 17, 2025 07:30
Copy link

semanticdiff-com bot commented Apr 17, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/types/api/refunds.rs  93% smaller
  crates/router/src/routes/app.rs  79% smaller
  crates/router/src/core/utils.rs  45% smaller
  api-reference-v2/openapi_spec.json  0% smaller
  crates/api_models/src/events/refund.rs  0% smaller
  crates/api_models/src/refunds.rs  0% smaller
  crates/diesel_models/src/refund.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments.rs  0% smaller
  crates/openapi/src/openapi_v2.rs  0% smaller
  crates/openapi/src/routes/refunds.rs  0% smaller
  crates/router/src/core/refunds_v2.rs Unsupported file format
  crates/router/src/routes/refunds.rs  0% smaller

@AmeyWale AmeyWale self-assigned this Apr 17, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Apr 17, 2025
@AmeyWale AmeyWale linked an issue Apr 17, 2025 that may be closed by this pull request
@AmeyWale AmeyWale changed the title Refunds v2 retrieve flow feat(refunds_v2): Add Refunds Retrieve and Refunds Sync Core flow Apr 17, 2025
Base automatically changed from refunds-create-core-flow to main April 21, 2025 09:19
@AmeyWale AmeyWale force-pushed the refunds-v2-retrieve-flow branch from 185c552 to 9f11798 Compare April 21, 2025 11:37
jarnura
jarnura previously approved these changes Apr 29, 2025
tsdk02
tsdk02 previously approved these changes Apr 30, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue May 2, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 2, 2025
@AmeyWale AmeyWale dismissed stale reviews from tsdk02 and jarnura via 7abcb1a May 5, 2025 08:38
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 7, 2025
Merged via the queue into main with commit a289f19 May 7, 2025
16 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the refunds-v2-retrieve-flow branch May 7, 2025 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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]: Add Refunds Retrieve and Rsync Flow in V2 apis.
5 participants