Skip to content
14 changes: 14 additions & 0 deletions resources/bills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { UnitConfig, UnitResponse } from "../types/common"
import { Bill } from "../types/bill"
import { BaseResource } from "./baseResource"

export class Bills extends BaseResource {

constructor(token: string, basePath: string, config?: UnitConfig) {
super(token, basePath + "/bills", config)
}

public async get(id: string): Promise<UnitResponse<Bill>> {
return await this.httpGet<UnitResponse<Bill>>(`/${id}`)
}
}
1 change: 1 addition & 0 deletions resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export * from "./webhooks"
export * from "./chargeback"
export * from "./taxForms"
export * from "./creditApplication"
export * from "./bills"
56 changes: 56 additions & 0 deletions tests/bills.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Bill, Unit } from "../unit"

import dotenv from "dotenv"
dotenv.config()
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")

describe("Test Bills", () => {
test("Test Bill Resource", () => {
const bill: Bill = {
"type": "bill",
"id": "1",
"attributes": {
"status": "Pending",
"version": 1,
"createdAt": "2023-01-01T00:00:00.000Z",
"updatedAt": "2023-01-01T00:00:00.000Z",
"currency": "USD",
"total": 10000,
"description": "Electric bill payment"
},
"relationships": {
"org": {
"data": {
"type": "org",
"id": "1"
}
},
"vendor": {
"data": {
"type": "vendor",
"id": "100"
}
}
}
}

expect(bill.type).toBe("bill")
expect(bill.attributes.status).toBe("Pending")
expect(bill.attributes.total).toBe(10000)
})

test("Get Bill", async () => {
const billId = process.env.TEST_BILL_ID
if (billId) {
const res = await unit.bills.get(billId)
expect(res.data.type).toBe("bill")
expect(res.data.id).toBe(billId)
expect(typeof res.data.attributes.status).toBe("string")
expect(typeof res.data.attributes.version).toBe("number")
expect(typeof res.data.attributes.createdAt).toBe("string")
expect(typeof res.data.attributes.updatedAt).toBe("string")
expect(res.data.relationships.org.data.type).toBe("org")
expect(typeof res.data.relationships.org.data.id).toBe("string")
}
})
})
214 changes: 214 additions & 0 deletions types/bill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import { Relationship, Tags } from "./common"

export type BillStatus =
| "Draft"
| "Pending"
| "Scheduled"
| "Paid"
| "PaymentInProgress"
| "FundsPushed"
| "DeductionPaymentFailed"
| "VendorPaymentFailed"
| "RefundInitiated"
| "Refunded"
| "CancellationInitiated"
| "Canceled"
| "Archived"

export interface BillLineItem {
/**
* Optional. Reference identifier for the line item.
*/
reference?: string

/**
* Optional. Description of the line item.
*/
description?: string

/**
* Optional. Category identifier for the line item.
*/
categoryId?: string

/**
* Quantity of the line item.
*/
quantity: number

/**
* Unit price of the line item in cents.
*/
unitPrice: number
}

export interface PlatformPaymentMethod {
/**
* Date only. The deduction date.
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
*/
deductionDate?: string

/**
* Date only. The expected payment date.
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
*/
expectedDate?: string

/**
* Optional. Fee amount in cents. Positive values represent fees, negative values represent rebates.
*/
feeAmount?: number
}

export interface ExternalPaymentMethod {
/**
* Date only. The date the payment was made.
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
*/
paymentDate?: string
}

export type BillPaymentMethod =
| { ach: PlatformPaymentMethod; }
| { sameDayAch: PlatformPaymentMethod; }
| { check: PlatformPaymentMethod; }
| { wire: PlatformPaymentMethod; }
| { external: ExternalPaymentMethod; }

export interface Bill {
/**
* Identifier of the bill resource.
*/
id: string

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

/**
* JSON object representing the bill data.
*/
attributes: {
/**
* One of Draft, Pending, Scheduled, Paid, PaymentInProgress, FundsPushed, DeductionPaymentFailed,
* VendorPaymentFailed, RefundInitiated, Refunded, CancellationInitiated, Canceled, Archived.
*/
status: BillStatus

/**
* Version of the bill resource.
*/
version: number

/**
* The date and time the resource was created.
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
*/
createdAt: string

/**
* The date and time the resource was last updated.
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
*/
updatedAt: string

/**
* Optional. ISO 4217 currency code (e.g. "USD").
*/
currency?: string

/**
* Optional. Line items that make up the bill.
*/
lineItems?: BillLineItem[]

/**
* Date only. The date of the bill.
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
*/
billDate?: string

/**
* Date only. The due date of the bill.
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
*/
dueDate?: string

/**
* Optional. Invoice number for the bill.
*/
invoiceNumber?: string

/**
* Optional. Description of the bill.
*/
description?: string

/**
* Optional. Tax percentage applied to the bill (0-100).
*/
tax?: number

/**
* Optional. Total amount of the bill in cents.
*/
total?: number

/**
* Optional. The payment method used or scheduled for this bill.
*/
paymentMethod?: BillPaymentMethod

/**
* Optional. See [Tags](https://developers.unit.co/#tags).
*/
tags?: Tags

/**
* Optional. Reason for payment failure, present when status is DeductionPaymentFailed or VendorPaymentFailed.
*/
failureReason?: string
}

/**
* Describes relationships between the bill resource and other resources.
*/
relationships: {
/**
* The organization this bill belongs to.
*/
org: Relationship

/**
* Optional. The vendor this bill is for.
*/
vendor?: Relationship

/**
* Optional. The customer associated with this bill.
*/
customer?: Relationship

/**
* Optional. The uploaded bill file.
*/
billFile?: Relationship

/**
* Optional. The fee associated with this bill.
*/
fee?: Relationship

/**
* Optional. The payment associated with this bill.
*/
payment?: Relationship

/**
* Optional. The linked account for this bill.
*/
linkedAccount?: Relationship
}
}
3 changes: 2 additions & 1 deletion types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export * from "./webhooks"
export * from "./chargeback"
export * from "./taxForms"
export * from "./creditApplication"
export * from "./threadApplication"
export * from "./threadApplication"
export * from "./bill"
3 changes: 3 additions & 0 deletions unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { CashDeposits } from "./resources/cashDeposits"
import { CreditApplications } from "./resources/creditApplication"
import { RecurringRepayments } from "./resources/recurringRepayments"
import { Migrations } from "./resources/migrations"
import { Bills } from "./resources/bills"

export class Unit {
public applications: Applications
Expand Down Expand Up @@ -73,6 +74,7 @@ export class Unit {
public creditApplications: CreditApplications
public recurringRepayments: RecurringRepayments
public migrations: Migrations;
public bills: Bills

constructor(token: string, basePath: string, config?: UnitConfig) {
// remove all trailing slashes from user-provided basePath
Expand Down Expand Up @@ -114,6 +116,7 @@ export class Unit {
this.creditApplications = new CreditApplications(token, basePath, config)
this.recurringRepayments = new RecurringRepayments(token, basePath, config)
this.migrations = new Migrations(token, basePath, config)
this.bills = new Bills(token, basePath, config)
this.helpers = helpers
}

Expand Down