-
Notifications
You must be signed in to change notification settings - Fork 91
ISS-971955 feat: Add DeviceActivity support for POS Gateway integration #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
273f7da
feat: Add DeviceActivity support for POS Gateway integration
PayManiRazor 260ec9e
refactor: simplify authentication and improve DeviceActivity API
PayManiRazor d384304
Implement single client with use_public_auth parameter for device APIs
PayManiRazor f0f8061
chore: bump version to 1.5.0
PayManiRazor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| class DeviceMode: | ||
| WIRED = "wired" | ||
| WIRELESS = "wireless" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,3 +29,5 @@ class URL(object): | |
| DOCUMENT= "/documents" | ||
| DISPUTE= "/disputes" | ||
|
|
||
| DEVICE_ACTIVITY_URL = "/devices/activity" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from typing import Any, Dict, Optional | ||
|
|
||
| from .base import Resource | ||
| from ..constants.url import URL | ||
| from ..constants.device import DeviceMode | ||
| from ..errors import BadRequestError | ||
|
|
||
|
|
||
| class DeviceActivity(Resource): | ||
| def __init__(self, client=None): | ||
| super(DeviceActivity, self).__init__(client) | ||
| self.base_url = URL.V1 + URL.DEVICE_ACTIVITY_URL | ||
|
|
||
| def _validate_device_mode(self, mode: Optional[str]) -> Optional[str]: | ||
| """ | ||
| Validate device communication mode | ||
|
|
||
| Args: | ||
| mode: Device communication mode ("wired" or "wireless") | ||
|
|
||
| Returns: | ||
| Validated mode or None if mode is None | ||
|
|
||
| Raises: | ||
| BadRequestError: If mode is invalid | ||
| """ | ||
| if mode is not None: | ||
| if mode not in (DeviceMode.WIRED, DeviceMode.WIRELESS): | ||
| raise BadRequestError("Invalid device mode. Allowed values are 'wired' and 'wireless'.") | ||
| return mode | ||
| return None | ||
|
|
||
| def create(self, data: Dict[str, Any], mode: Optional[str] = None, **kwargs) -> Dict[str, Any]: | ||
| """ | ||
| Create a new device activity for POS gateway | ||
|
|
||
| Args: | ||
| data: Dictionary containing device activity data in the format expected by rzp-pos-gateway | ||
| mode: Device communication mode ("wired" or "wireless") | ||
|
|
||
| Returns: | ||
| DeviceActivity object | ||
| """ | ||
| device_mode = self._validate_device_mode(mode) | ||
|
|
||
| url = self.base_url | ||
| return self.post_url(url, data, device_mode=device_mode, use_public_auth=True, **kwargs) | ||
|
|
||
| def get_status(self, activity_id: str, mode: Optional[str] = None, **kwargs) -> Dict[str, Any]: | ||
| """ | ||
| Get the status of a device activity | ||
|
|
||
| Args: | ||
| activity_id: Activity ID to fetch status for | ||
| mode: Device communication mode ("wired" or "wireless") | ||
|
|
||
| Returns: | ||
| DeviceActivity object with current status | ||
| """ | ||
| if not activity_id: | ||
| raise BadRequestError("Activity ID must be provided") | ||
|
|
||
| device_mode = self._validate_device_mode(mode) | ||
|
|
||
| url = f"{self.base_url}/{activity_id}" | ||
| return self.get_url(url, {}, device_mode=device_mode, use_public_auth=True, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"id": "act_123", "status": "created", "mode": "wired"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"id": "act_123", "status": "in_progress", "mode": "wireless"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import unittest | ||
| import responses | ||
| import json | ||
|
|
||
| from .helpers import mock_file, ClientTestCase | ||
| from razorpay.errors import BadRequestError | ||
| import razorpay | ||
|
|
||
|
|
||
| class TestClientDeviceActivity(ClientTestCase): | ||
|
|
||
| def setUp(self): | ||
| super(TestClientDeviceActivity, self).setUp() | ||
| self.device_activity_base_url = f"{self.base_url}/devices/activity" | ||
| # Device APIs automatically use public authentication (key_id only) | ||
| # by passing use_public_auth=True internally in device_activity.py | ||
| self.public_client = razorpay.Client(auth=('key_id', 'key_secret')) | ||
|
|
||
| @responses.activate | ||
| def test_create_device_activity(self): | ||
| result = mock_file('fake_device_activity') | ||
| url = self.device_activity_base_url | ||
| responses.add(responses.POST, url, status=200, | ||
| body=json.dumps(result), match_querystring=True) | ||
| self.assertEqual(self.public_client.device_activity.create({'foo': 'bar'}, mode='wired'), result) | ||
|
|
||
| @responses.activate | ||
| def test_get_status_device_activity(self): | ||
| activity_id = 'act_123' | ||
| result = mock_file('fake_device_activity_status') | ||
| url = f"{self.device_activity_base_url}/{activity_id}" | ||
| responses.add(responses.GET, url, status=200, | ||
| body=json.dumps(result), match_querystring=True) | ||
| self.assertEqual(self.public_client.device_activity.get_status(activity_id, mode='wireless'), result) | ||
|
|
||
| def test_invalid_mode_raises(self): | ||
| with self.assertRaises(BadRequestError): | ||
| self.public_client.device_activity.create({'foo': 'bar'}, mode='invalid') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.