Skip to content

Conversation

sai-harsha-vardhan
Copy link
Contributor

@sai-harsha-vardhan sai-harsha-vardhan commented Apr 15, 2024

Type of Change

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

Description

add retrieve poll status api

This is a generic poll status retrieve API, which can be used in any polling flows. application will set a poll_id in backend as pending, and sends back a poll_id to client to keep polling until the status is completed. once it turns to completed, client will do the required action. This is a light weight alternative to actually polling with the payment status or similar heavy 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

How did you test it?

Tested Manually

  1. Currently we can't test the entire flow, but to check the API we can use the below CURL to check the poll status of some random poll_id, which is expected to give status as 404 Not Found (because it's not a valid one)
curl --location --request GET '{{BASE_URL}}/poll/status/poll_id' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: {{API_KEY}}'
image

Expected 200 response

{
    "poll_id": "abc",
    "status": "pending"
}

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
  • I added a CHANGELOG entry if applicable

@sai-harsha-vardhan sai-harsha-vardhan added A-core Area: Core flows C-feature Category: Feature request or enhancement labels Apr 15, 2024
@sai-harsha-vardhan sai-harsha-vardhan added this to the April 2024 milestone Apr 15, 2024
@sai-harsha-vardhan sai-harsha-vardhan self-assigned this Apr 15, 2024
@sai-harsha-vardhan sai-harsha-vardhan requested review from a team as code owners April 15, 2024 04:15
.parse_enum("PollStatus")
.map_err(|err| logger::warn!("error while parsing PollStatus: {err}"))
.ok()
.unwrap_or(PollStatus::NotFound)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be InternalServerError

.ok()
.unwrap_or(PollStatus::NotFound)
})
.unwrap_or(PollStatus::NotFound);
Copy link
Contributor

Choose a reason for hiding this comment

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

we should return a 4xx in this case because we have poll id in the request path, so if the resource is not found then a 404 should be returned

.attach_printable("Failed to get redis connection")?;
let request_poll_id = req.poll_id;
// prepend 'poll_' to restrict access to only fetching Poll IDs, as this is a freely passed string in the request
let poll_id = format!("poll_{}", request_poll_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

how are we restricting access control for poll ids? A merchant with a publishable key can access poll status of other merchants?

@sai-harsha-vardhan sai-harsha-vardhan requested a review from a team as a code owner April 17, 2024 08:01
@likhinbopanna likhinbopanna added this pull request to the merge queue Apr 17, 2024
Merged via the queue into main with commit ca47ea9 Apr 17, 2024
@likhinbopanna likhinbopanna deleted the add-poll-status-api branch April 17, 2024 10:39
pixincreate added a commit that referenced this pull request Apr 18, 2024
…en-capture-status-handle

* 'main' of github.com:juspay/hyperswitch:
  feat(router): add retrieve poll status api (#4358)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants