Skip to content

Commit

Permalink
updated order class (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored Apr 1, 2024
1 parent 6994748 commit d899315
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
71 changes: 71 additions & 0 deletions documents/order.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,77 @@ Order order = instance.orders.edit(orderId,orderRequest);
```
-------------------------------------------------------------------------------------------------------

### View RTO/Risk Reasons

```java
String orderId = "order_DaaS6LOUAASb7Y";

Order order = instance.orders.viewRtoReview(orderId);
```
**Parameters**

| Name | Type | Description |
|----------|--------|-------------------------------------------------------------------------|
| orderId* | string | The unique identifier of an order to access the rto_review 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

```java
String orderId = "order_DaaS6LOUAASb7Y";

JSONObject request = new JSONObject();
JSONObject shipping = new JSONObject();
shipping.put("waybill", "123456789");
shipping.put("status", "rto");
shipping.put("provider", "Bluedart");

request.put("payment_method","upi");
request.put("shipping","shipping");

Order order = instance.orders.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>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/razorpay/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public class Constants {
static final String TOKEN = "/token";
static final String REVOKE = "/revoke";

static final String VIEW_RTO = "orders/%s/rto_review";
static final String FULFILLMENT = "orders/%s/fulfillment";

static final String DISPUTE = "/disputes";
static final String DISPUTE_FETCH = "/disputes/%s";
static final String DISPUTE_ACCEPT = "/disputes/%s/accept";
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/razorpay/OrderClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public List<Payment> fetchPayments(String id) throws RazorpayException {
public Order edit(String id, JSONObject request) throws RazorpayException {
return patch(Constants.VERSION, String.format(Constants.ORDER_EDIT, id), request);
}

public Order viewRtoReview(String id) throws RazorpayException {
return post(Constants.VERSION, String.format(Constants.VIEW_RTO, id), null);
}

public Order editFulfillment(String id, JSONObject request) throws RazorpayException {
return post(Constants.VERSION, String.format(Constants.FULFILLMENT, id), request);
}
}
75 changes: 75 additions & 0 deletions src/test/java/com/razorpay/OrderClientTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.razorpay;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -219,4 +220,78 @@ public void edit() throws RazorpayException {
assertTrue(false);
}
}

@Test
public void viewRtoReview() throws RazorpayException {
JSONObject request = new JSONObject();
request.put("payment_method","upi");

JSONObject mockedResponseJson = new JSONObject();
mockedResponseJson.put("entity","order");
mockedResponseJson.put("risk_tier","high");

JSONArray rtoArray = new JSONArray();
JSONObject reason1 = new JSONObject();
reason1.put("reason", "short_shipping_address");
reason1.put("description", "Short shipping address");
reason1.put("bucket", "address");

JSONObject reason2 = new JSONObject();
reason1.put("reason", "address_pincode_state_mismatch");
reason1.put("description", "Incorrect pincode state entered");
reason1.put("bucket", "address");

rtoArray.put(reason1);
rtoArray.put(reason2);

mockedResponseJson.put("rto_reasons", rtoArray);

try {
mockResponseFromExternalClient(mockedResponseJson.toString());
mockResponseHTTPCodeFromExternalClient(200);
Order fetch = orderClient.viewRtoReview(ORDER_ID);
assertNotNull(fetch);
assertEquals(true,fetch.has("risk_tier"));
String createRequest = getHost(String.format(Constants.VIEW_RTO, ORDER_ID));
verifySentRequest(false, null, createRequest);
} catch (IOException e) {
assertTrue(false);
}
}
@Test
public void editFulfillment() throws RazorpayException {
JSONObject request = new JSONObject();
JSONObject shipping = new JSONObject();
shipping.put("waybill", "123456789");
shipping.put("status", "rto");
shipping.put("provider", "Bluedart");

request.put("payment_method","upi");
request.put("shipping","shipping");

JSONObject mockedResponseJson = new JSONObject();
mockedResponseJson.put("entity","order");
mockedResponseJson.put("order_id","order_EKwxwAgItmmXdp");
mockedResponseJson.put("payment_method","upi");

JSONObject shippingObj = new JSONObject();
shippingObj.put("waybill", "123456789");
shippingObj.put("status", "rto");
shippingObj.put("provider", "Bluedart");

mockedResponseJson.put("shipping",shippingObj);

try {
mockResponseFromExternalClient(mockedResponseJson.toString());
mockResponseHTTPCodeFromExternalClient(200);
Order fetch = orderClient.editFulfillment(ORDER_ID, request);
assertNotNull(fetch);
assertEquals(ORDER_ID,fetch.get("order_id"));
assertEquals("order",fetch.get("entity"));
String createRequest = getHost(String.format(Constants.FULFILLMENT, ORDER_ID));
verifySentRequest(true, request.toString(), createRequest);
} catch (IOException e) {
assertTrue(false);
}
}
}

0 comments on commit d899315

Please sign in to comment.