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

feat: Added document entity #392

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
73 changes: 73 additions & 0 deletions documents/documents.md
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)**
6 changes: 6 additions & 0 deletions lib/razorpay.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import webhooks from './types/webhooks'
import products from './types/products'
import tokens from './types/tokens'
import iins from './types/iins'
import documents from './types/documents'

interface IRazorpayConfig {
key_id: string;
Expand Down Expand Up @@ -144,6 +145,11 @@ declare class Razorpay {
* @see https://razorpay.com/docs/api/payments/cards/iin-api/#iin-entity
*/
iins: ReturnType<typeof iins>
/**
* Documents Entity
* @see https://razorpay.com/docs/api/documents
*/
documents: ReturnType<typeof documents>
}

export = Razorpay
3 changes: 2 additions & 1 deletion lib/razorpay.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class Razorpay {
fundAccount : require('./resources/fundAccount')(this.api),
items : require('./resources/items')(this.api),
cards : require('./resources/cards')(this.api),
webhooks : require('./resources/webhooks')(this.api)
webhooks : require('./resources/webhooks')(this.api),
documents : require('./resources/documents')(this.api),
})
}
}
Expand Down
21 changes: 21 additions & 0 deletions lib/resources/documents.js
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);
},
}
}
67 changes: 67 additions & 0 deletions lib/types/documents.d.ts
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
56 changes: 56 additions & 0 deletions test/resources/documents.spec.js
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()
})
})
})
Loading