From 0c0ebe9c4f4f2499b812ee82ee756a3972d56570 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 21 Mar 2024 11:26:28 +0530 Subject: [PATCH 1/2] updated order class --- documents/order.md | 71 +++++++++++++++++++ src/main/java/com/razorpay/Constants.java | 3 +- src/main/java/com/razorpay/OrderClient.java | 8 +++ .../java/com/razorpay/OrderClientTest.java | 68 ++++++++++++++++++ 4 files changed, 149 insertions(+), 1 deletion(-) diff --git a/documents/order.md b/documents/order.md index 03eeb01e..88401fdf 100644 --- a/documents/order.md +++ b/documents/order.md @@ -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**
diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 98452716..659a1e7c 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -169,5 +169,6 @@ public class Constants { static final String AUTHORIZE = "authorize"; 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"; } diff --git a/src/main/java/com/razorpay/OrderClient.java b/src/main/java/com/razorpay/OrderClient.java index 1a35d1fe..cdd83bdf 100644 --- a/src/main/java/com/razorpay/OrderClient.java +++ b/src/main/java/com/razorpay/OrderClient.java @@ -33,4 +33,12 @@ public List 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); + } } diff --git a/src/test/java/com/razorpay/OrderClientTest.java b/src/test/java/com/razorpay/OrderClientTest.java index 364bb00e..623eed95 100644 --- a/src/test/java/com/razorpay/OrderClientTest.java +++ b/src/test/java/com/razorpay/OrderClientTest.java @@ -219,4 +219,72 @@ public void edit() throws RazorpayException { assertTrue(false); } } + + @Test + public void viewRtoReview() throws RazorpayException { + JSONObject request = new JSONObject(); + request.put("payment_method","upi"); + + String mockedResponseJson = "{\n" + + " \"risk_tier\": \"high\",\n" + + " \"entity\": \"order\",\n" + + " \"rto_reasons\": [\n" + + " {\n" + + " \"reason\": \"short_shipping_address\",\n" + + " \"description\": \"Short shipping address\",\n" + + " \"bucket\": \"address\"\n" + + " },\n" + + " {\n" + + " \"reason\": \"address_pincode_state_mismatch\",\n" + + " \"description\": \"Incorrect pincode state entered\",\n" + + " \"bucket\": \"address\"\n" + + " }\n" + + " ]\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + 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"); + + String mockedResponseJson = "{\n" + + " \"entity\": \"order\",\n" + + " \"order_id\": \"order_EKwxwAgItmmXdp\",\n" + + " \"payment_method\": \"upi\",\n" + + " \"shipping\": {\n" + + " \"waybill\": \"123456789\",\n" + + " \"status\": \"rto\",\n" + + " \"provider\": \"Bluedart\"\n" + + " }\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + 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); + } + } } \ No newline at end of file From 211eb42c0333a92d29a8d6244d71db868a4384bb Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 26 Mar 2024 12:16:00 +0530 Subject: [PATCH 2/2] update doc and test response --- documents/order.md | 14 ++--- .../java/com/razorpay/OrderClientTest.java | 63 ++++++++++--------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/documents/order.md b/documents/order.md index 88401fdf..a060b19e 100644 --- a/documents/order.md +++ b/documents/order.md @@ -274,8 +274,8 @@ Order order = instance.orders.viewRtoReview(orderId); ``` **Parameters** -| Name | Type | Description | -|----------|--------|-------------------------------------| +| Name | Type | Description | +|----------|--------|-------------------------------------------------------------------------| | orderId* | string | The unique identifier of an order to access the rto_review information. | **Response:** @@ -316,11 +316,11 @@ 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 | +| 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 diff --git a/src/test/java/com/razorpay/OrderClientTest.java b/src/test/java/com/razorpay/OrderClientTest.java index 623eed95..9be263b8 100644 --- a/src/test/java/com/razorpay/OrderClientTest.java +++ b/src/test/java/com/razorpay/OrderClientTest.java @@ -1,5 +1,6 @@ package com.razorpay; +import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; import org.mockito.InjectMocks; @@ -225,24 +226,28 @@ public void viewRtoReview() throws RazorpayException { JSONObject request = new JSONObject(); request.put("payment_method","upi"); - String mockedResponseJson = "{\n" + - " \"risk_tier\": \"high\",\n" + - " \"entity\": \"order\",\n" + - " \"rto_reasons\": [\n" + - " {\n" + - " \"reason\": \"short_shipping_address\",\n" + - " \"description\": \"Short shipping address\",\n" + - " \"bucket\": \"address\"\n" + - " },\n" + - " {\n" + - " \"reason\": \"address_pincode_state_mismatch\",\n" + - " \"description\": \"Incorrect pincode state entered\",\n" + - " \"bucket\": \"address\"\n" + - " }\n" + - " ]\n" + - "}"; + 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); + mockResponseFromExternalClient(mockedResponseJson.toString()); mockResponseHTTPCodeFromExternalClient(200); Order fetch = orderClient.viewRtoReview(ORDER_ID); assertNotNull(fetch); @@ -264,18 +269,20 @@ public void editFulfillment() throws RazorpayException { request.put("payment_method","upi"); request.put("shipping","shipping"); - String mockedResponseJson = "{\n" + - " \"entity\": \"order\",\n" + - " \"order_id\": \"order_EKwxwAgItmmXdp\",\n" + - " \"payment_method\": \"upi\",\n" + - " \"shipping\": {\n" + - " \"waybill\": \"123456789\",\n" + - " \"status\": \"rto\",\n" + - " \"provider\": \"Bluedart\"\n" + - " }\n" + - "}"; + 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); + mockResponseFromExternalClient(mockedResponseJson.toString()); mockResponseHTTPCodeFromExternalClient(200); Order fetch = orderClient.editFulfillment(ORDER_ID, request); assertNotNull(fetch);