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
1 change: 1 addition & 0 deletions resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from "./customerToken"
export * from "./events"
export * from "./fee"
export * from "./payments"
export * from "./receivedPayments"
export * from "./returns"
export * from "./statements"
export * from "./transactions"
Expand Down
104 changes: 104 additions & 0 deletions resources/receivedPayments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Account } from "../types/account"
import { Include, UnitConfig, UnitResponse } from "../types/common"
import { Customer } from "../types/customer"
import { AchReceivedPayment, PatchPaymentRequest } from "../types/payments"
import { Transaction } from "../types/transactions"
import { BaseResource } from "./baseResource"

export class ReceivedPayments extends BaseResource {
constructor(token: string, basePath: string, config?: UnitConfig) {
super(token, basePath + "/received-payments", config)
}

public async update(id: string, request: PatchPaymentRequest): Promise<UnitResponse<AchReceivedPayment>> {
return this.httpPatch<UnitResponse<AchReceivedPayment>>(`/${id}`, { data: request })
}

public async advance(id: string): Promise<UnitResponse<AchReceivedPayment>> {
return this.httpPost<UnitResponse<AchReceivedPayment>>(`/${id}/advance`)
}

/**
* @param include
* Optional. A comma-separated list of related resources to include in the response.
* Related resources include: customer, account. See Getting Related Resources
*/
public async get(id: string, include?: string): Promise<UnitResponse<AchReceivedPayment & Include<Account[] | Customer[]>>> {
const params = { include: include ? `include=${include}` : "" }
return this.httpGet<UnitResponse<AchReceivedPayment & Include<Account[] | Customer[]>>>(`/${id}`, { params })
}

public async list(params?: ReceivedPaymentListParams): Promise<UnitResponse<AchReceivedPayment[] & Include<Account[] | Customer[] | Transaction[]>>> {
const parameters: any = {
"page[limit]": (params?.limit ? params.limit : 100),
"page[offset]": (params?.offset ? params.offset : 0),
...(params?.accountId && { "filter[accountId]": params.accountId }),
...(params?.customerId && { "filter[customerId]": params.customerId }),
...(params?.tags && { "filter[tags]": params.tags }),
...(params?.includeCompleted && { "filter[includeCompleted]": params.includeCompleted }),
"sort": params?.sort ? params.sort : "-createdAt",
"include": params?.include ? params.include : ""
}

if (params?.status)
params.status.forEach((s, idx) => {
parameters[`filter[status][${idx}]`] = s
})

return this.httpGet<UnitResponse<AchReceivedPayment[] & Include<Account[] | Customer[] | Transaction[]>>>("", { params: parameters })
}
}

export interface ReceivedPaymentListParams {
/**
* Maximum number of resources that will be returned. Maximum is 1000 resources. See Pagination.
* default: 100
*/
limit?: number

/**
* Number of resources to skip. See Pagination.
* default: 0
*/
offset?: number

/**
* Optional. Filters the results by the specified account id.
* default: empty
*/
accountId?: string

/**
* Optional. Filters the results by the specified customer id.
* default: empty
*/
customerId?: string

/**
* Optional. Filter Applications by Tags.
* default: empty
*/
tags?: object

/**
* Optional. Filter Received Payments by ReceivedPayment Status. Usage example: filter[status][0]=Pending&filter[status][1]=Advanced. cant be stated with includeCompleted.
*/
status?: string[]

/**
* Optional. Filter to include ReceivedPayment with Status 'Completed', default False. cant be stated with filter[status[]
*/
includeCompleted?: boolean

/**
* Optional. Leave empty or provide sort = createdAt for ascending order.Provide sort = -createdAt(leading minus sign) for descending order.
* default: sort=-createdAt
*/
sort?: string

/**
* Optional. A comma-separated list of related resources to include in the response.
* Related resources include: customer, account. [See Getting Related Resources](https://developers.unit.co/#intro-getting-related-resources)
*/
include?: string
}
172 changes: 103 additions & 69 deletions types/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ interface BasePaymentAttributes {
tags?: object
}

interface BasePaymentRelationships {
/**
* The Deposit Account of the customer.
*/
account: Relationship

/**
* The Customer the deposit account belongs to. This relationship is only available if the account belongs to a single customer, business or individual.
*/
customer?: Relationship

/**
* The list of Customers the deposit account belongs to. This relationship is only available if the account belongs to a multiple individual customers.
*/
customers?: Relationship[]

/**
* The Book Transaction generated by this payment.
*/
transaction?: Relationship
}

export interface AchPayment {
/**
* Identifier of the ACH payment resource.
Expand Down Expand Up @@ -79,26 +101,11 @@ export interface AchPayment {
* Describes relationships between the ACH payment and the originating deposit account and customer.
*/
relationships: {
/**
* The Deposit Account originating the transfer.
*/
account: Relationship

/**
* The Customer the deposit account belongs to. This relationship is only available if the account belongs to a single customer, business or individual.
*/
customer?: Relationship

/**
* The list of Customers the deposit account belongs to. This relationship is only available if the account belongs to multiple individual customers.
*/
customers?: Relationship[]

/**
* The Counterparty the payment to be made to.
*/
counterparty: Relationship
}
} & BasePaymentRelationships
}

