-
Notifications
You must be signed in to change notification settings - Fork 91
docs: add Device Activity and POS Gateway integration documentation #311
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
9 commits
Select commit
Hold shift + click to select a range
e8dc7bd
docs: add Device Activity and POS Gateway integration documentation
PayManiRazor d3e9a99
fix: Replace hardcoded port 8080 with PORT placeholder in documentation
PayManiRazor 157a025
fix: reverse device_mode requirements in documentation
PayManiRazor 43afbbc
docs: Update POS Gateway documentation
PayManiRazor 2bc1c5c
Order first and then device activity APIs
PayManiRazor 7d1bbc0
docs: Update device mode requirements and remove authentication section
PayManiRazor d3fb8a0
docs: Final updates to POS Gateway documentation
PayManiRazor f2820c6
docs: Final cleanup of deviceActivity.md
PayManiRazor c933ba4
Merge branch 'master' into feature/add-pos-documentation
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,299 @@ | ||
| ## Device Activity | ||
|
|
||
| ### Create device activity | ||
|
|
||
| ```py | ||
| client.device_activity.create({ | ||
| "device_id": "2841158834", # Required for device_mode="wireless", optional for device_mode="wired" | ||
| "action": "initiate_checkout", # Required: Action type | ||
| "notes": { # Optional: Additional notes | ||
| "key1": "value1", | ||
| "key2": "value2" | ||
| }, | ||
| "initiate_checkout": { # Required for initiate_checkout | ||
| "name": "Acme Corp", # Optional: Business name | ||
| "amount": 19900, # Required: Amount in paise (₹199.00) | ||
| "currency": "INR", # Required: Currency code | ||
| "description": "POS Transaction", # Required: Transaction description | ||
| "type": "in_person", # Optional: Transaction type | ||
| "order_id": "order_R7vqkfqG3Iw02m", # Required: Order reference | ||
| "prefill": { # Optional: Customer prefill data | ||
| "name": "Gaurav Kumar", | ||
| "email": "[email protected]", | ||
| "contact": "9000090000", | ||
| "method": "upi" # Optional: "upi"|"card" | ||
| } | ||
| } | ||
| }, device_mode="wired") | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Name | Type | Description | | ||
| |---------------|--------|--------------------------------------------------------------------------------| | ||
| | device_id | string | Device identifier. Required for wireless mode, optional for wired mode | | ||
| | action* | string | Action type. Possible values: `initiate_checkout`, `close_checkout` | | ||
| | notes | object | A key-value pair for additional information | | ||
| | initiate_checkout* | object | Required when action is `initiate_checkout`. Contains checkout details | | ||
| | device_mode* | string | Device communication mode. Possible values: `wired`, `wireless` | | ||
|
|
||
| **initiate_checkout Object Parameters:** | ||
|
|
||
| | Name | Type | Description | | ||
| |---------------|--------|--------------------------------------------------------------------------------| | ||
| | name* | string | Business name | | ||
| | amount* | integer| Amount in paise (₹199.00 = 19900) | | ||
| | currency* | string | Currency code (e.g., "INR") | | ||
| | description* | string | Transaction description | | ||
| | type | string | Optional transaction type (e.g., "in_person") | | ||
| | order_id* | string | Order reference ID | | ||
| | prefill | object | Optional customer prefill data (name, email, contact, method) | | ||
|
|
||
| **prefill Object Parameters:** | ||
|
|
||
| | Name | Type | Description | | ||
| |---------------|--------|--------------------------------------------------------------------------------| | ||
| | name | string | Optional customer name | | ||
| | email | string | Optional customer email | | ||
| | contact | string | Optional customer contact number | | ||
| | method | string | Optional payment method: "upi", "card" | ||
|
|
||
| **Success Response:** | ||
|
|
||
| ```json | ||
| { | ||
| "id": "pda_NVTKa9PL0yessI", | ||
| "entity": "device.activity", | ||
| "device_id": "2841158834", | ||
| "action": "initiate_checkout", | ||
| "initiate_checkout": { | ||
| "name": "Acme Corp", | ||
| "amount": 19900, | ||
| "currency": "INR", | ||
| "description": "POS Transaction", | ||
| "order_id": "order_R7vqkfqG3Iw02m", | ||
| "prefill": { | ||
| "name": "Gaurav Kumar", | ||
| "email": "[email protected]", | ||
| "contact": "9000090000", | ||
| "method": "upi" | ||
| } | ||
| }, | ||
| "status": "processing", | ||
| "error": null | ||
| } | ||
| ``` | ||
|
|
||
| **Failure Response:** | ||
|
|
||
| ```json | ||
| { | ||
| "id": "pda_NVTKa9PL0yessI", | ||
| "entity": "device.activity", | ||
| "device_id": "2841158834", | ||
| "action": "initiate_checkout", | ||
| "initiate_checkout": { | ||
| "name": "Acme Corp", | ||
| "amount": 19900, | ||
| "currency": "INR", | ||
| "description": "POS Transaction", | ||
| "order_id": "order_R7vqkfqG3Iw02m", | ||
| "prefill": { | ||
| "name": "Gaurav Kumar", | ||
| "email": "[email protected]", | ||
| "contact": "9000090000", | ||
| "method": "upi" | ||
| } | ||
| }, | ||
| "status": "failed", | ||
| "error": { | ||
| "code": "BAD_REQUEST_ERROR", | ||
| "reason": "device_not_connected" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| **Status Values:** | ||
| - `"processing"` - Checkout is being processed | ||
| - `"completed"` - Checkout completed successfully | ||
| - `"failed"` - Checkout failed with error details | ||
|
|
||
| --- | ||
|
|
||
| ### Create device activity (Close Checkout) | ||
|
|
||
| ```py | ||
| client.device_activity.create({ | ||
| "device_id": "2841158834", | ||
| "action": "close_checkout" | ||
| }, device_mode="wireless") | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Name | Type | Description | | ||
| |---------------|--------|--------------------------------------------------------------------------------| | ||
| | device_id | string | Device identifier. Required for wireless mode, optional for wired mode | | ||
| | action* | string | Action type: `close_checkout` | | ||
| | device_mode* | string | Device communication mode. Possible values: `wired`, `wireless` | | ||
|
|
||
| **Success Response:** | ||
|
|
||
| ```json | ||
| { | ||
| "id": "pda_NVTKa9PL0yessJ", | ||
| "entity": "device.activity", | ||
| "device_id": "2841158834", | ||
| "action": "close_checkout", | ||
| "status": "completed", | ||
| "error": null | ||
| } | ||
| ``` | ||
|
|
||
| **Failure Response:** | ||
|
|
||
| ```json | ||
| { | ||
| "id": "pda_NVTKa9PL0yessJ", | ||
| "entity": "device.activity", | ||
| "device_id": "2841158834", | ||
| "action": "close_checkout", | ||
| "status": "failed", | ||
| "error": { | ||
| "code": "BAD_REQUEST_ERROR", | ||
| "reason": "checkout_not_found" | ||
| } | ||
| } | ||
| ``` | ||
| --- | ||
|
|
||
| ## Device Modes | ||
|
|
||
| ### Wired Mode | ||
| - **device_mode**: `"wired"` | ||
| - **device_id**: Optional | ||
| - Direct device connection | ||
|
|
||
| ### Wireless Mode | ||
| - **device_mode**: `"wireless"` | ||
| - **device_id**: Required | ||
| - Wireless device communication | ||
|
|
||
| --- | ||
|
|
||
| ## Error Handling | ||
|
|
||
| ```py | ||
| from razorpay.errors import BadRequestError | ||
|
|
||
| try: | ||
| response = client.device_activity.create({ | ||
| "device_id": "2841158834", | ||
| "action": "initiate_checkout" | ||
| }, device_mode="invalid_mode") | ||
| except BadRequestError as e: | ||
| print(f"Error: {e}") | ||
| # Output: Invalid device mode. Allowed values are 'wired' and 'wireless'. | ||
| ``` | ||
|
|
||
| **Common Errors:** | ||
|
|
||
| | Error | Description | Solution | | ||
| |-------|-------------|----------| | ||
| | `BadRequestError` | Invalid device_mode parameter | Use only `"wired"` or `"wireless"` | | ||
| | `BadRequestError` | Missing activity_id | Provide valid activity ID for get_status | | ||
| | `BadRequestError` | Missing device_id in wireless mode | Include device_id when using wireless mode | | ||
|
|
||
| **API Error Responses:** | ||
|
|
||
| | Error Code | Reason | Description | Solution | | ||
| |------------|--------|-------------|----------| | ||
| | `BAD_REQUEST_ERROR` | `device_not_connected` | Device is not connected | Check device connection and try again | | ||
| | `BAD_REQUEST_ERROR` | `checkout_not_found` | Checkout session not found | Verify checkout was initiated before closing | | ||
|
|
||
| --- | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```py | ||
| import razorpay | ||
|
|
||
| # Initialize client | ||
| client = razorpay.Client(auth=('key_id', 'key_secret'), base_url='http://localhost:PORT') | ||
|
|
||
| try: | ||
| # Step 1: Initiate checkout | ||
| activity = client.device_activity.create({ | ||
| "device_id": "2841158834", | ||
| "action": "initiate_checkout", | ||
| "notes": {"merchant_id": "12345"}, | ||
| "initiate_checkout": { | ||
| "name": "Acme Corp", | ||
| "amount": 19900, | ||
| "currency": "INR", | ||
| "description": "POS Transaction", | ||
| "type": "in_person", # Optional | ||
| "order_id": "order_R7vqkfqG3Iw02m", | ||
| "prefill": { | ||
| "name": "Gaurav Kumar", | ||
| "email": "[email protected]", | ||
| "contact": "9000090000", | ||
| "method": "upi" | ||
| } | ||
| } | ||
| }, device_mode="wired") | ||
|
|
||
| activity_id = activity['id'] | ||
| print(f"Checkout initiated: {activity_id}") | ||
|
|
||
| # Step 2: Check status | ||
| status = client.device_activity.get_status(activity_id, device_mode="wired") | ||
| print(f"Current status: {status['status']}") | ||
|
|
||
| # Step 3: Close checkout when done | ||
| close_response = client.device_activity.create({ | ||
| "device_id": "2841158834", | ||
| "action": "close_checkout" | ||
| }, device_mode="wired") | ||
|
|
||
| print("Checkout closed successfully") | ||
|
|
||
| except Exception as e: | ||
| print(f"Error: {e}") | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Integration with Order APIs | ||
|
|
||
| Device Activity APIs work seamlessly with Order APIs for complete POS integration: | ||
|
|
||
| ```py | ||
| # Create order with device_mode | ||
| order = client.order.create({ | ||
| "amount": 50000, | ||
| "currency": "INR", | ||
| "receipt": "order_001" | ||
| }, device_mode="wired") | ||
|
|
||
| # Initiate device checkout | ||
| checkout = client.device_activity.create({ | ||
| "device_id": "2841158834", | ||
| "action": "initiate_checkout", | ||
| "notes": {"order_id": order['id']}, | ||
| "initiate_checkout": { | ||
| "name": "Acme Corp", | ||
| "amount": order['amount'], | ||
| "currency": order['currency'], | ||
| "description": "POS Transaction", | ||
| "type": "in_person", | ||
| "order_id": order['id'], | ||
| "prefill": { | ||
| "method": "upi" | ||
| } | ||
| } | ||
| }, device_mode="wired") | ||
|
|
||
| # Monitor checkout status | ||
| status = client.device_activity.get_status(checkout['id'], device_mode="wired") | ||
| ``` |
Oops, something went wrong.
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.