Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 10 additions & 6 deletions resources/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Include, UnitResponse, UnitConfig } from "../types/common"
import { Customer } from "../types/customer"
import { CreateAccountRequest, Account, PatchAccountRequest, AccountLimits } from "../types/account"
import { CreateAccountRequest, Account, PatchAccountRequest, AccountLimits, AccountDepositProduct, CloseAccountRequest } from "../types/account"
import { BaseResource } from "./baseResource"

export class Accounts extends BaseResource {
Expand All @@ -13,8 +13,8 @@ export class Accounts extends BaseResource {
return this.httpPost<UnitResponse<Account>>("", { data: request })
}

public async closeAccount(accountId: string): Promise<UnitResponse<Account>> {
return this.httpPost<UnitResponse<Account>>(`/${accountId}/close`)
public async closeAccount(request: CloseAccountRequest): Promise<UnitResponse<Account>> {
return this.httpPost<UnitResponse<Account>>(`/${request.accountId}/close`, request.to_json())
}

public async reopenAccount(accountId: string): Promise<UnitResponse<Account>> {
Expand Down Expand Up @@ -42,13 +42,17 @@ export class Accounts extends BaseResource {
return this.httpGet<UnitResponse<Account[]> & Include<Customer[]>>("", { params: parameters })
}

public async update(request: PatchAccountRequest) : Promise<UnitResponse<Account>> {
return this.httpPatch<UnitResponse<Account>>(`/${request.accountId}`,{data: request.data})
public async update(request: PatchAccountRequest): Promise<UnitResponse<Account>> {
return this.httpPatch<UnitResponse<Account>>(`/${request.accountId}`, { data: request.data })
}

public async limits(accountId: string) : Promise<UnitResponse<AccountLimits>> {
public async limits(accountId: string): Promise<UnitResponse<AccountLimits>> {
return this.httpGet<UnitResponse<AccountLimits>>(`/${accountId}/limits`)
}

public async getAvailableDepositProducts(accountId: string): Promise<UnitResponse<AccountDepositProduct[]>> {
return this.httpGet<UnitResponse<AccountDepositProduct[]>>(`/${accountId}/deposit-products`)
}
}

export interface AccountListParams {
Expand Down
19 changes: 6 additions & 13 deletions resources/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,30 @@ export class Cards extends BaseResource {
}

public async reportLost(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/report-lost`
return await this.httpPost<UnitResponse<Card>>(path)
return await this.httpPost<UnitResponse<Card>>(`/${id}/report-lost`)
}

public async closeCard(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/close`
return await this.httpPost<UnitResponse<Card>>(path)
return await this.httpPost<UnitResponse<Card>>(`/${id}/close`)
}

public async freeze(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/freeze`
return await this.httpPost<UnitResponse<Card>>(path)
return await this.httpPost<UnitResponse<Card>>(`/${id}/freeze`)
}

public async unfreeze(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/unfreeze`
return await this.httpPost<UnitResponse<Card>>(path)
return await this.httpPost<UnitResponse<Card>>(`/${id}/unfreeze`)
}

public async replace(request: ReplaceCardRequest): Promise<UnitResponse<Card>> {
const path = `/${request.id}/replace`
const data = {
type: "replaceCard",
attributes: {
shippingAddress: request.shippingAddress
}
}

return await this.httpPost<UnitResponse<Card>>(path, { data })
return await this.httpPost<UnitResponse<Card>>(`/${request.id}/replace`, { data })
}

/**
Expand All @@ -57,9 +52,7 @@ export class Cards extends BaseResource {
* Related resources include: customer, account. See [Getting Related Resources](https://developers.unit.co/#intro-getting-related-resources).
*/
public async get(id: string, include = ""): Promise<UnitResponse<Card>> {
const path = `/${id}?include=${include}`

return await this.httpGet<UnitResponse<Card> & Include<Account[] | Customer[]>>(path)
return await this.httpGet<UnitResponse<Card> & Include<Account[] | Customer[]>>(`/${id}?include=${include}`)
}

public async list(params?: CardListParams): Promise<UnitResponse<Card[]> & Include<Account[] | Customer[]>> {
Expand Down
48 changes: 44 additions & 4 deletions types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,16 @@ export interface CreateDepositAccountRequest {
*/
relationships: {
/**
* The customer.
* The customer the deposit account belongs to. The customer is either a business or an individual.
* You must provide exactly one of customer or customers
*/
customer: Relationship
customer?: Relationship

/**
* The list of customers the deposit account belongs to. Each of the customers is an individual customer and at least one must be over 18 years old.
* You must provide exactly one of customer or customers
*/
customers?: Relationship[]
}
}
export interface CreateBatchAccountRequest {
Expand Down Expand Up @@ -203,7 +210,8 @@ export interface PatchDepositAccountRequest {
data: {
type: "depositAccount"
attributes: {
tags: object
tags?: object
depositProduct?: string
}
}
}
Expand All @@ -222,4 +230,36 @@ export interface BatchAccount {
relationships: {
org: Relationship
}
}
}

export interface AccountDepositProduct {
type: "accountDepositProduct"
attributes: {
name: string
}
}

type CloseReason = "ByCustomer" | "Fraud"

export class CloseAccountRequest {
public accountId: string
public reason: CloseReason

constructor(accountId: string, reason: CloseReason = "ByCustomer") {
this.accountId = accountId
this.reason = reason
}

public to_json(): any {
const data: any = {
"data": {
"type": "accountClose",
"attributes": {
"reason": this.reason
}
}
}

return data
}
}
14 changes: 12 additions & 2 deletions types/application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, BeneficialOwner, BusinessContact, FullName, Officer, Phone, State, Relationship } from "./common"
import { Address, BeneficialOwner, BusinessContact, FullName, Officer, Phone, State, Relationship, DeviceFingerprint } from "./common"

export type ApplicationStatus =
"AwaitingDocuments" | //Certain documents are required for the process to continue. You may upload them via Upload Document.
Expand Down Expand Up @@ -385,6 +385,11 @@ export interface CreateIndividualApplicationRequest {
* See [Idempotency.](https://developers.unit.co/#intro-idempotency)
*/
idempotencyKey?: string

/**
* Optional. A list of device fingerprints for fraud and risk prevention [See Device Fingerprints](https://developers.unit.co/applications/#device-fingerprints).
*/
deviceFingerprints?: DeviceFingerprint[]
}
}

Expand Down Expand Up @@ -461,6 +466,11 @@ export interface CreateBusinessApplicationRequest {
* See [Idempotency.](https://developers.unit.co/#intro-idempotency)
*/
idempotencyKey?: string

/**
* Optional. A list of device fingerprints for fraud and risk prevention [See Device Fingerprints](https://developers.unit.co/applications/#device-fingerprints).
*/
deviceFingerprints?: DeviceFingerprint[]
}
}

Expand All @@ -470,4 +480,4 @@ export interface UploadDocumentRequest {
isBackSide?: boolean
file: Buffer
fileType: "jpeg" | "png" | "pdf"
}
}
1 change: 0 additions & 1 deletion types/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ export interface ReplaceCardRequest {
shippingAddress?: Address
}


export interface PinStatus {
type: "pinStatus"

Expand Down
15 changes: 15 additions & 0 deletions types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,21 @@ export interface Statement {
*/
export type Relationship = { data: { type: string; id: string; }; }

/**
* More about [DeviceFingerprint](https://developers.unit.co/types#devicefingerprint)
*/
export interface DeviceFingerprint {
/**
* Provider of the device fingerprint fraud and risk prevention. The value is always iovation
*/
provider: string

/**
* The device fingerprint blackbox value.
*/
value: string
}

export interface UnitResponse<T> {
data: T
}
Expand Down