Skip to content

Commit

Permalink
added documents (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored May 27, 2024
1 parent 829f1f4 commit d7f0aeb
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
65 changes: 65 additions & 0 deletions documents/documents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## Document

### Create a Document

```rb
Razorpay::Document.create({
"file": File.new("/Users/your_name/Downloads/sample_uploaded.jpeg"),
"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

```rb
documentId = "doc_NiyXWXXXXXXXXX"

Razorpay::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)**
1 change: 1 addition & 0 deletions lib/razorpay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
require 'razorpay/product'
require 'razorpay/stakeholder'
require 'razorpay/account'
require 'razorpay/document'
require 'razorpay/dispute'
require 'razorpay/oauth_token'

Expand Down
19 changes: 19 additions & 0 deletions lib/razorpay/document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'razorpay/request'
require 'razorpay/entity'

module Razorpay
# Document API allows you to create and fetch document on Razorpay
class Document < Entity
def self.request
Razorpay::Request.new('documents')
end

def self.create(options)
request.create options
end

def self.fetch(id)
request.fetch id
end
end
end
10 changes: 10 additions & 0 deletions test/fixtures/document_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"error": {
"code": "BAD_REQUEST_ERROR",
"description": "Invalid file id provided or merchant is unauthorized to access the fileId(s) provided",
"source": "NA",
"step": "NA",
"reason": "NA",
"metadata": {}
}
}
9 changes: 9 additions & 0 deletions test/fixtures/fake_document.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"entity": "document",
"id": "doc_O4KANwWi2kHGiV",
"purpose": "dispute_evidence",
"created_at": 1714368859,
"mime_type": "image/jpeg",
"display_name": "Screenshot 2022-09-12 at 5.48.23 PM",
"size": 334201
}
27 changes: 27 additions & 0 deletions test/razorpay/test_document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'test_helper'

module Razorpay
# Tests for Razorpay::Document
class RazorpayDocumentTest < Minitest::Test
def setup
@document_id = 'doc_O4KCaSbX4BjA6I'
# Any request that ends with document/document_id
stub_get(%r{documents/#{@document_id}$}, 'fake_document')
end

def test_document_should_be_defined
refute_nil Razorpay::Document
end

def test_document_should_be_defined_exception
para_attr = {}
stub_get(%r{documents/#{@document_id}$}, 'document_error')
assert_raises(Razorpay::Error) do
document = Razorpay::Document.fetch(@document_id)
if document.error
raise Razorpay::Error.new, document.error['code']
end
end
end
end
end

0 comments on commit d7f0aeb

Please sign in to comment.