From 5adec4a4ae4e64fc3ec6a1744c1df55861bce283 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 26 Mar 2024 14:27:49 +0530 Subject: [PATCH 1/8] doc allignment --- documents/document.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/documents/document.md b/documents/document.md index cd7088cb..e93e35b7 100644 --- a/documents/document.md +++ b/documents/document.md @@ -12,10 +12,10 @@ **Parameters:** -| Name | Type | Description | -|-------|-----------|--------------------------------------------------| -| file* | string | The URL generated once the business proof document is uploaded. | -| purpose | string | Possible value is `dispute_evidence` | +| Name | Type | Description | +|----------|-----------|-----------------------------------------------------------------| +| file* | string | The URL generated once the business proof document is uploaded. | +| purpose | string | Possible value is `dispute_evidence` | **Response:** ```json @@ -41,9 +41,9 @@ Document document = instance.document.fetch(documentId); **Parameters:** -| Name | Type | Description | -|-------|--------|--------------------------------------------------| -| documentId | string | The unique identifier of the document. | +| Name | Type | Description | +|-------------|--------|--------------------------------------------------| +| documentId | string | The unique identifier of the document. | **Response:** ```json From c8f4edaa901089233c145deb21138871713e423f Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 29 Mar 2024 16:49:02 +0530 Subject: [PATCH 2/8] null handling --- src/main/java/com/razorpay/ApiUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/razorpay/ApiUtils.java b/src/main/java/com/razorpay/ApiUtils.java index c02b4070..20778b08 100755 --- a/src/main/java/com/razorpay/ApiUtils.java +++ b/src/main/java/com/razorpay/ApiUtils.java @@ -80,7 +80,7 @@ static Response postRequest(String version, String path, JSONObject requestObjec RequestBody requestBody; - if(requestObject.has("file")){ + if(requestObject != null && requestObject.has("file")){ requestBody = fileRequestBody(requestObject); }else{ String requestContent = requestObject == null ? "" : requestObject.toString(); From a521eebcc8121a982ebcbf7715c5a183fb9dfd12 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 1 Apr 2024 13:10:09 +0530 Subject: [PATCH 3/8] json string to json object --- documents/document.md | 2 +- .../java/com/razorpay/DocumentClientTest.java | 42 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/documents/document.md b/documents/document.md index e93e35b7..ca936745 100644 --- a/documents/document.md +++ b/documents/document.md @@ -4,7 +4,7 @@ ```java JSONObject request = new JSONObject(); - request.put("file","/Users/your_name/Downloads/sample_uploaded.pdf"); + request.put("file","/Users/your_name/Downloads/sample_uploaded.jpeg"); request.put("purpose","dispute_evidence"); Document document = instance.document.create(request); diff --git a/src/test/java/com/razorpay/DocumentClientTest.java b/src/test/java/com/razorpay/DocumentClientTest.java index a123c7b2..4bccc645 100644 --- a/src/test/java/com/razorpay/DocumentClientTest.java +++ b/src/test/java/com/razorpay/DocumentClientTest.java @@ -16,20 +16,20 @@ public class DocumentClientTest extends BaseTest{ @Test public void create() throws RazorpayException { JSONObject request = new JSONObject(); - request.put("files","/Users/your_name/Downloads/sample_uploaded.pdf"); + request.put("files","/Users/your_name/Downloads/sample_uploaded.jpeg"); request.put("purpose","dispute_evidence"); - String mockedResponseJson = "{\n" + - " \"id\": \"doc_EsyWjHrfzb59Re\",\n" + - " \"entity\": \"document\",\n" + - " \"purpose\": \"dispute_evidence\",\n" + - " \"name\": \"file_19_18_2020.jpg\",\n" + - " \"mime_type\": \"image/png\",\n" + - " \"size\": 2863,\n" + - " \"created_at\": 1590604200\n" + - "}"; + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("id","doc_EsyWjHrfzb59Re"); + mockedResponseJson.put("entity","document"); + mockedResponseJson.put("purpose","dispute_evidence"); + mockedResponseJson.put("name","sample_uploaded.jpg"); + mockedResponseJson.put("mime_type","image/png"); + mockedResponseJson.put("size","2863"); + mockedResponseJson.put("created_at","1590604200"); + try { - mockResponseFromExternalClient(mockedResponseJson); + mockResponseFromExternalClient(mockedResponseJson.toString()); mockResponseHTTPCodeFromExternalClient(200); Document document = documentClient.create(request); assertNotNull(document); @@ -46,17 +46,17 @@ public void create() throws RazorpayException { @Test public void fetch() throws RazorpayException { - String mockedResponseJson = "{\n" + - " \"id\": \"doc_EsyWjHrfzb59Re\",\n" + - " \"entity\": \"document\",\n" + - " \"purpose\": \"dispute_evidence\",\n" + - " \"name\": \"doc_19_12_2020.jpg\",\n" + - " \"mime_type\": \"image/png\",\n" + - " \"size\": 2863,\n" + - " \"created_at\": 1590604200\n" + - "}"; + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("id","doc_EsyWjHrfzb59Re"); + mockedResponseJson.put("entity","document"); + mockedResponseJson.put("purpose","dispute_evidence"); + mockedResponseJson.put("name","doc_19_12_2020.jpg"); + mockedResponseJson.put("mime_type","image/png"); + mockedResponseJson.put("size","2863"); + mockedResponseJson.put("created_at","1590604200"); + try { - mockResponseFromExternalClient(mockedResponseJson); + mockResponseFromExternalClient(mockedResponseJson.toString()); mockResponseHTTPCodeFromExternalClient(200); Document fetch = documentClient.fetch(DOCUMENT_ID); assertNotNull(fetch); From 2896eb17664a5d6a54b49e7ee2d9166749a66035 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:10:28 +0530 Subject: [PATCH 4/8] update customer endpoint (#308) --- documents/customers.md | 245 ++++++++++++++++++ src/main/java/com/razorpay/BankAccount.java | 10 + .../java/com/razorpay/BankAccountClient.java | 13 + src/main/java/com/razorpay/Constants.java | 7 + .../java/com/razorpay/CustomerClient.java | 16 ++ .../java/com/razorpay/RazorpayClient.java | 2 + .../java/com/razorpay/CustomerClientTest.java | 165 +++++++++++- 7 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/razorpay/BankAccount.java create mode 100644 src/main/java/com/razorpay/BankAccountClient.java diff --git a/documents/customers.md b/documents/customers.md index dfd8e665..360f8ee7 100644 --- a/documents/customers.md +++ b/documents/customers.md @@ -155,6 +155,251 @@ Customer customer = instance.customers.fetch(customerId); ------------------------------------------------------------------------------------------------------- + +### Add Bank Account of Customer + +```java +String customerId = "cust_N5mywh91sXB69O" + +JSONObject customerRequest = new JSONObject(); +customerRequest.put("ifsc_code","UTIB0000194"); +customerRequest.put("account_number","916010082985661"); +customerRequest.put("beneficiary_name","Pratheek"); +customerRequest.put("beneficiary_address1","address 1"); +customerRequest.put("beneficiary_address2","address 2"); +customerRequest.put("beneficiary_address3","address 3"); +customerRequest.put("beneficiary_address4","address 4"); +customerRequest.put("beneficiary_email","random@email.com"); +customerRequest.put("beneficiary_mobile","8762489310"); +customerRequest.put("beneficiary_city","Bangalore"); +customerRequest.put("beneficiary_state","KA"); +customerRequest.put("beneficiary_country","IN"); + +BankAccount bankaccount = instance.customers.addBankAccount(customerId, customerRequest) +``` + +**Parameters:** + +| Name | Type | Description | +|----------------------|----------|---------------------------------------------------------------| +| customerId* | string | Unique identifier of the customer. | +| account_number | string | Customer's bank account number. | +| beneficiary_name | string | The name of the beneficiary associated with the bank account. | +| beneficiary_address1 | string | The virtual payment address. | +| beneficiary_email | string | Email address of the beneficiary. | +| beneficiary_mobile | integer | Mobile number of the beneficiary. | +| beneficiary_city | string | The name of the city of the beneficiary. | +| beneficiary_state | string | The state of the beneficiary. | +| beneficiary_pin | interger | The pin code of the beneficiary's address. | +| ifsc_code | string | The IFSC code of the bank branch associated with the account. | + +**Response:** +```json +{ + "id" : "cust_1Aa00000000001", + "entity": "customer", + "name" : "Saurav Kumar", + "email" : "Saurav.kumar@example.com", + "contact" : "+919000000000", + "gstin":"29XAbbA4369J1PA", + "notes" : [], + "created_at ": 1234567890 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Delete Bank Account of Customer + +```java +String customerId = "cust_N5mywh91sXB69O" + +String bankAccountId = "ba_N6aM8uo64IzxHu" + +Customer customer = instance.customers.deleteBankAccount(customerId, bankaccountId) +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| customerId* | string | Unique identifier of the customer. | +| bankAccountId | string | The bank_id that needs to be deleted. | + +**Response:** +```json +{ + "id": "ba_Evg09Ll05SIPSD", + "ifsc": "ICIC0001207", + "bank_name": "ICICI Bank", + "name": "Test R4zorpay", + "account_number": "XXXXXXXXXXXXXXX0434", + "status": "deleted" +} +``` + +------------------------------------------------------------------------------------------------------- + +### Eligibility Check API + +```java +JSONObject customerRequest = new JSONObject(); +customerRequest.put("inquiry","affordability"); +customerRequest.put("amount", 500); +customerRequest.put("currency","INR"); +JSONObject customer = new JSONObject(); +customer.put("id","elig_xxxxxxxxxxxxx") +customer.put("contact","+919999999999") +customer.put("ip","105.106.107.108") +customer.put("referrer","https://merchansite.com/example/paybill") +customer.put("user_agent","Mozilla/5.0") +customerRequest.put("customer",customer); + +Customer customer = instance.customers.requestEligibilityCheck(customerRequest) +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| inquiry | string | List of methods or instruments on which eligibility check is required. | +| amount* | string | The amount for which the order was created, in currency subunits. | +| currency* | string | A three-letter ISO code for the currency in which you want to accept the payment. | +| customer* | object | Customer details. [here](https://razorpay.com/docs/payments/payment-gateway/affordability/eligibility-check/#eligibility-check-api) | +| instruments | object | Payment instruments on which an eligibility check is required. [here](https://razorpay.com/docs/payments/payment-gateway/affordability/eligibility-check/#eligibility-check-api) | + + +**Response:** +```json +{ + "amount": "500000", + "customer": { + "id": "KkBhM9EC1Y0HTm", + "contact": "+919999999999" + }, + "instruments": [ + { + "method": "emi", + "issuer": "HDFC", + "type": "debit", + "eligibility_req_id": "elig_xxxxxxxxxxxxx", + "eligibility": { + "status": "eligible" + } + }, + { + "method": "paylater", + "provider": "getsimpl", + "eligibility_req_id": "elig_xxxxxxxxxxxxx", + "eligibility": { + "status": "eligible" + } + }, + { + "method": "paylater", + "provider": "icic", + "eligibility_req_id": "elig_xxxxxxxxxxxxx", + "eligibility": { + "status": "eligible" + } + }, + { + "method": "cardless_emi", + "provider": "walnut369", + "eligibility_req_id": "elig_xxxxxxxxxxxxx", + "eligibility": { + "status": "ineligible", + "error": { + "code": "GATEWAY_ERROR", + "description": "The customer has not been approved by the partner.", + "source": "business", + "step": "inquiry", + "reason": "user_not_approved" + } + } + }, + { + "method": "cardless_emi", + "provider": "zestmoney", + "eligibility_req_id": "elig_xxxxxxxxxxxxx", + "eligibility": { + "status": "ineligible", + "error": { + "code": "GATEWAY_ERROR", + "description": "The customer has exhausted their credit limit.", + "source": "business", + "step": "inquiry", + "reason": "credit_limit_exhausted" + } + } + }, + { + "method": "paylater", + "provider": "lazypay", + "eligibility_req_id": "elig_xxxxxxxxxxxxx", + "eligibility": { + "status": "ineligible", + "error": { + "code": "GATEWAY_ERROR", + "description": "The order amount is less than the minimum transaction amount.", + "source": "business", + "step": "inquiry", + "reason": "min_amt_required" + } + } + } + ] +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch Eligibility by id + +```java +String eligibilityId = "elig_xxxxxxxxxxxxx" +Customer customer = instance.customers.fetchEligibility(eligibilityId) +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| eligibilityId | string | The unique identifier of the eligibility request to be retrieved. | + +**Response:** +```json +{ + "instruments": [ + { + "method": "paylater", + "provider": "lazypay", + "eligibility_req_id": "elig_xxxxxxxxxxxxx", + "eligibility": { + "status": "eligible" + } + }, + { + "method": "paylater", + "provider": "getsimpl", + "eligibility_req_id": "elig_xxxxxxxxxxxxx", + "eligibility": { + "status": "ineligible", + "error": { + "code": "GATEWAY_ERROR", + "description": "The customer has exhausted their credit limit", + "source": "gateway", + "step": "inquiry", + "reason": "credit_limit_exhausted" + } + } + } + ] +} +``` + +------------------------------------------------------------------------------------------------------- + **PN: * indicates mandatory fields**

diff --git a/src/main/java/com/razorpay/BankAccount.java b/src/main/java/com/razorpay/BankAccount.java new file mode 100644 index 00000000..47b4303b --- /dev/null +++ b/src/main/java/com/razorpay/BankAccount.java @@ -0,0 +1,10 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class BankAccount extends Entity { + + public BankAccount(JSONObject jsonObject) { + super(jsonObject); + } +} diff --git a/src/main/java/com/razorpay/BankAccountClient.java b/src/main/java/com/razorpay/BankAccountClient.java new file mode 100644 index 00000000..0663714f --- /dev/null +++ b/src/main/java/com/razorpay/BankAccountClient.java @@ -0,0 +1,13 @@ +package com.razorpay; + +import java.util.List; + +import org.json.JSONObject; + +public class BankAccountClient extends ApiClient { + + BankAccountClient(String auth) { + super(auth); + } + +} diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 98452716..8a6a7fc2 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -170,4 +170,11 @@ public class Constants { static final String TOKEN = "/token"; static final String REVOKE = "/revoke"; + static final String ADD_BANK_ACCOUNT = "customers/%s/bank_account"; + + static final String DELETE_BANK_ACCOUNT = "customers/%s/bank_account/%s"; + + static final String ELIGIBILITY = "customers/eligibility"; + + static final String ELIGIBILITY_FETCH = "customers/eligibility/%s"; } diff --git a/src/main/java/com/razorpay/CustomerClient.java b/src/main/java/com/razorpay/CustomerClient.java index aef1da36..6bbe079d 100644 --- a/src/main/java/com/razorpay/CustomerClient.java +++ b/src/main/java/com/razorpay/CustomerClient.java @@ -50,4 +50,20 @@ public Token fetchToken(String id, String tokenId) throws RazorpayException { public Customer deleteToken(String id, String tokenId) throws RazorpayException { return delete(Constants.VERSION, String.format(Constants.TOKEN_DELETE, id, tokenId), null); } + + public BankAccount addBankAccount(String id, JSONObject request) throws RazorpayException { + return post(Constants.VERSION, String.format(Constants.ADD_BANK_ACCOUNT, id), request); + } + + public Customer deleteBankAccount(String id, String bankId) throws RazorpayException { + return delete(Constants.VERSION, String.format(Constants.DELETE_BANK_ACCOUNT, id, bankId), null); + } + + public Customer requestEligibilityCheck(JSONObject request) throws RazorpayException { + return post(Constants.VERSION, Constants.ELIGIBILITY, request); + } + + public Customer fetchEligibility(String id) throws RazorpayException { + return get(Constants.VERSION, String.format(Constants.ELIGIBILITY_FETCH, id), null); + } } diff --git a/src/main/java/com/razorpay/RazorpayClient.java b/src/main/java/com/razorpay/RazorpayClient.java index f009117f..9f5e33d7 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -29,6 +29,7 @@ public class RazorpayClient { public ProductClient product; public WebhookClient webhook; public TncMap tncMap; + public BankAccountClient bankAccount; public RazorpayClient(String key, String secret) throws RazorpayException { this(key, secret, false); } @@ -66,6 +67,7 @@ private void initializeResources(String auth, Boolean enableLogging) throws Razo stakeholder = new StakeholderClient(auth); product = new ProductClient(auth); webhook = new WebhookClient(auth); + bankAccount = new BankAccountClient(auth); } public RazorpayClient addHeaders(Map headers) { diff --git a/src/test/java/com/razorpay/CustomerClientTest.java b/src/test/java/com/razorpay/CustomerClientTest.java index b6ab38c7..c080268e 100644 --- a/src/test/java/com/razorpay/CustomerClientTest.java +++ b/src/test/java/com/razorpay/CustomerClientTest.java @@ -5,6 +5,7 @@ import org.mockito.InjectMocks; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import static org.junit.Assert.*; @@ -14,7 +15,8 @@ public class CustomerClientTest extends BaseTest{ protected CustomerClient customerClient = new CustomerClient(TEST_SECRET_KEY); private static final String CUSTOMER_ID = "cust_1Aa00000000004"; - + private static final String BANKACCOUNT_ID = "ba_LSZht1Cm7xFTwF"; + private static final String ELIGIBILITY_ID = "elig_F1cxDoHWD4fkQt"; private static final String TOKEN_ID = "token_Hxe0skTXLeg9pF"; /** @@ -295,4 +297,165 @@ public void testDeleteToken() throws IOException, RazorpayException { assertTrue(false); } } + + /** + * Add Bank Account + */ + @Test + public void testaddBankAccount() throws RazorpayException{ + + JSONObject request = new JSONObject(); + request.put("account_number","916010082985661"); + request.put("beneficiary_name","Pratheek"); + request.put("ifsc_code","UTIB0000194"); + request.put("beneficiary_address1","address 1"); + request.put("beneficiary_address2","address 2"); + request.put("beneficiary_address3","address 3"); + request.put("beneficiary_address4","address 4"); + request.put("beneficiary_email","random@email.com"); + request.put("beneficiary_mobile","8762489310"); + request.put("beneficiary_city","Bangalore"); + request.put("beneficiary_state","KA"); + request.put("beneficiary_country","IN"); + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("id", "ba_LSZht1Cm7xFTwF"); + mockedResponseJson.put("entity", "bank_account"); + mockedResponseJson.put("ifsc", "ICIC0001207"); + mockedResponseJson.put("bank_name", "ICICI Bank"); + mockedResponseJson.put("name", "Gaurav Kumar"); + ArrayList notes = new ArrayList(); + mockedResponseJson.put("notes", notes); + mockedResponseJson.put("account_number", "XXXXXXXXXXXXXXX0434"); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + BankAccount customer = customerClient.addBankAccount(CUSTOMER_ID,request); + assertNotNull(customer); + assertEquals(BANKACCOUNT_ID,customer.get("id")); + String createRequest = getHost(String.format(Constants.ADD_BANK_ACCOUNT,CUSTOMER_ID)); + verifySentRequest(true, request.toString(), createRequest); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Delete Bank Account + */ + @Test + public void testDeleteBankAccount() throws RazorpayException { + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("id", "ba_LSZht1Cm7xFTwF"); + mockedResponseJson.put("entity", "customer"); + mockedResponseJson.put("ifsc", "ICIC0001207"); + mockedResponseJson.put("bank_name", "ICICI Bank"); + mockedResponseJson.put("name", "Gaurav Kumar"); + ArrayList notes = new ArrayList(); + mockedResponseJson.put("notes", notes); + mockedResponseJson.put("account_number", "XXXXXXXXXXXXXXX0434"); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Customer fetch = customerClient.deleteBankAccount(CUSTOMER_ID, BANKACCOUNT_ID); + assertNotNull(fetch); + assertEquals(BANKACCOUNT_ID,fetch.get("id")); + String fetchRequest = getHost(String.format(Constants.DELETE_BANK_ACCOUNT, CUSTOMER_ID, BANKACCOUNT_ID)); + verifySentRequest(false, null, fetchRequest); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Eligibility Check + */ + @Test + public void testEligibilityCheck() throws RazorpayException{ + + JSONObject request = new JSONObject(); + request.put("inquiry","affordability"); + request.put("amount", 500); + request.put("currency","INR"); + JSONObject customerParam = new JSONObject(); + customerParam.put("id","elig_xxxxxxxxxxxxx"); + customerParam.put("contact","+919999999999"); + customerParam.put("ip","105.106.107.108"); + customerParam.put("referrer","https://merchansite.com/example/paybill"); + customerParam.put("user_agent","Mozilla/5.0"); + request.put("customer",customerParam); + + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("amount", 500000); + mockedResponseJson.put("entity", "customer"); + JSONObject _customerParam = new JSONObject(); + _customerParam.put("id","KkBhM9EC1Y0HTm"); + _customerParam.put("contact","+918220722114"); + mockedResponseJson.put("customer", _customerParam); + ArrayList instrument = new ArrayList(); + JSONObject instrumentObj = new JSONObject(); + instrumentObj.put("method","emi"); + instrumentObj.put("issuer","HDFC"); + instrumentObj.put("type","debit"); + instrumentObj.put("eligibility_req_id","elig_KkCNLzlNeMYQyZ"); + JSONObject eligibilityObj = new JSONObject(); + eligibilityObj.put("status","eligible"); + instrument.add(instrumentObj); + mockedResponseJson.put("instruments", instrument); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Customer customer = customerClient.requestEligibilityCheck(request); + assertNotNull(customer); + assertEquals(true, customer.has("amount")); + assertEquals(true, customer.has("customer")); + String createRequest = getHost(Constants.ELIGIBILITY); + verifySentRequest(true, request.toString(), createRequest); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Fetch Eligibility + */ + @Test + public void testFetchEligibility() throws RazorpayException { + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("amount", 500000); + mockedResponseJson.put("entity", "customer"); + JSONObject _customerParam = new JSONObject(); + _customerParam.put("id","KkBhM9EC1Y0HTm"); + _customerParam.put("contact","+918220722114"); + mockedResponseJson.put("customer", _customerParam); + ArrayList instrument = new ArrayList(); + JSONObject instrumentObj = new JSONObject(); + instrumentObj.put("method","emi"); + instrumentObj.put("issuer","HDFC"); + instrumentObj.put("type","debit"); + instrumentObj.put("eligibility_req_id","elig_KkCNLzlNeMYQyZ"); + JSONObject eligibilityObj = new JSONObject(); + eligibilityObj.put("status","eligible"); + instrument.add(instrumentObj); + mockedResponseJson.put("instruments", instrument); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Customer fetch = customerClient.fetchEligibility(ELIGIBILITY_ID); + assertNotNull(fetch); + assertEquals(true, fetch.has("amount")); + assertEquals(true, fetch.has("customer")); + String fetchRequest = getHost(String.format(Constants.ELIGIBILITY_FETCH, ELIGIBILITY_ID)); + verifySentRequest(false, null, fetchRequest); + } catch (IOException e) { + assertTrue(false); + } + } } \ No newline at end of file From e74c3cac5693e8e9a149ad7f2e241f85b8b44043 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:32:01 +0530 Subject: [PATCH 5/8] added dispute endpoint (#309) --- documents/dispute.md | 242 ++++++++++++++++ src/main/java/com/razorpay/Constants.java | 8 +- src/main/java/com/razorpay/Dispute.java | 11 + src/main/java/com/razorpay/DisputeClient.java | 41 +++ .../java/com/razorpay/RazorpayClient.java | 3 + .../java/com/razorpay/DisputeClientTest.java | 266 ++++++++++++++++++ 6 files changed, 568 insertions(+), 3 deletions(-) create mode 100644 documents/dispute.md create mode 100644 src/main/java/com/razorpay/Dispute.java create mode 100644 src/main/java/com/razorpay/DisputeClient.java create mode 100644 src/test/java/com/razorpay/DisputeClientTest.java diff --git a/documents/dispute.md b/documents/dispute.md new file mode 100644 index 00000000..203fb7f1 --- /dev/null +++ b/documents/dispute.md @@ -0,0 +1,242 @@ +## Document + +### Fetch All Disputes + +```java +Dispute dispute = instance.dispute.fetchAll(); +``` + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "disp_Esz7KAitoYM7PJ", + "entity": "dispute", + "payment_id": "pay_EsyWjHrfzb59eR", + "amount": 10000, + "currency": "INR", + "amount_deducted": 0, + "reason_code": "pre_arbitration", + "respond_by": 1590604200, + "status": "open", + "phase": "pre_arbitration", + "created_at": 1590059211, + "evidence": { + "amount": 10000, + "summary": null, + "shipping_proof": null, + "billing_proof": null, + "cancellation_proof": null, + "customer_communication": null, + "proof_of_service": null, + "explanation_letter": null, + "refund_confirmation": null, + "access_activity_log": null, + "refund_cancellation_policy": null, + "term_and_conditions": null, + "others": null, + "submitted_at": null + } + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch a Dispute + +```java +String disputeId = "disp_0000000000000"; + +Dispute dispute = instance.dispute.fetchAll(disputeId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| disputeId* | string | The unique identifier of the dispute. | + +**Response:** +```json +{ + "id": "disp_AHfqOvkldwsbqt", + "entity": "dispute", + "payment_id": "pay_EsyWjHrfzb59eR", + "amount": 10000, + "currency": "INR", + "amount_deducted": 0, + "reason_code": "pre_arbitration", + "respond_by": 1590604200, + "status": "open", + "phase": "pre_arbitration", + "created_at": 1590059211, + "evidence": { + "amount": 10000, + "summary": "goods delivered", + "shipping_proof": null, + "billing_proof": null, + "cancellation_proof": null, + "customer_communication": null, + "proof_of_service": null, + "explanation_letter": null, + "refund_confirmation": null, + "access_activity_log": null, + "refund_cancellation_policy": null, + "term_and_conditions": null, + "others": null, + "submitted_at": null + } +} +``` +------------------------------------------------------------------------------------------------------- +### Contest a Dispute + +```java +// Use this API sample code for draft + +String disputeId = "disp_0000000000000"; + +JSONObject disputeRequest = new JSONObject(); +disputeRequest.put("amount",5000); +disputeRequest.put("summary","goods delivered"); +List shipping_proof = new ArrayList<>(); +shipping_proof.add("doc_EFtmUsbwpXwBH9") +shipping_proof.add("doc_EFtmUsbwpXwBH8") +disputeRequest.put("shipping_proof", shipping_proof); +List others = new ArrayList<>(); +JSONObject otherParam = new JSONObject(); +otherParam.put("type","receipt_signed_by_customer"); +List doc = new ArrayList<>(); +doc.add("doc_EFtmUsbwpXwBH1"); +doc.add("doc_EFtmUsbwpXwBH7"); +otherParam.put("document_ids",doc); +others.add(otherParam) +disputeRequest.put("others", others); +disputeRequest.put("action", "submit"); + +Dispute dispute = instance.dispute.contest(disputeId, disputeRequest) +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| disputeId* | string | The unique identifier of the dispute. | +| amount | integer | The amount being contested. If the contest amount is not mentioned, we will assume it to be a full dispute contest. | +| summary | string | The explanation provided by you for contesting the dispute. It can have a maximum length of 1000 characters. | +| shipping_proof | array | List of document ids which serves as proof that the product was shipped to the customer at their provided address. It should show their complete shipping address, if possible. | +| others | array | All keys listed [here](https://razorpay.com/docs/api/disputes/contest) are supported | + +```java +// Use this API sample code for submit + +String disputeId = "disp_0000000000000"; + +JSONObject disputeRequest = new JSONObject(); +List billing_proof = new ArrayList<>(); +billing_proof.add("doc_EFtmUsbwpXwBH9") +billing_proof.add("doc_EFtmUsbwpXwBH8") +disputeRequest.put("billing_proof", billing_proof); +disputeRequest.put("action", "submit"); + +Dispute dispute = instance.dispute.contest(disputeId, disputeRequest) +``` + +**Response:** +```json +// Draft +{ + "id": "disp_AHfqOvkldwsbqt", + "entity": "dispute", + "payment_id": "pay_EsyWjHrfzb59eR", + "amount": 10000, + "currency": "INR", + "amount_deducted": 0, + "reason_code": "chargeback", + "respond_by": 1590604200, + "status": "open", + "phase": "chargeback", + "created_at": 1590059211, + "evidence": { + "amount": 5000, + "summary": "goods delivered", + "shipping_proof": [ + "doc_EFtmUsbwpXwBH9", + "doc_EFtmUsbwpXwBH8" + ], + "billing_proof": null, + "cancellation_proof": null, + "customer_communication": null, + "proof_of_service": null, + "explanation_letter": null, + "refund_confirmation": null, + "access_activity_log": null, + "refund_cancellation_policy": null, + "term_and_conditions": null, + "others": [ + { + "type": "receipt_signed_by_customer", + "document_ids": [ + "doc_EFtmUsbwpXwBH1", + "doc_EFtmUsbwpXwBH7" + ] + } + ], + "submitted_at": null + } +} + +//Submit +{ + "id": "disp_AHfqOvkldwsbqt", + "entity": "dispute", + "payment_id": "pay_EsyWjHrfzb59eR", + "amount": 10000, + "currency": "INR", + "amount_deducted": 0, + "reason_code": "chargeback", + "respond_by": 1590604200, + "status": "under_review", + "phase": "chargeback", + "created_at": 1590059211, + "evidence": { + "amount": 5000, + "summary": "goods delivered", + "shipping_proof": [ + "doc_EFtmUsbwpXwBH9", + "doc_EFtmUsbwpXwBH8" + ], + "billing_proof": [ + "doc_EFtmUsbwpXwBG9", + "doc_EFtmUsbwpXwBG8" + ], + "cancellation_proof": null, + "customer_communication": null, + "proof_of_service": null, + "explanation_letter": null, + "refund_confirmation": null, + "access_activity_log": null, + "refund_cancellation_policy": null, + "term_and_conditions": null, + "others": [ + { + "type": "receipt_signed_by_customer", + "document_ids": [ + "doc_EFtmUsbwpXwBH1", + "doc_EFtmUsbwpXwBH7" + ] + } + ], + "submitted_at": 1590603200 + } +} +``` +------------------------------------------------------------------------------------------------------- +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/documents)** \ No newline at end of file diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 8a6a7fc2..9ffe26ab 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -170,11 +170,13 @@ public class Constants { static final String TOKEN = "/token"; static final String REVOKE = "/revoke"; - static final String ADD_BANK_ACCOUNT = "customers/%s/bank_account"; + static final String DISPUTE = "/disputes"; + static final String DISPUTE_FETCH = "/disputes/%s"; + static final String DISPUTE_ACCEPT = "/disputes/%s/accept"; + static final String DISPUTE_CONTEST = "/disputes/%s/contest"; + static final String ADD_BANK_ACCOUNT = "customers/%s/bank_account"; static final String DELETE_BANK_ACCOUNT = "customers/%s/bank_account/%s"; - static final String ELIGIBILITY = "customers/eligibility"; - static final String ELIGIBILITY_FETCH = "customers/eligibility/%s"; } diff --git a/src/main/java/com/razorpay/Dispute.java b/src/main/java/com/razorpay/Dispute.java new file mode 100644 index 00000000..0742a0a5 --- /dev/null +++ b/src/main/java/com/razorpay/Dispute.java @@ -0,0 +1,11 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class Dispute extends Entity { + + public Dispute(JSONObject jsonObject) { + super(jsonObject); + } +} + diff --git a/src/main/java/com/razorpay/DisputeClient.java b/src/main/java/com/razorpay/DisputeClient.java new file mode 100644 index 00000000..07c4abe5 --- /dev/null +++ b/src/main/java/com/razorpay/DisputeClient.java @@ -0,0 +1,41 @@ +package com.razorpay; + +import java.util.List; + +import org.json.JSONObject; + +public class DisputeClient extends ApiClient { + + DisputeClient(String auth) { + super(auth); + } + + public Dispute fetch(String id) throws RazorpayException { + return get(Constants.VERSION, String.format(Constants.DISPUTE_FETCH, id), null); + } + + /** + * It is wrapper of fetchAll with parameter here sending null defines fetchAll + * with a default values without filteration + * @throws RazorpayException + */ + public List fetchAll() throws RazorpayException { + return fetchAll(null); + } + + /** + * This method get list of disputes filtered by parameters @request + * @throws RazorpayException + */ + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.VERSION, Constants.DISPUTE, request); + } + + public Dispute accept(String id) throws RazorpayException { + return post(Constants.VERSION, String.format(Constants.DISPUTE_ACCEPT, id), null); + } + + public Dispute contest(String id, JSONObject request) throws RazorpayException { + return patch(Constants.VERSION, String.format(Constants.DISPUTE_CONTEST, id), request); + } +} diff --git a/src/main/java/com/razorpay/RazorpayClient.java b/src/main/java/com/razorpay/RazorpayClient.java index 9f5e33d7..4eaeeeb1 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -28,6 +28,8 @@ public class RazorpayClient { public StakeholderClient stakeholder; public ProductClient product; public WebhookClient webhook; + + public DisputeClient dispute; public TncMap tncMap; public BankAccountClient bankAccount; public RazorpayClient(String key, String secret) throws RazorpayException { @@ -67,6 +69,7 @@ private void initializeResources(String auth, Boolean enableLogging) throws Razo stakeholder = new StakeholderClient(auth); product = new ProductClient(auth); webhook = new WebhookClient(auth); + dispute = new DisputeClient(auth); bankAccount = new BankAccountClient(auth); } diff --git a/src/test/java/com/razorpay/DisputeClientTest.java b/src/test/java/com/razorpay/DisputeClientTest.java new file mode 100644 index 00000000..4d7abd81 --- /dev/null +++ b/src/test/java/com/razorpay/DisputeClientTest.java @@ -0,0 +1,266 @@ +package com.razorpay; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import static org.junit.Assert.*; + +public class DisputeClientTest extends BaseTest{ + + @InjectMocks + protected DisputeClient disputeClient = new DisputeClient(TEST_SECRET_KEY); + + private static final String DISPUTE_ID = "disp_AHfqOvkldwsbqt"; + + /** + * Contest a Dispute using dispute id. + * @throws RazorpayException + */ + @Test + public void TestContest() throws RazorpayException{ + + JSONObject request = new JSONObject(); + request.put("amount",5000); + request.put("summary","goods delivered"); + List shipping_proof = new ArrayList<>(); + shipping_proof.add("doc_EFtmUsbwpXwBH9"); + shipping_proof.add("doc_EFtmUsbwpXwBH8"); + request.put("shipping_proof", shipping_proof); + List others = new ArrayList<>(); + JSONObject otherParam = new JSONObject(); + otherParam.put("type","receipt_signed_by_customer"); + List doc = new ArrayList<>(); + doc.add("doc_EFtmUsbwpXwBH1"); + doc.add("doc_EFtmUsbwpXwBH7"); + otherParam.put("document_ids",doc); + others.add(otherParam); + request.put("others", others); + request.put("action", "submit"); + + JSONObject mockedResponseJson = new JSONObject(); + + mockedResponseJson.put("id", "disp_AHfqOvkldwsbqt"); + mockedResponseJson.put("amount", 5000); + mockedResponseJson.put("entity", "dispute"); + mockedResponseJson.put("summary", "goods delivered"); + + JSONArray shippingProofArray = new JSONArray(); + shippingProofArray.put("doc_EFtmUsbwpXwBH9"); + shippingProofArray.put("doc_EFtmUsbwpXwBH8"); + mockedResponseJson.put("shipping_proof", shippingProofArray); + + mockedResponseJson.put("billing_proof", JSONObject.NULL); + mockedResponseJson.put("cancellation_proof", JSONObject.NULL); + mockedResponseJson.put("customer_communication", JSONObject.NULL); + mockedResponseJson.put("proof_of_service", JSONObject.NULL); + mockedResponseJson.put("explanation_letter", JSONObject.NULL); + mockedResponseJson.put("refund_confirmation", JSONObject.NULL); + mockedResponseJson.put("access_activity_log", JSONObject.NULL); + mockedResponseJson.put("refund_cancellation_policy", JSONObject.NULL); + mockedResponseJson.put("term_and_conditions", JSONObject.NULL); + + JSONArray othersArray = new JSONArray(); + JSONObject othersObject = new JSONObject(); + othersObject.put("type", "receipt_signed_by_customer"); + JSONArray documentIdsArray = new JSONArray(); + documentIdsArray.put("doc_EFtmUsbwpXwBH1"); + documentIdsArray.put("doc_EFtmUsbwpXwBH7"); + othersObject.put("document_ids", documentIdsArray); + othersArray.put(othersObject); + mockedResponseJson.put("others", othersArray); + + mockedResponseJson.put("submitted_at", JSONObject.NULL); + + JSONObject evidenceObject = new JSONObject(); + evidenceObject.put("amount", 5000); + evidenceObject.put("summary", "goods delivered"); + evidenceObject.put("shipping_proof", shippingProofArray); + evidenceObject.put("billing_proof", JSONObject.NULL); + evidenceObject.put("cancellation_proof", JSONObject.NULL); + evidenceObject.put("customer_communication", JSONObject.NULL); + evidenceObject.put("proof_of_service", JSONObject.NULL); + evidenceObject.put("explanation_letter", JSONObject.NULL); + evidenceObject.put("refund_confirmation", JSONObject.NULL); + evidenceObject.put("access_activity_log", JSONObject.NULL); + evidenceObject.put("refund_cancellation_policy", JSONObject.NULL); + evidenceObject.put("term_and_conditions", JSONObject.NULL); + evidenceObject.put("others", othersArray); + evidenceObject.put("submitted_at", JSONObject.NULL); + mockedResponseJson.put("evidence", evidenceObject); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Dispute dispute = disputeClient.contest(DISPUTE_ID,request); + assertNotNull(dispute); + assertEquals(DISPUTE_ID,dispute.get("id")); + String createRequest = getHost(String.format(Constants.DISPUTE_CONTEST, DISPUTE_ID)); + verifySentRequest(true, request.toString(), createRequest); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Accept a dispute using dispute id. + * @throws RazorpayException + */ + @Test + public void TestAccept() throws RazorpayException { + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("id", "disp_AHfqOvkldwsbqt"); + mockedResponseJson.put("entity", "dispute"); + mockedResponseJson.put("payment_id", "pay_EsyWjHrfzb59eR"); + mockedResponseJson.put("amount", 10000); + mockedResponseJson.put("currency", "INR"); + mockedResponseJson.put("amount_deducted", 10000); + mockedResponseJson.put("reason_code", "pre_arbitration"); + mockedResponseJson.put("respond_by", 1590604200); + mockedResponseJson.put("status", "lost"); + mockedResponseJson.put("phase", "pre_arbitration"); + mockedResponseJson.put("created_at", 1590059211); + + JSONObject evidenceObject = new JSONObject(); + evidenceObject.put("amount", 5000); + evidenceObject.put("summary", JSONObject.NULL); + evidenceObject.put("shipping_proof", JSONObject.NULL); + evidenceObject.put("billing_proof", JSONObject.NULL); + evidenceObject.put("cancellation_proof", JSONObject.NULL); + evidenceObject.put("customer_communication", JSONObject.NULL); + evidenceObject.put("proof_of_service", JSONObject.NULL); + evidenceObject.put("explanation_letter", JSONObject.NULL); + evidenceObject.put("refund_confirmation", JSONObject.NULL); + evidenceObject.put("access_activity_log", JSONObject.NULL); + evidenceObject.put("refund_cancellation_policy", JSONObject.NULL); + evidenceObject.put("term_and_conditions", JSONObject.NULL); + evidenceObject.put("others", JSONObject.NULL); + evidenceObject.put("submitted_at", JSONObject.NULL); + mockedResponseJson.put("evidence", evidenceObject); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Dispute fetch = disputeClient.accept(DISPUTE_ID); + assertNotNull(fetch); + assertEquals(DISPUTE_ID,fetch.get("id")); + String fetchRequest = getHost(String.format(Constants.DISPUTE_ACCEPT, DISPUTE_ID)); + verifySentRequest(false, null, fetchRequest); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Fetch all disputes + * @throws RazorpayException + */ + @Test + public void TestfetchAll() throws RazorpayException { + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("entity", "collection"); + mockedResponseJson.put("count", 1); + + JSONArray disputeArray = new JSONArray(); + + JSONObject disputeObj = new JSONObject(); + disputeObj.put("id", "disp_AHfqOvkldwsbqt"); + disputeObj.put("entity", "dispute"); + disputeObj.put("payment_id", "pay_EsyWjHrfzb59eR"); + disputeObj.put("amount", 10000); + disputeObj.put("currency", "INR"); + disputeObj.put("amount_deducted", 10000); + disputeObj.put("reason_code", "pre_arbitration"); + disputeObj.put("respond_by", 1590604200); + disputeObj.put("status", "lost"); + disputeObj.put("phase", "pre_arbitration"); + disputeObj.put("created_at", 1590059211); + + JSONObject evidenceObject = new JSONObject(); + evidenceObject.put("amount", 5000); + evidenceObject.put("summary", JSONObject.NULL); + evidenceObject.put("shipping_proof", JSONObject.NULL); + evidenceObject.put("billing_proof", JSONObject.NULL); + evidenceObject.put("cancellation_proof", JSONObject.NULL); + evidenceObject.put("customer_communication", JSONObject.NULL); + evidenceObject.put("proof_of_service", JSONObject.NULL); + evidenceObject.put("explanation_letter", JSONObject.NULL); + evidenceObject.put("refund_confirmation", JSONObject.NULL); + evidenceObject.put("access_activity_log", JSONObject.NULL); + evidenceObject.put("refund_cancellation_policy", JSONObject.NULL); + evidenceObject.put("term_and_conditions", JSONObject.NULL); + evidenceObject.put("others", JSONObject.NULL); + evidenceObject.put("submitted_at", JSONObject.NULL); + disputeObj.put("evidence", evidenceObject); + + disputeArray.put(disputeObj); + + mockedResponseJson.put("items", disputeArray); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = disputeClient.fetchAll(); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("id")); + String fetchRequest = getHost(Constants.DISPUTE); + verifySentRequest(false, null, fetchRequest); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Fetch Disputes + * @throws RazorpayException + */ + @Test + public void testFetch() throws IOException, RazorpayException { + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("id", "disp_AHfqOvkldwsbqt"); + mockedResponseJson.put("entity", "dispute"); + mockedResponseJson.put("payment_id", "pay_EsyWjHrfzb59eR"); + mockedResponseJson.put("amount", 10000); + mockedResponseJson.put("currency", "INR"); + mockedResponseJson.put("amount_deducted", 10000); + mockedResponseJson.put("reason_code", "pre_arbitration"); + mockedResponseJson.put("respond_by", 1590604200); + mockedResponseJson.put("status", "lost"); + mockedResponseJson.put("phase", "pre_arbitration"); + mockedResponseJson.put("created_at", 1590059211); + + JSONObject evidenceObject = new JSONObject(); + evidenceObject.put("amount", 5000); + evidenceObject.put("summary", JSONObject.NULL); + evidenceObject.put("shipping_proof", JSONObject.NULL); + evidenceObject.put("billing_proof", JSONObject.NULL); + evidenceObject.put("cancellation_proof", JSONObject.NULL); + evidenceObject.put("customer_communication", JSONObject.NULL); + evidenceObject.put("proof_of_service", JSONObject.NULL); + evidenceObject.put("explanation_letter", JSONObject.NULL); + evidenceObject.put("refund_confirmation", JSONObject.NULL); + evidenceObject.put("access_activity_log", JSONObject.NULL); + evidenceObject.put("refund_cancellation_policy", JSONObject.NULL); + evidenceObject.put("term_and_conditions", JSONObject.NULL); + evidenceObject.put("others", JSONObject.NULL); + evidenceObject.put("submitted_at", JSONObject.NULL); + mockedResponseJson.put("evidence", evidenceObject); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Dispute dispute = disputeClient.fetch(DISPUTE_ID); + assertNotNull(dispute); + assertEquals(DISPUTE_ID,dispute.get("id")); + verifySentRequest(false, null, getHost(String.format(Constants.DISPUTE_FETCH,DISPUTE_ID))); + } catch (IOException e) { + assertTrue(false); + } + } +} \ No newline at end of file From 6994748632027670388535ba254c9f7d64f3a4bd Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:52:20 +0530 Subject: [PATCH 6/8] added expanded details methods (#312) --- documents/payment.md | 257 ++++++++++++++++++ src/main/java/com/razorpay/PaymentClient.java | 3 + .../java/com/razorpay/PaymentClientTest.java | 65 +++++ 3 files changed, 325 insertions(+) diff --git a/documents/payment.md b/documents/payment.md index 28148e5a..e8373e47 100644 --- a/documents/payment.md +++ b/documents/payment.md @@ -826,6 +826,263 @@ Iin token = instance.iin.fetch(tokenIin); ] } ``` +------------------------------------------------------------------------------------------------------- + +### Fetch a Payment (With Expanded EMI Details) + +```java +JSONObject request = new JSONObject(); +request.put("expand[]","emi"); + +Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|------------------------------------------------------------------| +| paymentId* | integer | Unique identifier of the payment | +| expand[] | string | Use to expand the `emi` details when the payment method is emi. | + +**Response:**
+ +```json +{ + "id": "pay_DG4ZdRK8ZnXC3k", + "entity": "payment", + "amount": 200000, + "currency": "INR", + "status": "authorized", + "order_id": null, + "invoice_id": null, + "international": false, + "method": "emi", + "amount_refunded": 0, + "refund_status": null, + "captured": false, + "description": null, + "card_id": "card_DG4ZdUO3xABb20", + "bank": "ICIC", + "wallet": null, + "vpa": null, + "email": "gaurav@example.com", + "contact": "+919972000005", + "notes": [], + "fee": null, + "tax": null, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "emi": { + "issuer": "ICIC", + "rate": 1300, + "duration": 6 + }, + "acquirer_data": { + "auth_code": "828553" + }, + "created_at": 1568026077 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch a Payment (With Expanded Card Details) + +```java +JSONObject request = new JSONObject(); +request.put("expand[]","card"); + +Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|---------------------------------------------------------------------| +| paymentId* | integer | Unique identifier of the payment | +| expand[] | string | Use to expand the card details when the payment method is `card`. | + +**Response:**
+ +```json +{ + "id": "pay_H9oR0gLCaVlV6m", + "entity": "payment", + "amount": 100, + "currency": "INR", + "status": "failed", + "order_id": "order_H9o58N6qmLYQKC", + "invoice_id": null, + "terminal_id": "term_G5kJnYM9GhhLYT", + "international": false, + "method": "card", + "amount_refunded": 0, + "refund_status": null, + "captured": false, + "description": null, + "card_id": "card_H9oR0ocen1cmZq", + "card": { + "id": "card_H9oR0ocen1cmZq", + "entity": "card", + "name": "Gaurav", + "last4": "1213", + "network": "RuPay", + "type": "credit", + "issuer": "UTIB", + "international": false, + "emi": false, + "sub_type": "business" + }, + "bank": null, + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "+919000090000", + "notes": { + "email": "gaurav.kumar@example.com", + "phone": "09000090000" + }, + "fee": null, + "tax": null, + "error_code": "BAD_REQUEST_ERROR", + "error_description": "Card issuer is invalid", + "error_source": "customer", + "error_step": "payment_authentication", + "error_reason": "incorrect_card_details", + "acquirer_data": { + "auth_code": null, + "authentication_reference_number": "100222021120200000000742753928" + }, + "created_at": 1620807547 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch a Payment (With Expanded Offers Details) + +```java +JSONObject request = new JSONObject(); +request.put("expand[]","offers"); + +Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|----------------------------------------------------------------| +| paymentId* | integer | Unique identifier of the payment | +| expand[] | string | Use to expand the emi details when the payment method is emi. | + +**Response:**
+ +```json +{ + "id": "pay_DG4ZdRK8ZnXC3k", + "entity": "payment", + "amount": 200000, + "currency": "INR", + "status": "authorized", + "order_id": null, + "invoice_id": null, + "international": false, + "method": "emi", + "amount_refunded": 0, + "refund_status": null, + "captured": false, + "description": null, + "card_id": "card_DG4ZdUO3xABb20", + "bank": "ICIC", + "wallet": null, + "vpa": null, + "email": "gaurav@example.com", + "contact": "+919972000005", + "notes": [], + "fee": null, + "tax": null, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "emi": { + "issuer": "ICIC", + "rate": 1300, + "duration": 6 + }, + "acquirer_data": { + "auth_code": "828553" + }, + "created_at": 1568026077 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch a Payment (With Expanded UPI Details) + +```java +JSONObject request = new JSONObject(); +request.put("expand[]","upi"); + +Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|--------------------------------------------------------------| +| paymentId* | integer | Unique identifier of the payment | +| expand[] | string | Use to expand the UPI details when the payment method is upi. | + +**Response:**
+ +```json +{ + "id": "pay_DG4ZdRK8ZnXC3k", + "entity": "payment", + "amount": 100, + "currency": "INR", + "status": "captured", + "order_id": "order_GjCr5oKh4AVC51", + "invoice_id": null, + "international": false, + "method": "upi", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "Payment for Adidas shoes", + "card_id": null, + "bank": null, + "wallet": null, + "vpa": "gaurav.kumar@upi", + "email": "gaurav.kumar@example.com", + "contact": "9000090000", + "customer_id": "cust_K6fNE0WJZWGqtN", + "token_id": "token_KOdY$DBYQOv08n", + "notes": [], + "fee": 1, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "rrn": "303107535132" + }, + "created_at": 1605871409, + "upi": { + "payer_account_type": "credit_card", + "vpa": "gaurav.kumar@upi", + "flow": "in_app" // appears only for Turbo UPI Payments. + } +} +``` + ------------------------------------------------------------------------------------------------------- **PN: * indicates mandatory fields**
diff --git a/src/main/java/com/razorpay/PaymentClient.java b/src/main/java/com/razorpay/PaymentClient.java index 92e0f502..1da3811f 100755 --- a/src/main/java/com/razorpay/PaymentClient.java +++ b/src/main/java/com/razorpay/PaymentClient.java @@ -119,4 +119,7 @@ public Payment validateUpi(JSONObject request) throws RazorpayException { return post(Constants.VERSION, Constants.VALIDATE_VPA, request); } + public Payment expandedDetails(String id, JSONObject request) throws RazorpayException { + return get(Constants.VERSION, String.format(Constants.PAYMENT_GET, id), request); + } } diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java index a133f6ec..0fdd24df 100644 --- a/src/test/java/com/razorpay/PaymentClientTest.java +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -934,4 +934,69 @@ public void fetchAllRefund() throws RazorpayException { assertTrue(false); } } + + @Test + public void expandedDetails() throws RazorpayException { + JSONObject request = new JSONObject(); + request.put("expand[]","payments"); + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("id","pay_IDRP0tbirMSsbn"); + mockedResponseJson.put("entity","payment"); + mockedResponseJson.put("amount",100); + mockedResponseJson.put("currency","INR"); + mockedResponseJson.put("status","failed"); + mockedResponseJson.put("order_id","order_H9o58N6qmLYQKC"); + mockedResponseJson.put("invoice_id", JSONObject.NULL); + mockedResponseJson.put("terminal_id","term_G5kJnYM9GhhLYT"); + mockedResponseJson.put("international",false); + mockedResponseJson.put("method","card"); + mockedResponseJson.put("amount_refunded",JSONObject.NULL); + mockedResponseJson.put("captured",false); + mockedResponseJson.put("description",JSONObject.NULL); + mockedResponseJson.put("card_id","card_H9oR0ocen1cmZq"); + JSONObject cardObj = new JSONObject(); + cardObj.put("id",""); + cardObj.put("entity","card"); + cardObj.put("name","Gaurav"); + cardObj.put("last4","1213"); + cardObj.put("network","RuPay"); + cardObj.put("type", "credit"); + cardObj.put("issuer","UTIB"); + cardObj.put("international", false); + cardObj.put("emi", false); + cardObj.put("sub_type","business"); + mockedResponseJson.put("card",cardObj); + mockedResponseJson.put("bank",JSONObject.NULL); + mockedResponseJson.put("wallet",JSONObject.NULL); + mockedResponseJson.put("vpa",JSONObject.NULL); + mockedResponseJson.put("email","gaurav.kumar@example.com"); + mockedResponseJson.put("contact","+919000090000"); + JSONObject notesObj = new JSONObject(); + notesObj.put("key1",""); + notesObj.put("key2",""); + mockedResponseJson.put("notes",notesObj); + mockedResponseJson.put("fee",JSONObject.NULL); + mockedResponseJson.put("tax",JSONObject.NULL); + mockedResponseJson.put("error_code","BAD_REQUEST_ERROR"); + mockedResponseJson.put("error_description","Card issuer is invalid"); + mockedResponseJson.put("error_source","customer"); + mockedResponseJson.put("error_step","payment_authentication"); + mockedResponseJson.put("error_reason","incorrect_card_details"); + JSONObject acquirerDataObj = new JSONObject(); + acquirerDataObj.put("auth_code",JSONObject.NULL); + acquirerDataObj.put("authentication_reference_number","100222021120200000000742753928"); + mockedResponseJson.put("acquirer_data",acquirerDataObj); + mockedResponseJson.put("created_at",1620807547); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Payment fetch = paymentClient.expandedDetails(PAYMENT_ID, request); + assertNotNull(fetch); + assertEquals(PAYMENT_ID,fetch.get("id")); + } catch (IOException e) { + assertTrue(false); + } + } } \ No newline at end of file From d899315cc437a16fbe2c7b59dcf6bcbf161bc155 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Mon, 1 Apr 2024 18:03:34 +0530 Subject: [PATCH 7/8] updated order class (#314) --- 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 | 75 +++++++++++++++++++ 4 files changed, 157 insertions(+) diff --git a/documents/order.md b/documents/order.md index 03eeb01e..a060b19e 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 9ffe26ab..93cf6abe 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -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"; 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..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; @@ -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); + } + } } \ No newline at end of file From 16faf4baa2866281cbb0a263d1fc9d310ed60a68 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Mon, 1 Apr 2024 18:15:11 +0530 Subject: [PATCH 8/8] Updated stakeholder endpoints (#318) --- documents/stakeholder.md | 62 +++++++++++++++++++ src/main/java/com/razorpay/Constants.java | 2 + .../java/com/razorpay/StakeholderClient.java | 8 +++ .../com/razorpay/StakeholderClientTest.java | 50 +++++++++++++++ 4 files changed, 122 insertions(+) diff --git a/documents/stakeholder.md b/documents/stakeholder.md index ba1512db..9790364b 100644 --- a/documents/stakeholder.md +++ b/documents/stakeholder.md @@ -293,6 +293,68 @@ Stakeholder stakeholder = instance.stakeholder.fetch(accountId, stakeholderId); } ``` +------------------------------------------------------------------------------------------------------- +### Upload stakeholders documents +```java +String accoundId = "acc_LryDIBIjBDbOWy"; +String stakeholderId = "sth_M0zjeiVOLRJRPW"; + +JSONObject request = new JSONObject(); +request.put("file","/Users/your_name/Downloads/sample_uploaded.jpeg"); +request.put("document_type","aadhar_front"); + +Stakeholder stakeholder = instance.stakeholder.uploadStakeholderDoc(accoundId, stakeholderId, request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| accountId* | string | The unique identifier of a sub-merchant account generated by Razorpay. | +| stakeholderId* | string | The unique identifier of the stakeholder whose details are to be fetched. | +| file* | string | The URL generated once the business proof document is uploaded. | +| document_type* | string | The documents valid for the proof type to be shared. In case of individual_proof_of_address, both the front and back of a document proof must be uploaded. Possible values :
individual_proof_of_identification: `personal_pan`

individual_proof_of_address : `voter_id_back`, `voter_id_front`, `aadhar_front`, `aadhar_back`, `passport_front`, `passport_back` | + +**Response:** +```json +{ + "individual_proof_of_address": [ + { + "type": "aadhar_front", + "url": "https://rzp.io/i/bzDAbNg" + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch stakeholders documents +```java + +String accoundId = "acc_LryDIBIjBDbOWy"; +String stakeholderId = "sth_M0zjeiVOLRJRPW"; + +Stakeholder stakeholder = instance.stakeholder.fetchStakeholderDoc(accoundId, stakeholderId); +``` + +**Parameters:** + +| Name | Type | Description | +|----------------|-------------|---------------------------------------------------------------------------| +| accountId* | string | The unique identifier of a sub-merchant account generated by Razorpay. | +| stakeholderId* | string | The unique identifier of the stakeholder whose details are to be fetched. | + +**Response:** +```json +{ + "business_proof_of_identification": [ + { + "type": "business_proof_url", + "url": "" + } + ] +} +``` ------------------------------------------------------------------------------------------------------- **PN: * indicates mandatory fields** diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 5bcde0cc..dbbf8b77 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -173,4 +173,6 @@ public class Constants { static final String DOCUMENTS = "/documents"; static final String DOCUMENT_FETCH = "/documents/%s"; + + static final String UPLOAD_STAKEHOLDER_DOCUMENT = "accounts/%s/stakeholders/%s/documents"; } diff --git a/src/main/java/com/razorpay/StakeholderClient.java b/src/main/java/com/razorpay/StakeholderClient.java index a72e8c46..d7c81d59 100644 --- a/src/main/java/com/razorpay/StakeholderClient.java +++ b/src/main/java/com/razorpay/StakeholderClient.java @@ -25,4 +25,12 @@ public List fetchAll(String id) throws RazorpayException { public Stakeholder edit(String id, String stakeholder_id, JSONObject request) throws RazorpayException { return patch(Constants.VERSION_V2, String.format(Constants.STAKEHOLDER_FETCH, id, stakeholder_id), request); } + + public Account uploadStakeholderDoc(String id, String stakeholder_id, JSONObject request) throws RazorpayException { + return post(Constants.VERSION_V2, String.format(Constants.UPLOAD_STAKEHOLDER_DOCUMENT, id, stakeholder_id), request); + } + + public Account fetchStakeholderDoc(String id, String stakeholder_id) throws RazorpayException { + return get(Constants.VERSION_V2, String.format(Constants.UPLOAD_STAKEHOLDER_DOCUMENT, id, stakeholder_id), null); + } } diff --git a/src/test/java/com/razorpay/StakeholderClientTest.java b/src/test/java/com/razorpay/StakeholderClientTest.java index 46e4b2d3..c2758a63 100644 --- a/src/test/java/com/razorpay/StakeholderClientTest.java +++ b/src/test/java/com/razorpay/StakeholderClientTest.java @@ -1,5 +1,6 @@ package com.razorpay; +import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; import org.mockito.InjectMocks; @@ -200,4 +201,53 @@ private String getResponseCollection(){ " \"count\": 1\n" + "}"; } + + @Test + public void testuploadStakeholderDoc() throws RazorpayException { + JSONObject request = new JSONObject(); + request.put("files","/Users/your_name/Downloads/sample_uploaded.jpeg"); + request.put("document_type","aadhar_front"); + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("entity", "account"); + JSONArray addressArray = new JSONArray(); + JSONObject addressObj = new JSONObject(); + addressObj.put("type","aadhar_front"); + addressObj.put("url","https://rzp.io/i/bzDAbNg"); + addressArray.put(addressObj); + mockedResponseJson.put("individual_proof_of_address", addressArray); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Account document = stakeholderClient.uploadStakeholderDoc(ACCOUNT_ID, STAKEHOLDER_ID, request); + assertNotNull(document); + assertEquals(true,document.has("individual_proof_of_address")); + } catch (IOException e) { + assertTrue(false); + } + } + + @Test + public void testfetchStakeholderDoc() throws RazorpayException { + + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("entity", "account"); + JSONArray addressArray = new JSONArray(); + JSONObject addressObj = new JSONObject(); + addressObj.put("type","aadhar_front"); + addressObj.put("url","https://rzp.io/i/bzDAbNg"); + addressArray.put(addressObj); + mockedResponseJson.put("individual_proof_of_address", addressArray); + + try { + mockResponseFromExternalClient(mockedResponseJson.toString()); + mockResponseHTTPCodeFromExternalClient(200); + Account document = stakeholderClient.fetchStakeholderDoc(ACCOUNT_ID, STAKEHOLDER_ID); + assertNotNull(document); + assertEquals(true,document.has("individual_proof_of_address")); + } catch (IOException e) { + assertTrue(false); + } + } }