Skip to content

Commit 31dac06

Browse files
ilyamermanaxshaniYegorZh
authored
Version 0.45.0 (#455)
* Credit Applications (#451) * implementation of CreditApplication * small test * annualIncome is optional * two kinds of CreateCreditApplicationRequest * test for create credit application * lint fix * update interfaces, more work to be done * lint-fix * refactoring: Account Limits (#452) * credit account limits and new attributes to deposit account limits * added a test * limits id * lint-fix * New repayments (#454) * feat: configured types for Partner repayments * feat: repayment tests * fix: repayment tests cleanup * fix: updated repayment statuses * fix: fixed book repayment test failing * fix: updated counterparty creation in repayments to use a plaid token * fix: fixed incorrect check in tests * feat: repayment test adjustments to use another credit account with different lending terms * fix: added new credit terms into tests * feat: added recurring repayment to repayment list filters * 0.45.0 * 0.45.0 * Add check payment daily and monthly sent --------- Co-authored-by: Alex Shani <[email protected]> Co-authored-by: Yehor Zhukovskyi <[email protected]>
1 parent d2c37ec commit 31dac06

17 files changed

+696
-95
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ jobs:
1717
touch .env
1818
echo UNIT_TOKEN=${{ secrets.UNIT_TOKEN }} >> .env
1919
echo UNIT_API_URL=${{ secrets.UNIT_API_URL }} >> .env
20+
echo TEST_COUNTERPARTY_PLAID_TOKEN=${{ secrets.TEST_COUNTERPARTY_PLAID_TOKEN }} >> .env
2021
- run: npm run test

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@unit-finance/unit-node-sdk",
3-
"version": "0.44.0",
3+
"version": "0.45.0",
44
"description": "",
55
"main": "dist/unit.js",
66
"types": "dist/unit.d.ts",

resources/creditApplication.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { BaseResource } from "./baseResource"
2+
import { UnitConfig, UnitResponse, CreditApplication, BaseListParams, DeniedCreditApplication, ApprovedCreditApplication, PatchCreditApplicationRequest, CreateCreditApplicationRequest } from "../types"
3+
4+
export class CreditApplications extends BaseResource {
5+
constructor(token: string, basePath: string, config?: UnitConfig) {
6+
super(token, basePath + "/credit-applications", config)
7+
}
8+
9+
public async create(request: CreateCreditApplicationRequest) {
10+
return this.httpPost<UnitResponse<CreditApplication>>("", { data: request })
11+
}
12+
13+
public async approve(credit_application_id: string) {
14+
return this.httpPost<UnitResponse<ApprovedCreditApplication>>(`/approve/${credit_application_id}/`)
15+
}
16+
17+
public async deny(credit_application_id: string) {
18+
return this.httpPost<UnitResponse<DeniedCreditApplication>>(`/deny/${credit_application_id}/`)
19+
}
20+
21+
public async update(request: PatchCreditApplicationRequest) {
22+
return this.httpPatch<UnitResponse<CreditApplication>>(`/${request.id}`, { data: request.data })
23+
}
24+
25+
public async get(credit_application_id: string) {
26+
return this.httpGet<UnitResponse<CreditApplication>>(`/${credit_application_id}`)
27+
}
28+
29+
public async list(params?: CreditApplicationListParams) {
30+
const parameters: any = {
31+
"page[limit]": (params?.limit ? params?.limit : 100),
32+
"page[offset]": (params?.offset ? params?.offset : 0),
33+
...(params?.lendingProgramId && { "filter[lendingProgramId]": params?.lendingProgramId }),
34+
...(params?.orgId && { "filter[orgId]": params?.orgId }),
35+
...(params?.applicationId && { "filter[applicationId]": params?.applicationId }),
36+
...(params?.bankId && { "filter[bankId]": params?.bankId }),
37+
...(params?.customerId && { "filter[customerId]": params?.customerId })
38+
}
39+
40+
return this.httpGet<UnitResponse<CreditApplication[]>>("", { params: parameters })
41+
}
42+
}
43+
44+
export interface CreditApplicationListParams extends BaseListParams {
45+
/**
46+
* Optional. Search resources by lending program id.
47+
* default: empty
48+
*/
49+
lendingProgramId?: string
50+
51+
/**
52+
* Optional. Search resources by organization id.
53+
* default: empty
54+
*/
55+
orgId?: string
56+
57+
/**
58+
* Optional. Search resources by lending program id.
59+
* default: empty
60+
*/
61+
bankId?: string
62+
63+
/**
64+
* Optional. Search resources by application id.
65+
* default: empty
66+
*/
67+
applicationId?: string
68+
69+
/**
70+
* Optional. Search resources by customer id.
71+
* default: empty
72+
*/
73+
customerId?: string
74+
}

resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ export * from "./transactions"
3131
export * from "./webhooks"
3232
export * from "./chargeback"
3333
export * from "./taxForms"
34+
export * from "./creditApplication"

resources/repayments.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,9 @@ export interface RepaymentListParams extends BaseListParams {
6666
* Optional. Filter repayments by Repayment type. such as (AchRepayment, BookRepayment). Usage example: filter[type][0]=AchRepayment&filter[type][1]=BookRepayment
6767
*/
6868
type?: string[]
69+
70+
/**
71+
* Optional. Filters the result according to the associated [Recurring Repayment](https://www.unit.co/docs/api/recurring-repayments/) id
72+
*/
73+
recurringRepayment?: string
6974
}

resources/simulations.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseResource } from "."
2-
import { AtmAuthorizationRequest, CardTransactionAuthorizationRequest, CheckPayment, CreateAtmAuthorizationRequestSimulation,
3-
CreateCardPurchaseAuthorizationRequestSimulation, CreateCardTransactionAuthorizationRequestSimulation, CreateCheckPaymentSimulation, PurchaseAuthorizationRequest, UnitConfig, UnitResponse } from "../types"
2+
import { AtmAuthorizationRequest, AtmTransaction, AtmWithdrawalRequestSimulation, CardTransactionAuthorizationRequest, CheckPayment, CreateAtmAuthorizationRequestSimulation,
3+
CreateCardPurchaseAuthorizationRequestSimulation, CreateCardTransactionAuthorizationRequestSimulation, CreateCheckPaymentSimulation, PurchaseAuthorizationRequest, Relationship, UnitConfig, UnitResponse } from "../types"
44
import { AchReceivedPayment, Application, ApplicationDocument, AchPayment } from "../types"
55
import {
66
ApproveApplicationSimulation,
@@ -178,4 +178,21 @@ export class Simulations extends BaseResource {
178178
public async activateCard(id: string): Promise<UnitResponse<Card>> {
179179
return this.httpPost<UnitResponse<Card>>(`/cards/${id}/activate`)
180180
}
181+
182+
public async atmWithdrawal(amount: number, account: Relationship): Promise<UnitResponse<AtmTransaction>> {
183+
const req: AtmWithdrawalRequestSimulation = {
184+
"type":"atmTransaction",
185+
"attributes": {
186+
"amount": amount,
187+
"atmName": "HOME FED SAV BK",
188+
"atmLocation": "Cupertino, CA, US",
189+
"last4Digits": "0019"
190+
},
191+
"relationships": {
192+
account
193+
}
194+
}
195+
196+
return this.httpPost<UnitResponse<AtmTransaction>>("/atm-withdrawals", req)
197+
}
181198
}

tests/accounts.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,15 @@ describe("Close Account", () => {
8181
expect(account.type).toBe("depositAccount")
8282
expect(closedAccount.attributes.status).toBe("Closed")
8383
})
84+
})
85+
86+
describe("Account Limits", () => {
87+
test("Get Accounts List and Limits", async () => {
88+
const res = await unit.accounts.list()
89+
res.data.forEach(async account => {
90+
const limits = (await unit.accounts.limits(account.id)).data
91+
expect(limits.type).toContain("limits")
92+
expect(limits.id).not.toBe(undefined)
93+
})
94+
})
8495
})

