Skip to content

Commit 19aeb5e

Browse files
axshaniilyamerman
andauthored
Get bank verification (#235)
* added bank verification * lint-fix * Added test + response encoding option Co-authored-by: ilyamerman <ilya@unit.co>
1 parent 130146c commit 19aeb5e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

resources/statements.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { BaseListParams, Statement, UnitConfig, UnitResponse } from "../types/common"
1+
import { BaseListParams, Statement, UnitConfig, UnitResponse } from "../types"
22
import { BaseResource } from "./baseResource"
3+
import { responseEncoding } from "axios"
34

45
export class Statments extends BaseResource {
56
constructor(token: string, basePath: string, config?: UnitConfig) {
@@ -36,6 +37,10 @@ export class Statments extends BaseResource {
3637
const url = isPDF ? `/${statementId}/pdf` : `/${statementId}/html`
3738
return this.httpGet<string>(url, {params: parameters, responseEncoding:"binary"})
3839
}
40+
41+
public getBankVerification(accountId: string, includeProofOfFunds = false, responseEncoding: responseEncoding = "binary"): Promise<string> {
42+
return this.httpGet<string>(`/${accountId}/bank/pdf`, {params: {includeProofOfFunds}, responseEncoding})
43+
}
3944
}
4045

4146
export interface StatementsListParams extends BaseListParams {

tests/statements.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Unit } from "../unit"
22
import dotenv from "dotenv"
3+
import {createIndividualAccount} from "./testHelpers"
34
dotenv.config()
45
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
56
const statementId: string[] = []
@@ -20,4 +21,15 @@ describe("Get Statement Test", () => {
2021
const res = await unit.statements.get(statementId[0])
2122
expect(res.includes("html")).toBeTruthy()
2223
})
24+
})
25+
26+
describe("Get Bank Verification Test", () => {
27+
test("get bank verification", async () => {
28+
const account = await createIndividualAccount(unit)
29+
const res = await unit.statements.getBankVerification(account.data.id)
30+
expect(res.includes("PDF")).toBeTruthy()
31+
32+
// Example for saving the pdf on the server, note that the default response encoding is "binary"
33+
// fs.writeFileSync(__dirname + "/bankVerification.pdf", res, "binary")
34+
})
2335
})

0 commit comments

Comments
 (0)