-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f341db4
commit 5bc90ef
Showing
6 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
## Document | ||
|
||
### Create a Document | ||
|
||
```js | ||
var formData = { | ||
'file': { | ||
'value': fs.createReadStream('/Users/your_name/Downloads/sample_uploaded.pdf'), | ||
'options': { | ||
'filename': 'sample_uploaded.pdf', | ||
'contentType': null | ||
} | ||
}, | ||
'purpose': 'dispute_evidence' | ||
}; | ||
|
||
instance.documents.create(formData); | ||
``` | ||
|
||
**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 | ||
|
||
```js | ||
var documentId = "doc_EsyWjHrfzb59Re"; | ||
|
||
instance.documents.fetch(documentId); | ||
``` | ||
|
||
**Parameters:** | ||
|
||
| Name | Type | Description | | ||
|-------|-----------|--------------------------------------------------| | ||
| Id* | 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)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
module.exports = function (api) { | ||
|
||
const BASE_URL = "/documents"; | ||
|
||
return { | ||
create(params, callback) { | ||
return api.postFormData({ | ||
url: `${BASE_URL}`, | ||
formData: params | ||
}, callback); | ||
}, | ||
|
||
fetch(documentId, callback) { | ||
return api.get({ | ||
url: `${BASE_URL}/${documentId}`, | ||
}, callback); | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { INormalizeError } from "./api"; | ||
import * as fs from "fs" | ||
|
||
export declare namespace Documents { | ||
|
||
interface FileCreateParams { | ||
file: { | ||
value: fs.ReadStream; | ||
options?: { | ||
filename?: string; | ||
contentType?: string | null; | ||
}; | ||
}; | ||
purpose: string; | ||
} | ||
|
||
interface RazorpayDocument { | ||
/** | ||
* The unique identifier of the document. | ||
*/ | ||
id: string | ||
/** | ||
* Indicates the type of entity. | ||
*/ | ||
entity: string | ||
/** | ||
* The reason you are uploading this document. possible value is `dispute_evidence`. | ||
*/ | ||
purpose: string | ||
name: string | ||
/** | ||
* Indicates the nature and format in which the document is uploaded. | ||
* possible value is `image/jpg`, `image/jpeg`, `image/png`, `application/pdf` | ||
* | ||
*/ | ||
mime_type: string | ||
/** | ||
* Indicates the size of the document in bytes. | ||
*/ | ||
size: number | ||
/** | ||
* Unix timestamp at which the document was uploaded. | ||
*/ | ||
created_at: number | ||
} | ||
|
||
} | ||
|
||
declare function documents(api: any): { | ||
/** | ||
* Create a Document | ||
* | ||
* @param params - Check [doc](https://razorpay.com/docs/api/documents/create/) for required params | ||
* | ||
*/ | ||
create(params: Documents.FileCreateParams): Promise<Documents.RazorpayDocument> | ||
create(params: Documents.FileCreateParams, callback: (err: INormalizeError | null, data: Documents.RazorpayDocument) => void): void; | ||
/** | ||
* Fetch document by id | ||
* | ||
* @param documentId - The unique identifier of the document | ||
* | ||
*/ | ||
fetch(documentId: string): Promise<Documents.RazorpayDocument> | ||
} | ||
|
||
export default documents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const { assert } = chai | ||
const rzpInstance = require('../razorpay') | ||
const mocker = require('../mocker') | ||
const equal = require('deep-equal') | ||
|
||
const BASE_URL = '/documents', | ||
TEST_DOCUMENT_ID = 'disp_AHfqOvkldwsbqt'; | ||
|
||
describe('DOCUMENTS', () => { | ||
it('Create an document', (done) => { | ||
|
||
var formData = { | ||
'file': { | ||
'value': '/Users/your_name/Downloads/sample_uploaded.pdf', | ||
'options': { | ||
'filename': 'README.md', | ||
'contentType': null | ||
} | ||
}, | ||
'purpose': 'dispute_evidence' | ||
}; | ||
|
||
mocker.mock({ | ||
url: `${BASE_URL}`, | ||
method: 'POST' | ||
}) | ||
|
||
rzpInstance.documents.create(formData).then((response) => { | ||
assert.equal( | ||
response.__JUST_FOR_TESTS__.url, | ||
`/v1/documents`, | ||
'Create document request url formed' | ||
) | ||
done() | ||
}) | ||
}) | ||
|
||
it('Fetch document detail', (done) => { | ||
mocker.mock({ | ||
url: `/${BASE_URL}/${TEST_DOCUMENT_ID}`, | ||
method: 'GET' | ||
}) | ||
|
||
rzpInstance.documents.fetch(TEST_DOCUMENT_ID).then((response) => { | ||
assert.equal( | ||
response.__JUST_FOR_TESTS__.url, | ||
`/v1/documents/${TEST_DOCUMENT_ID}`, | ||
'fetch document detail request url formed' | ||
) | ||
done() | ||
}) | ||
}) | ||
}) |