tests/creditApplications.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import dotenv from "dotenv"
2+
import { CreateExistingCustomerCreditApplicationRequest, Unit } from "../unit"
3+
import { createBusinessApplication } from "./testHelpers"
4+
import { createRelationship } from "../helpers"
5+
6+
dotenv.config()
7+
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
8+
9+
describe("Get Credit Applications", () => {
10+
test("Test Get endpoint", async () => {
11+
const res = await unit.creditApplications.list()
12+
expect(res.data).toBeInstanceOf(Array)
13+
res.data.forEach(async element => {
14+
expect(element.type).toContain("CreditApplication")
15+
const app = await (await unit.creditApplications.get(element.id)).data
16+
expect(element.type).toBe(app.type)
17+
expect(element.id).toBe(app.id)
18+
})
19+
})
20+
21+
test("Get List of Credit Applications", async () => {
22+
const res = await unit.creditApplications.list()
23+
expect(res.data).toBeInstanceOf(Array)
24+
})
25+
})
26+
27+
describe("Create Credit Application", () => {
28+
test("Test Create Credit Application", async () => {
29+
const businessApplication = (await createBusinessApplication(unit)).data
30+
const customerId = businessApplication.relationships.customer?.data.id || ""
31+
32+
const request: CreateExistingCustomerCreditApplicationRequest = {
33+
type: "createExistingCustomerCreditApplication",
34+
attributes: {},
35+
relationships: {
36+
customer: createRelationship("customer", customerId),
37+
lendingProgram: createRelationship("lendingProgram", "51")
38+
}
39+
}
40+
41+
const creditApplication = (await unit.creditApplications.create(request)).data
42+
expect(creditApplication.type).toBe("existingCustomerCreditApplication")
43+
})
44+
})

0 commit comments

Comments
 (0)