diff --git a/resources/index.ts b/resources/index.ts index 24a283e5..cbc3ba7a 100644 --- a/resources/index.ts +++ b/resources/index.ts @@ -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" diff --git a/resources/receivedPayments.ts b/resources/receivedPayments.ts new file mode 100644 index 00000000..78d0eb92 --- /dev/null +++ b/resources/receivedPayments.ts @@ -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> { + return this.httpPatch>(`/${id}`, { data: request }) + } + + public async advance(id: string): Promise> { + return this.httpPost>(`/${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>> { + const params = { include: include ? `include=${include}` : "" } + return this.httpGet>>(`/${id}`, { params }) + } + + public async list(params?: ReceivedPaymentListParams): Promise>> { + 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>>("", { 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 +} diff --git a/types/payments.ts b/types/payments.ts index 05243595..af9e76eb 100644 --- a/types/payments.ts +++ b/types/payments.ts @@ -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. @@ -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 { @@ -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. */ @@ -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 { @@ -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 { @@ -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 + + + /** + * 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 } export interface PatchPaymentRequest { - type: "achPayment" | "bookPayment" + type: "achPayment" | "bookPayment" | "achReceivedPayment" attributes: { tags: object } diff --git a/unit.ts b/unit.ts index f0edaa43..1b9a7e43 100644 --- a/unit.ts +++ b/unit.ts @@ -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 @@ -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 @@ -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)