Skip to content

Commit 779d137

Browse files
authored
Added document endpoint (#316)
1 parent d899315 commit 779d137

13 files changed

+449
-2
lines changed

documents/account.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,63 @@ Account account = instance.account.fetch(accountId);
402402

403403
-------------------------------------------------------------------------------------------------------
404404

405+
### Upload account documents
406+
```java
407+
String accountId = "acc_M83Uw27KXuC7c8";
408+
409+
JSONObject request = new JSONObject();
410+
request.put("files","/Users/your_name/Downloads/sample_uploaded.jpeg");
411+
request.put("document_type","business_proof_url");
412+
413+
Account account = instance.account.uploadAccountDoc(accountId, request);
414+
```
415+
416+
**Parameters:**
417+
418+
| Name | Type | Description |
419+
|----------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
420+
| accountId* | string | The unique identifier of a sub-merchant account generated by Razorpay. |
421+
| file* | string | The URL generated once the business proof document is uploaded. |
422+
| 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` |
423+
424+
**Response:**
425+
```json
426+
{
427+
"business_proof_of_identification": [
428+
{
429+
"type": "business_proof_url",
430+
"url": "<https://rzp.io/i/bzDKbNg>"
431+
}
432+
]
433+
}
434+
```
435+
-------------------------------------------------------------------------------------------------------
436+
437+
### Fetch account documents
438+
```java
439+
String accountId = "acc_LryDIBIjBDbOWy";
440+
441+
Account account = instance.account.fetchAccountDoc(accountId);
442+
```
443+
444+
**Parameters:**
445+
446+
| Name | Type | Description |
447+
|-------------|-------------|------------------------------------------------------------------------|
448+
| accountId* | string | The unique identifier of a sub-merchant account generated by Razorpay. |
449+
450+
**Response:**
451+
```json
452+
{
453+
"business_proof_of_identification": [
454+
{
455+
"type": "business_proof_url",
456+
"url": "<https://rzp.io/i/bzDKbNg>"
457+
}
458+
]
459+
}
460+
```
461+
-------------------------------------------------------------------------------------------------------
405462
**PN: * indicates mandatory fields**
406463
<br>
407464
<br>

documents/document.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## Document
2+
3+
### Create a Document
4+
5+
```java
6+
JSONObject request = new JSONObject();
7+
request.put("file","/Users/your_name/Downloads/sample_uploaded.jpeg");
8+
request.put("purpose","dispute_evidence");
9+
10+
Document document = instance.document.create(request);
11+
```
12+
13+
**Parameters:**
14+
15+
| Name | Type | Description |
16+
|----------|-----------|-----------------------------------------------------------------|
17+
| file* | string | The URL generated once the business proof document is uploaded. |
18+
| purpose | string | Possible value is `dispute_evidence` |
19+
20+
**Response:**
21+
```json
22+
{
23+
"id": "doc_EsyWjHrfzb59Re",
24+
"entity": "document",
25+
"purpose": "dispute_evidence",
26+
"name": "doc_19_12_2020.jpg",
27+
"mime_type": "image/png",
28+
"size": 2863,
29+
"created_at": 1590604200
30+
}
31+
```
32+
-------------------------------------------------------------------------------------------------------
33+
34+
### Fetch Document Information
35+
36+
```java
37+
String documentId = "doc_EsyWjHrfzb59Re";
38+
39+
Document document = instance.document.fetch(documentId);
40+
```
41+
42+
**Parameters:**
43+
44+
| Name | Type | Description |
45+
|-------------|--------|--------------------------------------------------|
46+
| documentId | string | The unique identifier of the document. |
47+
48+
**Response:**
49+
```json
50+
{
51+
"entity": "document",
52+
"id": "doc_00000000000000",
53+
"purpose": "dispute_evidence",
54+
"created_at": 1701701378,
55+
"mime_type": "application/pdf",
56+
"display_name": "ppm_00000000000000",
57+
"size": 404678,
58+
"url": ""
59+
}
60+
```
61+
-------------------------------------------------------------------------------------------------------
62+
63+
**PN: * indicates mandatory fields**
64+
<br>
65+
<br>
66+
**For reference click [here](https://razorpay.com/docs/api/documents)**

documents/stakeholder.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,68 @@ Stakeholder stakeholder = instance.stakeholder.fetch(accountId, stakeholderId);
293293
}
294294
```
295295

296+
-------------------------------------------------------------------------------------------------------
297+
### Upload stakeholders documents
298+
```java
299+
String accoundId = "acc_LryDIBIjBDbOWy";
300+
String stakeholderId = "sth_M0zjeiVOLRJRPW";
301+
302+
JSONObject request = new JSONObject();
303+
request.put("file","/Users/your_name/Downloads/sample_uploaded.jpeg");
304+
request.put("document_type","aadhar_front");
305+
306+
Stakeholder stakeholder = instance.stakeholder.uploadStakeholderDoc(accoundId, stakeholderId, request);
307+
```
308+
309+
**Parameters:**
310+
311+
| Name | Type | Description |
312+
|-------------|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
313+
| accountId* | string | The unique identifier of a sub-merchant account generated by Razorpay. |
314+
| stakeholderId* | string | The unique identifier of the stakeholder whose details are to be fetched. |
315+
| file* | string | The URL generated once the business proof document is uploaded. |
316+
| 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` |
317+
318+
**Response:**
319+
```json
320+
{
321+
"individual_proof_of_address": [
322+
{
323+
"type": "aadhar_front",
324+
"url": "https://rzp.io/i/bzDAbNg"
325+
}
326+
]
327+
}
328+
```
329+
-------------------------------------------------------------------------------------------------------
330+
331+
### Fetch stakeholders documents
332+
```java
333+
334+
String accoundId = "acc_LryDIBIjBDbOWy";
335+
String stakeholderId = "sth_M0zjeiVOLRJRPW";
336+
337+
Stakeholder stakeholder = instance.stakeholder.fetchStakeholderDoc(accoundId, stakeholderId);
338+
```
339+
340+
**Parameters:**
341+
342+
| Name | Type | Description |
343+
|----------------|-------------|---------------------------------------------------------------------------|
344+
| accountId* | string | The unique identifier of a sub-merchant account generated by Razorpay. |
345+
| stakeholderId* | string | The unique identifier of the stakeholder whose details are to be fetched. |
346+
347+
**Response:**
348+
```json
349+
{
350+
"business_proof_of_identification": [
351+
{
352+
"type": "business_proof_url",
353+
"url": "<https://rzp.io/i/bzDKbNg>"
354+
}
355+
]
356+
}
357+
```
296358
-------------------------------------------------------------------------------------------------------
297359

298360
**PN: * indicates mandatory fields**

src/main/java/com/razorpay/AccountClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ public Account edit(String id, JSONObject request) throws RazorpayException {
2222
public Account delete(String id) throws RazorpayException {
2323
return delete(Constants.VERSION_V2, String.format(Constants.ACCOUNT_DELETE, id), null);
2424
}
25+
26+
public Account uploadAccountDoc(String id, JSONObject request) throws RazorpayException {
27+
return post(Constants.VERSION_V2, String.format(Constants.UPLOAD_ACCOUNT_DOCUMENT, id), request);
28+
}
29+
public Account fetchAccountDoc(String id) throws RazorpayException {
30+
return get(Constants.VERSION_V2, String.format(Constants.UPLOAD_ACCOUNT_DOCUMENT, id), null);
31+
}
2532
}

src/main/java/com/razorpay/ApiUtils.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.razorpay;
22

3+
import java.io.File;
34
import java.io.IOException;
45
import java.security.KeyStore;
56
import java.security.KeyStoreException;
@@ -23,6 +24,8 @@
2324
import okhttp3.RequestBody;
2425
import okhttp3.Response;
2526
import okhttp3.logging.HttpLoggingInterceptor;
27+
import okhttp3.MultipartBody;
28+
import okhttp3.MediaType;
2629

2730
class ApiUtils {
2831

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

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

78-
String requestContent = requestObject == null ? "" : requestObject.toString();
79-
RequestBody requestBody = RequestBody.create(Constants.MEDIA_TYPE_JSON, requestContent);
81+
RequestBody requestBody;
82+
83+
if(requestObject != null && requestObject.has("file")){
84+
requestBody = fileRequestBody(requestObject);
85+
}else{
86+
String requestContent = requestObject == null ? "" : requestObject.toString();
87+
requestBody = RequestBody.create(Constants.MEDIA_TYPE_JSON, requestContent);
88+
}
89+
8090
Request request =
8191
createRequest(Method.POST.name(), builder.build().toString(), requestBody, auth);
8292
return processRequest(request);
@@ -225,4 +235,34 @@ private static X509TrustManager createDefaultTrustManager() throws NoSuchAlgorit
225235
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
226236
return trustManager;
227237
}
238+
239+
private static String getMediaType(String fileName){
240+
int extensionIndex = fileName.lastIndexOf('.');
241+
String extenionName = fileName.substring(extensionIndex + 1);
242+
if(extenionName == "jpg" | extenionName == "jpeg" | extenionName == "png" | extenionName == "jfif"){
243+
return "image/jpg";
244+
}
245+
return "image/pdf";
246+
}
247+
248+
private static RequestBody fileRequestBody(JSONObject requestObject){
249+
File fileToUpload = new File((String) requestObject.get("file"));
250+
String fileName = fileToUpload.getName();
251+
252+
MediaType mediaType = MediaType.parse(getMediaType(fileName));
253+
RequestBody fileBody = RequestBody.create(mediaType, fileToUpload);
254+
255+
MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM);
256+
multipartBodyBuilder.addFormDataPart("file",fileName, fileBody);
257+
258+
Iterator<?> iterator = requestObject.keys();
259+
while (iterator.hasNext()) {
260+
Object key = iterator.next();
261+
Object value = requestObject.get(key.toString());
262+
multipartBodyBuilder.addFormDataPart((String) key, (String) value);
263+
}
264+
265+
MultipartBody requestBody = multipartBodyBuilder.build();
266+
return requestBody;
267+
}
228268
}

src/main/java/com/razorpay/Constants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ public class Constants {
170170
static final String TOKEN = "/token";
171171
static final String REVOKE = "/revoke";
172172

173+
static final String DOCUMENTS = "/documents";
174+
static final String DOCUMENT_FETCH = "/documents/%s";
175+
176+
static final String UPLOAD_ACCOUNT_DOCUMENT = "accounts/%s/documents";
177+
static final String UPLOAD_STAKEHOLDER_DOCUMENT = "accounts/%s/stakeholders/%s/documents";
178+
173179
static final String VIEW_RTO = "orders/%s/rto_review";
174180
static final String FULFILLMENT = "orders/%s/fulfillment";
175181

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.razorpay;
2+
3+
import org.json.JSONObject;
4+
5+
public class Document extends Entity {
6+
7+
public Document(JSONObject jsonObject) {
8+
super(jsonObject);
9+
}
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.razorpay;
2+
3+
import org.json.JSONObject;
4+
5+
public class DocumentClient extends ApiClient {
6+
7+
DocumentClient(String auth) {super(auth);}
8+
9+
public Document create(JSONObject request) throws RazorpayException {
10+
return post(Constants.VERSION, Constants.DOCUMENTS, request);
11+
}
12+
13+
public Document fetch(String id) throws RazorpayException {
14+
return get(Constants.VERSION, String.format(Constants.DOCUMENT_FETCH, id), null);
15+
}
16+
}

src/main/java/com/razorpay/RazorpayClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public class RazorpayClient {
3131

3232
public DisputeClient dispute;
3333
public TncMap tncMap;
34+
public DocumentClient document;
35+
3436
public BankAccountClient bankAccount;
37+
3538
public RazorpayClient(String key, String secret) throws RazorpayException {
3639
this(key, secret, false);
3740
}
@@ -69,6 +72,7 @@ private void initializeResources(String auth, Boolean enableLogging) throws Razo
6972
stakeholder = new StakeholderClient(auth);
7073
product = new ProductClient(auth);
7174
webhook = new WebhookClient(auth);
75+
document = new DocumentClient(auth);
7276
dispute = new DisputeClient(auth);
7377
bankAccount = new BankAccountClient(auth);
7478
}

src/main/java/com/razorpay/StakeholderClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ public List<Stakeholder> fetchAll(String id) throws RazorpayException {
2525
public Stakeholder edit(String id, String stakeholder_id, JSONObject request) throws RazorpayException {
2626
return patch(Constants.VERSION_V2, String.format(Constants.STAKEHOLDER_FETCH, id, stakeholder_id), request);
2727
}
28+
29+
public Account uploadStakeholderDoc(String id, String stakeholder_id, JSONObject request) throws RazorpayException {
30+
return post(Constants.VERSION_V2, String.format(Constants.UPLOAD_STAKEHOLDER_DOCUMENT, id, stakeholder_id), request);
31+
}
32+
33+
public Account fetchStakeholderDoc(String id, String stakeholder_id) throws RazorpayException {
34+
return get(Constants.VERSION_V2, String.format(Constants.UPLOAD_STAKEHOLDER_DOCUMENT, id, stakeholder_id), null);
35+
}
2836
}

0 commit comments

Comments
 (0)