Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added document endpoint #271

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading