Skip to content

Commit

Permalink
Updated order endpoints (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored Mar 19, 2024
1 parent ec997c6 commit e40fbf1
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
75 changes: 75 additions & 0 deletions documents/order.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,82 @@ client.order.edit(orderId,{
}
```
-------------------------------------------------------------------------------------------------------
### View RTO/Risk Reasons

```py
orderId = "order_DaaS6LOUAASb7Y";

client.order.viewRtoReview(orderId)
```
**Parameters**

| Name | Type | Description |
|----------|--------|-------------------------------------|
| orderId* | string | The unique identifier of an order to access the fulfillment information. |

**Response:**
```json
{
"risk_tier": "high",
"rto_reasons": [
{
"reason": "short_shipping_address",
"description": "Short shipping address",
"bucket": "address"
},
{
"reason": "address_pincode_state_mismatch",
"description": "Incorrect pincode state entered",
"bucket": "address"
}
]
}
```
-------------------------------------------------------------------------------------------------------

### Update the Fulfillment Details

```py
orderId = "order_DaaS6LOUAASb7Y";

request = {
"payment_method": "upi",
"shipping": {
"waybill": "123456789",
"status": "rto",
"provider": "Bluedart"
}
}

client.order.editFulfillment(orderId, request)
```
**Parameters**

| Name | Type | Description |
|----------|--------|-------------------------------------|
| orderId* | string | The unique identifier of an order to access the fulfillment information. |
| payment_method | string | Payment Method opted by the customer to complete the payment. Possible values is `upi`, `card`, `wallet`, `netbanking`, `cod`, `emi`, `cardless_emi`, `paylater`, `recurring`, `other`. |
| shipping | object | Contains the shipping data. [here](https://razorpay.com/docs/payments/magic-checkout/rto-intelligence/#step-3-update-the-fulfillment-details) are supported |

**Response:**
```json
{
"entity": "order.fulfillment",
"order_id": "EKwxwAgItXXXX",
"payment_method": "upi",
"shipping": {
"waybill": "123456789",
"status": "rto",
"provider": "Bluedart"
}
}
```
-------------------------------------------------------------------------------------------------------

**PN: * indicates mandatory fields**
<br>
<br>
**For reference click [here](https://razorpay.com/docs/api/orders/)**

**PN: * indicates mandatory fields**
<br>
Expand Down
23 changes: 21 additions & 2 deletions razorpay/resources/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ def edit(self, order_id, data={}, **kwargs):
Order Dict which was edited
"""
url = '{}/{}'.format(self.base_url, order_id)
url = f"{self.base_url}/{order_id}"
return self.patch_url(url, data, **kwargs)

def viewRtoReview(self, order_id, data={}, **kwargs):
"""
View rto risk reasons
Returns:
Dict for given Order Id
"""
url = f"{self.base_url}/{order_id}/rto_review"
return self.post_url(url, data, **kwargs)

return self.patch_url(url, data, **kwargs)
def editFulfillment(self, order_id, data={}, **kwargs):
"""
Update the Fulfillment Details
Returns:
Dict for given Order Id
"""
url = f"{self.base_url}/{order_id}/fulfillment"
return self.post_url(url, data, **kwargs)
10 changes: 10 additions & 0 deletions tests/mocks/fulfillment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"entity": "order.fulfillment",
"order_id": "EKwxwAgItXXXX",
"payment_method": "upi",
"shipping": {
"waybill": "123456789",
"status": "rto",
"provider": "Bluedart"
}
}
15 changes: 15 additions & 0 deletions tests/mocks/rto.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"risk_tier": "high",
"rto_reasons": [
{
"reason": "short_shipping_address",
"description": "Short shipping address",
"bucket": "address"
},
{
"reason": "address_pincode_state_mismatch",
"description": "Incorrect pincode state entered",
"bucket": "address"
}
]
}
26 changes: 26 additions & 0 deletions tests/test_client_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,29 @@ def test_order_edit(self):
responses.add(responses.PATCH, url, status=200, body=json.dumps(result),
match_querystring=True)
self.assertEqual(self.client.order.edit('dummy_id', param), result)

@responses.activate
def test_order_view_rto_review(self):
result = mock_file('rto')
order_id = 'fake_order_id'
url = f"{self.base_url}/{order_id}/rto_review"
responses.add(responses.POST, url, status=200, body=json.dumps(result),
match_querystring=True)
self.assertEqual(self.client.order.viewRtoReview(order_id), result)

@responses.activate
def test_order_edit_fulfillment(self):
request = {
"payment_method": "upi",
"shipping": {
"waybill": "123456789",
"status": "rto",
"provider": "Bluedart"
}
}
order_id = 'fake_order_id'
result = mock_file('fulfillment')
url = f"{self.base_url}/{order_id}/fulfillment"
responses.add(responses.POST, url, status=200, body=json.dumps(result),
match_querystring=True)
self.assertEqual(self.client.order.editFulfillment(order_id, request), result)

0 comments on commit e40fbf1

Please sign in to comment.