interface BookPayment {
Expand All @@ -121,21 +128,6 @@ interface BookPayment {
* Describes relationships between the Book payment and the originating deposit account and customer.
*/
relationships: {
/**
* The Deposit Account originating the transfer.
*/
account: Relationship

/**
* The Customer the deposit account belongs to. This relationship is only available if the account belongs to a single customer, business or individual.
*/
customer?: Relationship

/**
* The list of Customers the deposit account belongs to. This relationship is only available if the account belongs to a multiple individual customers.
*/
customers?: Relationship[]

/**
* The Counterparty account the payment to be made to.
*/
Expand All @@ -145,12 +137,7 @@ interface BookPayment {
* The Customer the counterparty account belongs to. The customer is either a business or an individual, might be empty if there is more than one associated customer.
*/
counterpartyCustomer: Relationship

/**
* The Book Transaction generated by this payment.
*/
transaction: Relationship
}
} & BasePaymentRelationships
}

export interface WirePayment {
Expand Down Expand Up @@ -179,27 +166,7 @@ export interface WirePayment {
/**
* Describes relationships between the Wire payment and the originating deposit account and customer.
*/
relationships: {
/**
* The Deposit Account originating the transfer.
*/
account: Relationship

/**
* The Customer the deposit account belongs to. This relationship is only available if the account belongs to a single customer, business or individual.
*/
customer?: Relationship

/**
* The list of Customers the deposit account belongs to. This relationship is only available if the account belongs to a multiple individual customers.
*/
customers?: Relationship[]

/**
* The Wire Transaction generated by this payment.
*/
transaction: Relationship
}
relationships: BasePaymentRelationships
}

export interface BillPayment {
Expand All @@ -221,31 +188,98 @@ export interface BillPayment {
/**
* Describes relationships between the Wire payment and the originating deposit account and customer.
*/
relationships: {
relationships: BasePaymentRelationships
}

export interface AchReceivedPayment {
/**
* Identifier of the received payment resource.
*/
id: string

/**
* Type of the transaction resource. The value is always achReceivedPayment.
*/
type: "achReceivedPayment"

/**
*
*/
attributes: {
/**
* The Deposit Account creating the payment.
* The status of the Received Payment.
* One of Pending, Advanced, Completed or Returned, see (ReceivedPayment Statuses)[https://docs.unit.co/received-ach/#statuses].
* Common to all received payment types.
*/
account: Relationship
status: "Pending" | "Advanced" | "Completed" | "Returned"

/**
* The Customer the deposit account belongs to. This relationship is only available if the account belongs to a single customer, butisness or individual.
* Will be true if the received payment was or is being Advanced (has or has had the status Advanced).
* Common to all received payment types.
*/
customer?: Relationship
wasAdvanced: boolean

/**
* The list of Customers the deposit account belongs to. This relationship is only available if the account belongs to a multiple individual customer
* Shows the date on which the received ACH will be completed(settled or repaid).
*/
customers?: Relationship[]
completionDate: string

/**
* The BillPay Transaction generated by this payment.
* The reason if the received payment is Returned. See ACH return reasons.
*/
transaction: Relationship
}
returnReason?: string

/**
* Optional. Additional transaction description (maximum of 50 characters).
*/
addenda?: string

/**
* The name by which the originator is known to the receiver.
*/
companyName: string

/**
* The routing number of the party that originated the received ACH payment.
*/
counterpartyRoutingNumber: string

/**
* The ACH Trace Number.
*/
traceNumber: string

/**
* Optional. The 3-letter ACH Standard Entry Class (SEC) Code (e.g. WEB, CCD, PPD, etc.).
*/
secCode?: string

} & Pick<BasePaymentAttributes, "createdAt" | "amount" | "description" | "tags">


/**
* Describes relationships between the transaction resource and other resources (account, customer related transactions).
*/
relationships: {
/**
* The transaction of the received payment, created due to advance or when the ACH is processed.
*/
receivePaymentTransaction?: Relationship

/**
* The transaction that funded the Advance from the provisional credit operating account, if the received payment was advanced.
*/
paymentAdvanceTransaction?: Relationship

/**
* The transaction that repaid the advance once the received payment is completed.
*/
repayPaymentAdvanceTransaction?: Relationship
} & Pick<BasePaymentRelationships, "account" | "customer">
}

export interface PatchPaymentRequest {
type: "achPayment" | "bookPayment"
type: "achPayment" | "bookPayment" | "achReceivedPayment"
attributes: {
tags: object
}
Expand Down
3 changes: 3 additions & 0 deletions unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { BillPays } from "./resources"
import { Institutions } from "./resources/institutions"
import { AtmLocations } from "./resources/atmLocations"
import { CheckDeposits } from "./resources/checkDeposit"
import { ReceivedPayments } from "./resources/receivedPayments"

export class Unit {
public applications: Applications
Expand All @@ -36,6 +37,7 @@ export class Unit {
public fees: Fees
public counterparties: Counterparties
public payments: Payments
public receivedPayments: ReceivedPayments
public authorizations: Authorizations
public authorizationRequests: AuthorizationRequests
public helpers: typeof helpers
Expand Down Expand Up @@ -65,6 +67,7 @@ export class Unit {
this.counterparties = new Counterparties(token, basePath, config)
this.events = new Events(token, basePath, config)
this.payments = new Payments(token, basePath, config)
this.receivedPayments = new ReceivedPayments(token, basePath, config)
this.authorizations = new Authorizations(token, basePath, config)
this.authorizationRequests = new AuthorizationRequests(token, basePath, config)
this.statements = new Statments(token, basePath, config)
Expand Down