Skip to content

Commit

Permalink
Added document endpoint (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored Mar 19, 2024
1 parent e40fbf1 commit e0cf503
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
68 changes: 68 additions & 0 deletions documents/document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## Document

### Create a Document

```py

file = open('/Users/your_name/Downloads/sample_uploaded.jpeg', 'rb')

x = client.document.create({
'file': file,
'purpose': 'dispute_evidence'
})
```

**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

```py
documentId = "doc_NiyXWXXXXXXXXX"

client.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)**
2 changes: 2 additions & 0 deletions razorpay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .resources import Product
from .resources import Iin
from .resources import Webhook
from .resources import Document
from .resources import Dispute

__all__ = [
Expand Down Expand Up @@ -55,5 +56,6 @@
'Product',
'Iin',
'Webhook',
'Document',
'Dispute',
]
2 changes: 2 additions & 0 deletions razorpay/constants/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ class URL(object):
TOKEN = "/tokens"
IIN = "/iins"
WEBHOOK = "/webhooks"
DOCUMENT= "/documents"
DISPUTE= "/disputes"

2 changes: 2 additions & 0 deletions razorpay/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .product import Product
from .iin import Iin
from .webhook import Webhook
from .document import Document
from .dispute import Dispute

__all__ = [
Expand All @@ -47,5 +48,6 @@
'Product',
'Iin',
'Webhook',
'Document',
'Dispute',
]
27 changes: 27 additions & 0 deletions razorpay/resources/document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from .base import Resource
from ..constants.url import URL


class Document(Resource):
def __init__(self, client=None):
super(Document, self).__init__(client)
self.base_url = URL.V1 + URL.DOCUMENT

def create(self, data={}, **kwargs):
"""
Create a Document
Returns:
Dictionary of document
"""
url = self.base_url
return self.file_url(url, data, **kwargs)

def fetch(self, dispute_id, data={}, **kwargs):
"""
Fetch Document
Returns:
Dictionary of document
"""
return super(Document, self).fetch(dispute_id, data, **kwargs)
9 changes: 9 additions & 0 deletions tests/mocks/document.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "doc_EsyWjHrfzb59Re",
"entity": "document",
"purpose": "dispute_evidence",
"name": "doc_19_12_2020.jpg",
"mime_type": "image/png",
"size": 2863,
"created_at": 1590604200
}
32 changes: 32 additions & 0 deletions tests/test_client_document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import responses
import json

from .helpers import mock_file, ClientTestCase


class TestClientDocument(ClientTestCase):

def setUp(self):
super(TestClientDocument, self).setUp()
self.base_url = f"{self.base_url}/documents"

@responses.activate
def test_document_fetch(self):
result = mock_file('document')
id = 'fake_document_id'
url = f"{self.base_url}/{id}"
responses.add(responses.GET, url, status=200, body=json.dumps(result),
match_querystring=True)
self.assertEqual(self.client.document.fetch(id), result)

@responses.activate
def test_document_create(self):
request = {
'file': '',
'purpose': 'dispute_evidence'
}
result = mock_file('document')
url = self.base_url
responses.add(responses.POST, url, status=200, body=json.dumps(result),
match_querystring=True)
self.assertEqual(self.client.document.create(request), result)

0 comments on commit e0cf503

Please sign in to comment.