Skip to content

Commit a5e357d

Browse files
axshaniilyamerman
andauthored
Check Deposit (#96)
* init check deposit * done with check-deposits * update version * lint-fix Co-authored-by: ilyamerman <[email protected]>
1 parent f103680 commit a5e357d

File tree

6 files changed

+257
-0
lines changed

6 files changed

+257
-0
lines changed

resources/checkDeposit.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { Account, Customer, Transaction } from "../types"
2+
import { CheckDeposit, CreateCheckDepositRequest, PatchCheckDepositRequest, UploadCheckDepositRequest } from "../types/checkDeposit"
3+
import { UnitResponse, Include, UnitConfig } from "../types/common"
4+
import { BaseResource } from "./baseResource"
5+
6+
export class CheckDeposits extends BaseResource {
7+
8+
constructor(token: string, basePath: string, config?: UnitConfig) {
9+
super(token, basePath + "/check-deposits", config)
10+
}
11+
12+
public async list(params?: CheckDepositListParams): Promise<UnitResponse<CheckDeposit[]>> {
13+
const parameters = {
14+
"page[limit]": (params?.limit ? params.limit : 100),
15+
"page[offset]": (params?.offset ? params.offset : 0),
16+
...(params?.accountId && { "filter[accountId]": params.accountId }),
17+
...(params?.customerId && { "filter[customerId]": params.customerId }),
18+
...(params?.tags && { "filter[tags]": params.tags }),
19+
"sort": params?.sort ? params.sort : "-createdAt",
20+
"include": params?.include ? params.include : "include"
21+
}
22+
23+
return this.httpGet<UnitResponse<CheckDeposit[]>>("", { params: parameters })
24+
}
25+
26+
public async create(request: CreateCheckDepositRequest): Promise<UnitResponse<CheckDeposit>> {
27+
return this.httpPost<UnitResponse<CheckDeposit>>("", { data: request })
28+
}
29+
30+
public async get(id: string, include = ""): Promise<UnitResponse<CheckDeposit> & Include<(Customer | Account | Transaction)[]>> {
31+
return this.httpGet<UnitResponse<CheckDeposit> & Include<(Customer | Account | Transaction)[]>>(`/${id}`, { params: { include }})
32+
}
33+
34+
public async update(request: PatchCheckDepositRequest): Promise<UnitResponse<CheckDeposit>> {
35+
return this.httpPatch<UnitResponse<CheckDeposit>>(`/${request.checkDepositId}`, { data: request.data })
36+
}
37+
38+
public async upload(request: UploadCheckDepositRequest) : Promise<UnitResponse<CheckDeposit>> {
39+
40+
let path = `/${request.checkDepositId}`
41+
if (request.isBackSide)
42+
path += "/back"
43+
44+
const headers = { "Content-Type": "image/jpeg" }
45+
46+
return this.httpPut<UnitResponse<CheckDeposit>>(path, request.file, {headers})
47+
}
48+
}
49+
50+
export interface CheckDepositListParams {
51+
/**
52+
* Maximum number of resources that will be returned. Maximum is 1000 resources. [See Pagination](https://developers.unit.co/#intro-pagination).
53+
* default: 100
54+
*/
55+
limit?: number
56+
57+
/**
58+
* Number of resources to skip. [See Pagination](https://developers.unit.co/#intro-pagination).
59+
* default: 0
60+
*/
61+
offset?: number
62+
63+
/**
64+
* Optional. Filters the results by the specified account id.
65+
* default: empty
66+
*/
67+
accountId?: string
68+
69+
/**
70+
* Optional. Filters the results by the specified customer id.
71+
* default: empty
72+
*/
73+
customerId?: string
74+
75+
/**
76+
* Optional. Filter Applications by [Tags](https://developers.unit.co/#tags).
77+
* default: empty
78+
*/
79+
tags?: object
80+
81+
/**
82+
* Optional. Leave empty or provide sort=createdAt for ascending order. Provide sort=-createdAt (leading minus sign) for descending order.
83+
*/
84+
sort?: string
85+
86+
/**
87+
* Optional. Related resource available to include: customer. See [Getting Related Resources](https://developers.unit.co/#intro-getting-related-resources).
88+
* default: empty
89+
*/
90+
include?: string
91+
}

resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ export * from "./statements"
1717
export * from "./transactions"
1818
export * from "./webhooks"
1919
export * from "./billPays"
20+
export * from "./checkDeposit"
2021

types/checkDeposit.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import { Relationship,CheckCounterparty } from "./common"
2+
3+
type CheckDepositStatus = "AwaitingImages" | "AwaitingFrontImage" | "AwaitingBackImage" | "Pending" | "PendingReview" |
4+
"Rejected" | "Clearing" | "Sent" | "Canceled" | "Returned"
5+
6+
export interface CheckDeposit {
7+
/**
8+
* Identifier of the check deposit resource.
9+
*/
10+
id: string
11+
12+
/**
13+
* Type of the check deposit resource. The value is always checkDeposit.
14+
*/
15+
type: "checkDeposit"
16+
17+
/**
18+
* JSON object representing the check deposit resource.
19+
*/
20+
attributes: {
21+
/**
22+
* Date only. The date the resource was created.
23+
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
24+
*/
25+
createdAt: string
26+
27+
/**
28+
* One of AwaitingImages, AwaitingFrontImage, AwaitingBackImage, Pending, PendingReview, Rejected, Clearing, Sent, Canceled, Returned.
29+
*/
30+
status: CheckDepositStatus
31+
32+
/**
33+
* Optional. More information about the status.
34+
*/
35+
reason?: string
36+
37+
/**
38+
* Check Deposit description (maximum of 50 characters).
39+
*/
40+
description: string
41+
42+
/**
43+
* The amount (cents) of the check deposit.
44+
*/
45+
amount: number
46+
47+
/**
48+
* Optional. The serial number printed at the bottom of the check
49+
*/
50+
checkNumber?: number
51+
52+
/**
53+
* Optional. The party the check belongs to.
54+
*/
55+
counterparty?: CheckCounterparty
56+
57+
/**
58+
* Optional. See Tags.
59+
*/
60+
tags?: object
61+
62+
/**
63+
* Optional. See Idempotency.
64+
*/
65+
idempotencyKey?: string
66+
//TODO: do we need this?
67+
}
68+
69+
/**
70+
* Describes relationships between the check deposit resource and other resources
71+
*/
72+
relationships: {
73+
/**
74+
* The Deposit Account receiving the check deposit.
75+
*/
76+
account: Relationship
77+
78+
/**
79+
* The Customer the deposit account belongs to.
80+
* This relationship is only available if the account belongs to a single customer, business or individual.
81+
*/
82+
customer?: Relationship
83+
84+
/**
85+
* The list of Customers the deposit account belongs to.
86+
* This relationship is only available if the account belongs to multiple individual customers.
87+
*/
88+
customers?: Relationship[]
89+
90+
/**
91+
* The Check Deposit Transaction generated by this check deposit.
92+
*/
93+
transaction: Relationship
94+
}
95+
}
96+
97+
export interface CreateCheckDepositRequest {
98+
type: "checkDeposit"
99+
attributes: {
100+
/**
101+
* The check amount (in cents) to deposit.
102+
*/
103+
amount: number
104+
105+
/**
106+
* Optional. Description of the check deposit (maximum of 50 characters).
107+
*/
108+
description?: string
109+
110+
/**
111+
* Optional. See Tags.
112+
*/
113+
tags?: object
114+
115+
/**
116+
* Optional. See Idempotency.
117+
*/
118+
idempotencyKey?: string
119+
}
120+
121+
relationships: {
122+
/**
123+
* The account receiving the check deposit.
124+
*/
125+
account: Relationship
126+
}
127+
}
128+
129+
export interface PatchCheckDepositRequest {
130+
checkDepositId: string
131+
132+
data: {
133+
type: "checkDeposit"
134+
attributes: {
135+
tags?: object
136+
}
137+
}
138+
}
139+
140+
export interface UploadCheckDepositRequest {
141+
checkDepositId: string
142+
isBackSide?: boolean
143+
file: Buffer
144+
}

types/common.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,23 @@ export interface WireCounterparty {
272272
address: Address
273273
}
274274

275+
export interface CheckCounterparty {
276+
/**
277+
* Valid 9-digit ABA routing transit number.
278+
*/
279+
routingNumber: string
280+
281+
/**
282+
* Bank account number.
283+
*/
284+
accountNumber: string
285+
286+
/**
287+
* Name of the person or company that owns the bank account.
288+
*/
289+
name: string
290+
}
291+
275292
export interface Coordinates {
276293
/**
277294
* The longitude value.

types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export * from "./returns"
1616
export * from "./transactions"
1717
export * from "./webhooks"
1818
export * from "./billPay"
19+
export * from "./checkDeposit"

unit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { AccountsEndOfDay } from "./resources/accountEndOfDay"
2121
import { BillPays } from "./resources"
2222
import { Institutions } from "./resources/institutions"
2323
import { AtmLocations } from "./resources/atmLocations"
24+
import { CheckDeposits } from "./resources/checkDeposit"
2425

2526
export class Unit {
2627
public applications: Applications
@@ -45,6 +46,7 @@ export class Unit {
4546
public billPays: BillPays
4647
public institutions: Institutions
4748
public atmLocations: AtmLocations
49+
public checkDeposits: CheckDeposits
4850

4951
constructor(token: string, basePath: string, config?: UnitConfig) {
5052
// remove all trailing slashes from user-provided basePath
@@ -71,6 +73,7 @@ export class Unit {
7173
this.billPays = new BillPays(token, basePath, config)
7274
this.institutions = new Institutions(token, basePath, config)
7375
this.atmLocations = new AtmLocations(token, basePath, config)
76+
this.checkDeposits = new CheckDeposits(token, basePath, config)
7477
this.helpers = helpers
7578
}
7679

0 commit comments

Comments
 (0)