Skip to content

Commit e0cf503

Browse files
authored
Added document endpoint (#271)
1 parent e40fbf1 commit e0cf503

File tree

7 files changed

+142
-0
lines changed

7 files changed

+142
-0
lines changed

documents/document.md

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

razorpay/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .resources import Product
2626
from .resources import Iin
2727
from .resources import Webhook
28+
from .resources import Document
2829
from .resources import Dispute
2930

3031
__all__ = [
@@ -55,5 +56,6 @@
5556
'Product',
5657
'Iin',
5758
'Webhook',
59+
'Document',
5860
'Dispute',
5961
]

razorpay/constants/url.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ class URL(object):
2626
TOKEN = "/tokens"
2727
IIN = "/iins"
2828
WEBHOOK = "/webhooks"
29+
DOCUMENT= "/documents"
2930
DISPUTE= "/disputes"
31+

razorpay/resources/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .product import Product
2222
from .iin import Iin
2323
from .webhook import Webhook
24+
from .document import Document
2425
from .dispute import Dispute
2526

2627
__all__ = [
@@ -47,5 +48,6 @@
4748
'Product',
4849
'Iin',
4950
'Webhook',
51+
'Document',
5052
'Dispute',
5153
]

razorpay/resources/document.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from .base import Resource
2+
from ..constants.url import URL
3+
4+
5+
class Document(Resource):
6+
def __init__(self, client=None):
7+
super(Document, self).__init__(client)
8+
self.base_url = URL.V1 + URL.DOCUMENT
9+
10+
def create(self, data={}, **kwargs):
11+
"""
12+
Create a Document
13+
14+
Returns:
15+
Dictionary of document
16+
"""
17+
url = self.base_url
18+
return self.file_url(url, data, **kwargs)
19+
20+
def fetch(self, dispute_id, data={}, **kwargs):
21+
"""
22+
Fetch Document
23+
24+
Returns:
25+
Dictionary of document
26+
"""
27+
return super(Document, self).fetch(dispute_id, data, **kwargs)

tests/mocks/document.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "doc_EsyWjHrfzb59Re",
3+
"entity": "document",
4+
"purpose": "dispute_evidence",
5+
"name": "doc_19_12_2020.jpg",
6+
"mime_type": "image/png",
7+
"size": 2863,
8+
"created_at": 1590604200
9+
}

tests/test_client_document.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import responses
2+
import json
3+
4+
from .helpers import mock_file, ClientTestCase
5+
6+
7+
class TestClientDocument(ClientTestCase):
8+
9+
def setUp(self):
10+
super(TestClientDocument, self).setUp()
11+
self.base_url = f"{self.base_url}/documents"
12+
13+
@responses.activate
14+
def test_document_fetch(self):
15+
result = mock_file('document')
16+
id = 'fake_document_id'
17+
url = f"{self.base_url}/{id}"
18+
responses.add(responses.GET, url, status=200, body=json.dumps(result),
19+
match_querystring=True)
20+
self.assertEqual(self.client.document.fetch(id), result)
21+
22+
@responses.activate
23+
def test_document_create(self):
24+
request = {
25+
'file': '',
26+
'purpose': 'dispute_evidence'
27+
}
28+
result = mock_file('document')
29+
url = self.base_url
30+
responses.add(responses.POST, url, status=200, body=json.dumps(result),
31+
match_querystring=True)
32+
self.assertEqual(self.client.document.create(request), result)

0 commit comments

Comments
 (0)