From b2f6364b7b7aa686be96c2dd65325ffdd2e2001d Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 6 Mar 2024 23:27:43 +0530 Subject: [PATCH 1/4] added document --- documents/document.md | 68 ++++++++++++++++++++++++++++++++++ razorpay/constants/url.py | 1 + razorpay/resources/__init__.py | 4 +- razorpay/resources/document.py | 28 ++++++++++++++ tests/mocks/document.json | 9 +++++ tests/test_client_document.py | 31 ++++++++++++++++ 6 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 documents/document.md create mode 100644 razorpay/resources/document.py create mode 100644 tests/mocks/document.json create mode 100644 tests/test_client_document.py diff --git a/documents/document.md b/documents/document.md new file mode 100644 index 00000000..47ef8a93 --- /dev/null +++ b/documents/document.md @@ -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** +
+
+**For reference click [here](https://razorpay.com/docs/api/documents)** \ No newline at end of file diff --git a/razorpay/constants/url.py b/razorpay/constants/url.py index e9ae8dea..4091396a 100644 --- a/razorpay/constants/url.py +++ b/razorpay/constants/url.py @@ -26,3 +26,4 @@ class URL(object): TOKEN = "/tokens" IIN = "/iins" WEBHOOK = "/webhooks" + DOCUMENT= "/documents" diff --git a/razorpay/resources/__init__.py b/razorpay/resources/__init__.py index 68917d25..83be3656 100644 --- a/razorpay/resources/__init__.py +++ b/razorpay/resources/__init__.py @@ -21,6 +21,7 @@ from .product import Product from .iin import Iin from .webhook import Webhook +from .document import Document __all__ = [ 'Payment', @@ -45,5 +46,6 @@ 'Stakeholder', 'Product', 'Iin', - 'Webhook' + 'Webhook', + 'Document' ] diff --git a/razorpay/resources/document.py b/razorpay/resources/document.py new file mode 100644 index 00000000..d97b3e37 --- /dev/null +++ b/razorpay/resources/document.py @@ -0,0 +1,28 @@ +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 = '{}'.format(self.base_url) + print(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) diff --git a/tests/mocks/document.json b/tests/mocks/document.json new file mode 100644 index 00000000..4c9c696e --- /dev/null +++ b/tests/mocks/document.json @@ -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 +} diff --git a/tests/test_client_document.py b/tests/test_client_document.py new file mode 100644 index 00000000..ee635dd4 --- /dev/null +++ b/tests/test_client_document.py @@ -0,0 +1,31 @@ +import responses +import json + +from .helpers import mock_file, ClientTestCase + + +class TestClientDocument(ClientTestCase): + + def setUp(self): + super(TestClientDocument, self).setUp() + self.base_url = '{}/documents'.format(self.base_url) + + @responses.activate + def test_document_fetch(self): + result = mock_file('document') + url = '{}/{}'.format(self.base_url, 'fake_document_id') + responses.add(responses.GET, url, status=200, body=json.dumps(result), + match_querystring=True) + self.assertEqual(self.client.document.fetch('fake_document_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) From 74e3e3bdc0166c1ef32884208468cdb25f69c897 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 7 Mar 2024 11:51:45 +0530 Subject: [PATCH 2/4] change url method --- razorpay/__init__.py | 4 +++- razorpay/resources/document.py | 3 +-- tests/test_client_document.py | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/razorpay/__init__.py b/razorpay/__init__.py index 92fcd45d..b6281075 100644 --- a/razorpay/__init__.py +++ b/razorpay/__init__.py @@ -25,6 +25,7 @@ from .resources import Product from .resources import Iin from .resources import Webhook +from .resources import Document __all__ = [ 'Payment', @@ -53,5 +54,6 @@ 'Stakeholder', 'Product', 'Iin', - 'Webhook' + 'Webhook', + 'Document' ] diff --git a/razorpay/resources/document.py b/razorpay/resources/document.py index d97b3e37..0f095a1e 100644 --- a/razorpay/resources/document.py +++ b/razorpay/resources/document.py @@ -14,8 +14,7 @@ def create(self, data={}, **kwargs): Returns: Dictionary of document """ - url = '{}'.format(self.base_url) - print(url) + url = self.base_url return self.file_url(url, data, **kwargs) def fetch(self, dispute_id, data={}, **kwargs): diff --git a/tests/test_client_document.py b/tests/test_client_document.py index ee635dd4..c3f6e559 100644 --- a/tests/test_client_document.py +++ b/tests/test_client_document.py @@ -13,10 +13,11 @@ def setUp(self): @responses.activate def test_document_fetch(self): result = mock_file('document') - url = '{}/{}'.format(self.base_url, 'fake_document_id') + 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('fake_document_id'), result) + self.assertEqual(self.client.document.fetch(id), result) @responses.activate def test_document_create(self): From 2736a8556e997fcf0eb4cd67f8b4d7a51dbd9463 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 13 Mar 2024 10:21:32 +0530 Subject: [PATCH 3/4] added comma --- razorpay/__init__.py | 2 +- razorpay/resources/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/razorpay/__init__.py b/razorpay/__init__.py index b6281075..96cd6b1b 100644 --- a/razorpay/__init__.py +++ b/razorpay/__init__.py @@ -55,5 +55,5 @@ 'Product', 'Iin', 'Webhook', - 'Document' + 'Document', ] diff --git a/razorpay/resources/__init__.py b/razorpay/resources/__init__.py index 83be3656..30198a14 100644 --- a/razorpay/resources/__init__.py +++ b/razorpay/resources/__init__.py @@ -47,5 +47,5 @@ 'Product', 'Iin', 'Webhook', - 'Document' + 'Document', ] From 740a9e4a4cb30d73d8806e35abf4b9065907cdfc Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 13 Mar 2024 10:23:45 +0530 Subject: [PATCH 4/4] update url method --- tests/test_client_document.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_client_document.py b/tests/test_client_document.py index c3f6e559..4ef6fd85 100644 --- a/tests/test_client_document.py +++ b/tests/test_client_document.py @@ -8,7 +8,7 @@ class TestClientDocument(ClientTestCase): def setUp(self): super(TestClientDocument, self).setUp() - self.base_url = '{}/documents'.format(self.base_url) + self.base_url = f"{self.base_url}/documents" @responses.activate def test_document_fetch(self):