Skip to content

Commit

Permalink
Added document endpoint (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored Apr 1, 2024
1 parent d899315 commit 779d137
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 2 deletions.
57 changes: 57 additions & 0 deletions documents/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,63 @@ Account account = instance.account.fetch(accountId);

-------------------------------------------------------------------------------------------------------

### Upload account documents
```java
String accountId = "acc_M83Uw27KXuC7c8";

JSONObject request = new JSONObject();
request.put("files","/Users/your_name/Downloads/sample_uploaded.jpeg");
request.put("document_type","business_proof_url");

Account account = instance.account.uploadAccountDoc(accountId, request);
```

**Parameters:**

| Name | Type | Description |
|----------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| accountId* | string | The unique identifier of a sub-merchant account generated by Razorpay. |
| 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. Possible values : <br> business_proof_of_identification: `shop_establishment_certificate`, `gst_certificate`, `msme_certificate`, `business_proof_url`, `business_pan_url`, <br><br> additional_documents : `form_12_a_url`, `form_80g_url`, `cancelled_cheque` |

**Response:**
```json
{
"business_proof_of_identification": [
{
"type": "business_proof_url",
"url": "<https://rzp.io/i/bzDKbNg>"
}
]
}
```
-------------------------------------------------------------------------------------------------------

### Fetch account documents
```java
String accountId = "acc_LryDIBIjBDbOWy";

Account account = instance.account.fetchAccountDoc(accountId);
```

**Parameters:**

| Name | Type | Description |
|-------------|-------------|------------------------------------------------------------------------|
| accountId* | string | The unique identifier of a sub-merchant account generated by Razorpay. |

**Response:**
```json
{
"business_proof_of_identification": [
{
"type": "business_proof_url",
"url": "<https://rzp.io/i/bzDKbNg>"
}
]
}
```
-------------------------------------------------------------------------------------------------------
**PN: * indicates mandatory fields**
<br>
<br>
Expand Down
66 changes: 66 additions & 0 deletions documents/document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Document

### Create a Document

```java
JSONObject request = new JSONObject();
request.put("file","/Users/your_name/Downloads/sample_uploaded.jpeg");
request.put("purpose","dispute_evidence");

Document document = instance.document.create(request);
```

**Parameters:**

| Name | Type | Description |
|----------|-----------|-----------------------------------------------------------------|
| file* | string | The URL generated once the business proof document is uploaded. |
| purpose | string | Possible value is `dispute_evidence` |

**Response:**
```json
{
"id": "doc_EsyWjHrfzb59Re",
"entity": "document",
"purpose": "dispute_evidence",
"name": "doc_19_12_2020.jpg",
"mime_type": "image/png",
"size": 2863,
"created_at": 1590604200
}
```
-------------------------------------------------------------------------------------------------------

### Fetch Document Information

```java
String documentId = "doc_EsyWjHrfzb59Re";

Document document = instance.document.fetch(documentId);
```

**Parameters:**

| Name | Type | Description |
|-------------|--------|--------------------------------------------------|
| documentId | string | The unique identifier of the document. |

**Response:**
```json
{
"entity": "document",
"id": "doc_00000000000000",
"purpose": "dispute_evidence",
"created_at": 1701701378,
"mime_type": "application/pdf",
"display_name": "ppm_00000000000000",
"size": 404678,
"url": ""
}
```
-------------------------------------------------------------------------------------------------------

**PN: * indicates mandatory fields**
<br>
<br>
**For reference click [here](https://razorpay.com/docs/api/documents)**
62 changes: 62 additions & 0 deletions documents/stakeholder.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 : <br> individual_proof_of_identification: `personal_pan` <br><br> 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": "<https://rzp.io/i/bzDKbNg>"
}
]
}
```
-------------------------------------------------------------------------------------------------------

**PN: * indicates mandatory fields**
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/razorpay/AccountClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ public Account edit(String id, JSONObject request) throws RazorpayException {
public Account delete(String id) throws RazorpayException {
return delete(Constants.VERSION_V2, String.format(Constants.ACCOUNT_DELETE, id), null);
}

public Account uploadAccountDoc(String id, JSONObject request) throws RazorpayException {
return post(Constants.VERSION_V2, String.format(Constants.UPLOAD_ACCOUNT_DOCUMENT, id), request);
}
public Account fetchAccountDoc(String id) throws RazorpayException {
return get(Constants.VERSION_V2, String.format(Constants.UPLOAD_ACCOUNT_DOCUMENT, id), null);
}
}
44 changes: 42 additions & 2 deletions src/main/java/com/razorpay/ApiUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.razorpay;

import java.io.File;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
Expand All @@ -23,6 +24,8 @@
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.MultipartBody;
import okhttp3.MediaType;

class ApiUtils {

Expand Down Expand Up @@ -75,8 +78,15 @@ static Response postRequest(String version, String path, JSONObject requestObjec

HttpUrl.Builder builder = getBuilder(version, path, host);

String requestContent = requestObject == null ? "" : requestObject.toString();
RequestBody requestBody = RequestBody.create(Constants.MEDIA_TYPE_JSON, requestContent);
RequestBody requestBody;

if(requestObject != null && requestObject.has("file")){
requestBody = fileRequestBody(requestObject);
}else{
String requestContent = requestObject == null ? "" : requestObject.toString();
requestBody = RequestBody.create(Constants.MEDIA_TYPE_JSON, requestContent);
}

Request request =
createRequest(Method.POST.name(), builder.build().toString(), requestBody, auth);
return processRequest(request);
Expand Down Expand Up @@ -225,4 +235,34 @@ private static X509TrustManager createDefaultTrustManager() throws NoSuchAlgorit
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
return trustManager;
}

private static String getMediaType(String fileName){
int extensionIndex = fileName.lastIndexOf('.');
String extenionName = fileName.substring(extensionIndex + 1);
if(extenionName == "jpg" | extenionName == "jpeg" | extenionName == "png" | extenionName == "jfif"){
return "image/jpg";
}
return "image/pdf";
}

private static RequestBody fileRequestBody(JSONObject requestObject){
File fileToUpload = new File((String) requestObject.get("file"));
String fileName = fileToUpload.getName();

MediaType mediaType = MediaType.parse(getMediaType(fileName));
RequestBody fileBody = RequestBody.create(mediaType, fileToUpload);

MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM);
multipartBodyBuilder.addFormDataPart("file",fileName, fileBody);

Iterator<?> iterator = requestObject.keys();
while (iterator.hasNext()) {
Object key = iterator.next();
Object value = requestObject.get(key.toString());
multipartBodyBuilder.addFormDataPart((String) key, (String) value);
}

MultipartBody requestBody = multipartBodyBuilder.build();
return requestBody;
}
}
6 changes: 6 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,12 @@ public class Constants {
static final String TOKEN = "/token";
static final String REVOKE = "/revoke";

static final String DOCUMENTS = "/documents";
static final String DOCUMENT_FETCH = "/documents/%s";

static final String UPLOAD_ACCOUNT_DOCUMENT = "accounts/%s/documents";
static final String UPLOAD_STAKEHOLDER_DOCUMENT = "accounts/%s/stakeholders/%s/documents";

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

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/razorpay/Document.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.razorpay;

import org.json.JSONObject;

public class Document extends Entity {

public Document(JSONObject jsonObject) {
super(jsonObject);
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/razorpay/DocumentClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.razorpay;

import org.json.JSONObject;

public class DocumentClient extends ApiClient {

DocumentClient(String auth) {super(auth);}

public Document create(JSONObject request) throws RazorpayException {
return post(Constants.VERSION, Constants.DOCUMENTS, request);
}

public Document fetch(String id) throws RazorpayException {
return get(Constants.VERSION, String.format(Constants.DOCUMENT_FETCH, id), null);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/razorpay/RazorpayClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public class RazorpayClient {

public DisputeClient dispute;
public TncMap tncMap;
public DocumentClient document;

public BankAccountClient bankAccount;

public RazorpayClient(String key, String secret) throws RazorpayException {
this(key, secret, false);
}
Expand Down Expand Up @@ -69,6 +72,7 @@ private void initializeResources(String auth, Boolean enableLogging) throws Razo
stakeholder = new StakeholderClient(auth);
product = new ProductClient(auth);
webhook = new WebhookClient(auth);
document = new DocumentClient(auth);
dispute = new DisputeClient(auth);
bankAccount = new BankAccountClient(auth);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/razorpay/StakeholderClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public List<Stakeholder> 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);
}
}
Loading

0 comments on commit 779d137

Please sign in to comment.