Skip to content
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

updated order class #314

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading