Skip to content

Commit cf1d140

Browse files
axshaniilyamerman
andauthored
Update sdk (#60)
* update account resource * GetPinStatus added * DeviceFingerprint added * fix lint error * fix closeAccount * lint-fix * missed that one Co-authored-by: Ilya Merman <[email protected]>
1 parent 6c3a15a commit cf1d140

File tree

6 files changed

+87
-26
lines changed

6 files changed

+87
-26
lines changed

resources/account.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Include, UnitResponse, UnitConfig } from "../types/common"
22
import { Customer } from "../types/customer"
3-
import { CreateAccountRequest, Account, PatchAccountRequest, AccountLimits } from "../types/account"
3+
import { CreateAccountRequest, Account, PatchAccountRequest, AccountLimits, AccountDepositProduct, CloseAccountRequest } from "../types/account"
44
import { BaseResource } from "./baseResource"
55

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

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

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

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

49-
public async limits(accountId: string) : Promise<UnitResponse<AccountLimits>> {
49+
public async limits(accountId: string): Promise<UnitResponse<AccountLimits>> {
5050
return this.httpGet<UnitResponse<AccountLimits>>(`/${accountId}/limits`)
5151
}
52+
53+
public async getAvailableDepositProducts(accountId: string): Promise<UnitResponse<AccountDepositProduct[]>> {
54+
return this.httpGet<UnitResponse<AccountDepositProduct[]>>(`/${accountId}/deposit-products`)
55+
}
5256
}
5357

5458
export interface AccountListParams {

resources/cards.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,30 @@ export class Cards extends BaseResource {
2020
}
2121

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

2726
public async closeCard(id: string): Promise<UnitResponse<Card>> {
28-
const path = `/${id}/close`
29-
return await this.httpPost<UnitResponse<Card>>(path)
27+
return await this.httpPost<UnitResponse<Card>>(`/${id}/close`)
3028
}
3129

3230
public async freeze(id: string): Promise<UnitResponse<Card>> {
33-
const path = `/${id}/freeze`
34-
return await this.httpPost<UnitResponse<Card>>(path)
31+
return await this.httpPost<UnitResponse<Card>>(`/${id}/freeze`)
3532
}
3633

3734
public async unfreeze(id: string): Promise<UnitResponse<Card>> {
38-
const path = `/${id}/unfreeze`
39-
return await this.httpPost<UnitResponse<Card>>(path)
35+
return await this.httpPost<UnitResponse<Card>>(`/${id}/unfreeze`)
4036
}
4137

4238
public async replace(request: ReplaceCardRequest): Promise<UnitResponse<Card>> {
43-
const path = `/${request.id}/replace`
4439
const data = {
4540
type: "replaceCard",
4641
attributes: {
4742
shippingAddress: request.shippingAddress
4843
}
4944
}
5045

51-
return await this.httpPost<UnitResponse<Card>>(path, { data })
46+
return await this.httpPost<UnitResponse<Card>>(`/${request.id}/replace`, { data })
5247
}
5348

5449
/**
@@ -57,9 +52,7 @@ export class Cards extends BaseResource {
5752
* Related resources include: customer, account. See [Getting Related Resources](https://developers.unit.co/#intro-getting-related-resources).
5853
*/
5954
public async get(id: string, include = ""): Promise<UnitResponse<Card>> {
60-
const path = `/${id}?include=${include}`
61-
62-
return await this.httpGet<UnitResponse<Card> & Include<Account[] | Customer[]>>(path)
55+
return await this.httpGet<UnitResponse<Card> & Include<Account[] | Customer[]>>(`/${id}?include=${include}`)
6356
}
6457

6558
public async list(params?: CardListParams): Promise<UnitResponse<Card[]> & Include<Account[] | Customer[]>> {

types/account.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ export interface CreateDepositAccountRequest {
119119
*/
120120
relationships: {
121121
/**
122-
* The customer.
122+
* The customer the deposit account belongs to. The customer is either a business or an individual.
123+
* You must provide exactly one of customer or customers
123124
*/
124-
customer: Relationship
125+
customer?: Relationship
126+
127+
/**
128+
* 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.
129+
* You must provide exactly one of customer or customers
130+
*/
131+
customers?: Relationship[]
125132
}
126133
}
127134
export interface CreateBatchAccountRequest {
@@ -203,7 +210,8 @@ export interface PatchDepositAccountRequest {
203210
data: {
204211
type: "depositAccount"
205212
attributes: {
206-
tags: object
213+
tags?: object
214+
depositProduct?: string
207215
}
208216
}
209217
}
@@ -222,4 +230,36 @@ export interface BatchAccount {
222230
relationships: {
223231
org: Relationship
224232
}
225-
}
233+
}
234+
235+
export interface AccountDepositProduct {
236+
type: "accountDepositProduct"
237+
attributes: {
238+
name: string
239+
}
240+
}
241+
242+
type CloseReason = "ByCustomer" | "Fraud"
243+
244+
export class CloseAccountRequest {
245+
public accountId: string
246+
public reason: CloseReason
247+
248+
constructor(accountId: string, reason: CloseReason = "ByCustomer") {
249+
this.accountId = accountId
250+
this.reason = reason
251+
}
252+
253+
public to_json(): any {
254+
const data: any = {
255+
"data": {
256+
"type": "accountClose",
257+
"attributes": {
258+
"reason": this.reason
259+
}
260+
}
261+
}
262+
263+
return data
264+
}
265+
}

types/application.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Address, BeneficialOwner, BusinessContact, FullName, Officer, Phone, State, Relationship } from "./common"
1+
import { Address, BeneficialOwner, BusinessContact, FullName, Officer, Phone, State, Relationship, DeviceFingerprint } from "./common"
22

33
export type ApplicationStatus =
44
"AwaitingDocuments" | //Certain documents are required for the process to continue. You may upload them via Upload Document.
@@ -385,6 +385,11 @@ export interface CreateIndividualApplicationRequest {
385385
* See [Idempotency.](https://developers.unit.co/#intro-idempotency)
386386
*/
387387
idempotencyKey?: string
388+
389+
/**
390+
* Optional. A list of device fingerprints for fraud and risk prevention [See Device Fingerprints](https://developers.unit.co/applications/#device-fingerprints).
391+
*/
392+
deviceFingerprints?: DeviceFingerprint[]
388393
}
389394
}
390395

@@ -461,6 +466,11 @@ export interface CreateBusinessApplicationRequest {
461466
* See [Idempotency.](https://developers.unit.co/#intro-idempotency)
462467
*/
463468
idempotencyKey?: string
469+
470+
/**
471+
* Optional. A list of device fingerprints for fraud and risk prevention [See Device Fingerprints](https://developers.unit.co/applications/#device-fingerprints).
472+
*/
473+
deviceFingerprints?: DeviceFingerprint[]
464474
}
465475
}
466476

@@ -470,4 +480,4 @@ export interface UploadDocumentRequest {
470480
isBackSide?: boolean
471481
file: Buffer
472482
fileType: "jpeg" | "png" | "pdf"
473-
}
483+
}

types/cards.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ export interface ReplaceCardRequest {
519519
shippingAddress?: Address
520520
}
521521

522-
523522
export interface PinStatus {
524523
type: "pinStatus"
525524

types/common.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,21 @@ export interface Statement {
290290
*/
291291
export type Relationship = { data: { type: string; id: string; }; }
292292

293+
/**
294+
* More about [DeviceFingerprint](https://developers.unit.co/types#devicefingerprint)
295+
*/
296+
export interface DeviceFingerprint {
297+
/**
298+
* Provider of the device fingerprint fraud and risk prevention. The value is always iovation
299+
*/
300+
provider: string
301+
302+
/**
303+
* The device fingerprint blackbox value.
304+
*/
305+
value: string
306+
}
307+
293308
export interface UnitResponse<T> {
294309
data: T
295310
}

0 commit comments

Comments
 (0)