Skip to content

Commit

Permalink
feat(api): add create and delete operations for internal accounts bal…
Browse files Browse the repository at this point in the history
…ance reports (#317)
  • Loading branch information
stainless-bot committed Jan 11, 2024
1 parent 38a3e62 commit 583efb5
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 146
configured_endpoints: 148
2 changes: 2 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ Types:

Methods:

- <code title="post /api/internal_accounts/{internal_account_id}/balance_reports">client.internalAccounts.balanceReports.<a href="./src/resources/internal-accounts/balance-reports.ts">create</a>(internalAccountId, { ...params }) -> BalanceReport</code>
- <code title="get /api/internal_accounts/{internal_account_id}/balance_reports/{id}">client.internalAccounts.balanceReports.<a href="./src/resources/internal-accounts/balance-reports.ts">retrieve</a>(internalAccountId, id) -> BalanceReport</code>
- <code title="get /api/internal_accounts/{internal_account_id}/balance_reports">client.internalAccounts.balanceReports.<a href="./src/resources/internal-accounts/balance-reports.ts">list</a>(internalAccountId, { ...params }) -> BalanceReportsPage</code>
- <code title="delete /api/internal_accounts/{internal_account_id}/balance_reports/{id}">client.internalAccounts.balanceReports.<a href="./src/resources/internal-accounts/balance-reports.ts">del</a>(internalAccountId, id) -> void</code>

# Ledgers

Expand Down
126 changes: 104 additions & 22 deletions src/resources/internal-accounts/balance-reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ import * as Shared from 'modern-treasury/resources/shared';
import { Page, type PageParams } from 'modern-treasury/pagination';

export class BalanceReports extends APIResource {
/**
* create balance reports
*/
create(
internalAccountId: string,
params: BalanceReportCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<BalanceReport> {
// @ts-expect-error idempotency key header isn't defined anymore but is included here for back-compat
const { 'Idempotency-Key': idempotencyKey, ...body } = params;
if (idempotencyKey) {
console.warn(
"The Idempotency-Key request param is deprecated, the 'idempotencyToken' option should be set instead",
);
}
return this._client.post(`/api/internal_accounts/${internalAccountId}/balance_reports`, {
body,
...options,
headers: { 'Idempotency-Key': idempotencyKey, ...options?.headers },
});
}

/**
* Get a single balance report for a given internal account.
*/
Expand Down Expand Up @@ -45,6 +67,16 @@ export class BalanceReports extends APIResource {
{ query, ...options },
);
}

/**
* Deletes a given balance report.
*/
del(internalAccountId: string, id: string, options?: Core.RequestOptions): Core.APIPromise<void> {
return this._client.delete(`/api/internal_accounts/${internalAccountId}/balance_reports/${id}`, {
...options,
headers: { Accept: '', ...options?.headers },
});
}
}

export class BalanceReportsPage extends Page<BalanceReport> {}
Expand Down Expand Up @@ -138,31 +170,80 @@ export namespace BalanceReport {
*/
vendor_code: string;

/**
* The type of `vendor_code` being reported. Can be one of `bai2`, `bankprov`,
* `bnk_dev`, `cleartouch`, `currencycloud`, `cross_river`, `dc_bank`, `dwolla`,
* `evolve`, `goldman_sachs`, `iso20022`, `jpmc`, `mx`, `signet`, `silvergate`,
* `swift`, or `us_bank`.
*/
vendor_code_type: string | null;
}
}

export interface BalanceReportCreateParams {
/**
* Value in specified currency's smallest unit. e.g. $10 would be represented
* as 1000.
*/
amount: number;

/**
* The date of the balance report in local time.
*/
as_of_date: string;

/**
* The time (24-hour clock) of the balance report in local time.
*/
as_of_time: string;

/**
* The specific type of balance report. One of `intraday`, `previous_day`,
* `real_time`, or `other`.
*/
balance_report_type: 'intraday' | 'other' | 'previous_day' | 'real_time';

/**
* An array of `Balance` objects.
*/
balances: Array<BalanceReportCreateParams.Balance>;
}

export namespace BalanceReportCreateParams {
export interface Balance {
/**
* The balance amount.
*/
amount: number;

/**
* The specific type of balance reported. One of `opening_ledger`,
* `closing_ledger`, `current_ledger`, `opening_available`,
* `opening_available_next_business_day`, `closing_available`, `current_available`,
* or `other`.
*/
balance_type:
| 'closing_available'
| 'closing_ledger'
| 'current_available'
| 'current_ledger'
| 'opening_available'
| 'opening_available_next_business_day'
| 'opening_ledger'
| 'other';

/**
* The code used by the bank when reporting this specific balance.
*/
vendor_code_type:
| 'bai2'
| 'bankprov'
| 'bnk_dev'
| 'cleartouch'
| 'column'
| 'cross_river'
| 'currencycloud'
| 'dc_bank'
| 'dwolla'
| 'evolve'
| 'goldman_sachs'
| 'iso20022'
| 'jpmc'
| 'mx'
| 'plaid'
| 'rspec_vendor'
| 'signet'
| 'silvergate'
| 'swift'
| 'us_bank'
| null;
vendor_code: string;

/**
* The type of `vendor_code` being reported. Can be one of `bai2`, `bankprov`,
* `bnk_dev`, `cleartouch`, `currencycloud`, `cross_river`, `dc_bank`, `dwolla`,
* `evolve`, `goldman_sachs`, `iso20022`, `jpmc`, `mx`, `signet`, `silvergate`,
* `swift`, or `us_bank`.
*/
vendor_code_type: string | null;
}
}

Expand All @@ -182,5 +263,6 @@ export interface BalanceReportListParams extends PageParams {
export namespace BalanceReports {
export import BalanceReport = BalanceReportsAPI.BalanceReport;
export import BalanceReportsPage = BalanceReportsAPI.BalanceReportsPage;
export import BalanceReportCreateParams = BalanceReportsAPI.BalanceReportCreateParams;
export import BalanceReportListParams = BalanceReportsAPI.BalanceReportListParams;
}
1 change: 1 addition & 0 deletions src/resources/internal-accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export {
BalanceReport,
BalanceReportCreateParams,
BalanceReportListParams,
BalanceReportsPage,
BalanceReports,
Expand Down
1 change: 1 addition & 0 deletions src/resources/internal-accounts/internal-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,6 @@ export namespace InternalAccounts {
export import BalanceReports = BalanceReportsAPI.BalanceReports;
export import BalanceReport = BalanceReportsAPI.BalanceReport;
export import BalanceReportsPage = BalanceReportsAPI.BalanceReportsPage;
export import BalanceReportCreateParams = BalanceReportsAPI.BalanceReportCreateParams;
export import BalanceReportListParams = BalanceReportsAPI.BalanceReportListParams;
}
29 changes: 29 additions & 0 deletions src/resources/invoices/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ export interface Invoice {
*/
invoicer_address: Invoice.InvoicerAddress | null;

/**
* The ledger account settlment object linked to the invoice.
*/
ledger_account_settlement_id: string | null;

/**
* This field will be true if this object exists in the live environment or false
* if it exists in the test environment.
Expand Down Expand Up @@ -420,11 +425,23 @@ export interface InvoiceCreateParams {
*/
fallback_payment_method?: string | null;

/**
* Whether to ingest the ledger_entries to populate the invoice line items. If this
* is false, then a line item must be provided. If this is true, line_items must be
* empty. Ignored if ledger_account_settlement_id is empty.
*/
ingest_ledger_entries?: boolean | null;

/**
* The invoice issuer's business address.
*/
invoicer_address?: InvoiceCreateParams.InvoicerAddress | null;

/**
* The ID of the virtual account the invoice should be paid to.
*/
ledger_account_settlement_id?: string | null;

/**
* Emails in addition to the counterparty email to send invoice status
* notifications to. At least one email is required if notifications are enabled
Expand Down Expand Up @@ -668,11 +685,23 @@ export interface InvoiceUpdateParams {
*/
fallback_payment_method?: string | null;

/**
* Whether to ingest the ledger_entries to populate the invoice line items. If this
* is false, then a line item must be provided. If this is true, line_items must be
* empty. Ignored if ledger_account_settlement_id is empty.
*/
ingest_ledger_entries?: boolean | null;

/**
* The invoice issuer's business address.
*/
invoicer_address?: InvoiceUpdateParams.InvoicerAddress | null;

/**
* The ID of the virtual account the invoice should be paid to.
*/
ledger_account_settlement_id?: string | null;

/**
* Emails in addition to the counterparty email to send invoice status
* notifications to. At least one email is required if notifications are enabled
Expand Down
1 change: 1 addition & 0 deletions src/resources/payment-orders/payment-orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ export namespace PaymentOrder {
| 'svb_transaction_held_for_sanctions_review'
| 'swift_mir'
| 'swift_uetr'
| 'umb_product_partner_account_number'
| 'usbank_payment_id'
| 'wells_fargo_payment_id'
| 'wells_fargo_trace_number';
Expand Down
1 change: 1 addition & 0 deletions src/resources/payment-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface PaymentReference {
| 'svb_transaction_held_for_sanctions_review'
| 'swift_mir'
| 'swift_uetr'
| 'umb_product_partner_account_number'
| 'usbank_payment_id'
| 'wells_fargo_payment_id'
| 'wells_fargo_trace_number';
Expand Down
1 change: 1 addition & 0 deletions src/resources/returns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export namespace ReturnObject {
| 'svb_transaction_held_for_sanctions_review'
| 'swift_mir'
| 'swift_uetr'
| 'umb_product_partner_account_number'
| 'usbank_payment_id'
| 'wells_fargo_payment_id'
| 'wells_fargo_trace_number';
Expand Down
55 changes: 55 additions & 0 deletions tests/api-resources/internal-accounts/balance-reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,41 @@ const modernTreasury = new ModernTreasury({
});

describe('resource balanceReports', () => {
test('create: only required params', async () => {
const responsePromise = modernTreasury.internalAccounts.balanceReports.create('string', {
amount: 0,
as_of_date: '2019-12-27',
as_of_time: 'string',
balance_report_type: 'intraday',
balances: [
{ amount: 0, balance_type: 'closing_available', vendor_code: 'string', vendor_code_type: 'string' },
{ amount: 0, balance_type: 'closing_available', vendor_code: 'string', vendor_code_type: 'string' },
{ amount: 0, balance_type: 'closing_available', vendor_code: 'string', vendor_code_type: 'string' },
],
});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('create: required and optional params', async () => {
const response = await modernTreasury.internalAccounts.balanceReports.create('string', {
amount: 0,
as_of_date: '2019-12-27',
as_of_time: 'string',
balance_report_type: 'intraday',
balances: [
{ amount: 0, balance_type: 'closing_available', vendor_code: 'string', vendor_code_type: 'string' },
{ amount: 0, balance_type: 'closing_available', vendor_code: 'string', vendor_code_type: 'string' },
{ amount: 0, balance_type: 'closing_available', vendor_code: 'string', vendor_code_type: 'string' },
],
});
});

test('retrieve', async () => {
const responsePromise = modernTreasury.internalAccounts.balanceReports.retrieve('string', 'string');
const rawResponse = await responsePromise.asResponse();
Expand Down Expand Up @@ -58,4 +93,24 @@ describe('resource balanceReports', () => {
),
).rejects.toThrow(ModernTreasury.NotFoundError);
});

test('del', async () => {
const responsePromise = modernTreasury.internalAccounts.balanceReports.del('string', 'string');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('del: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
modernTreasury.internalAccounts.balanceReports.del('string', 'string', {
path: '/_stainless_unknown_path',
}),
).rejects.toThrow(ModernTreasury.NotFoundError);
});
});
8 changes: 6 additions & 2 deletions tests/api-resources/invoices/invoices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('resource invoices', () => {
currency: 'AED',
description: 'string',
fallback_payment_method: 'string',
ingest_ledger_entries: true,
invoicer_address: {
line1: 'string',
line2: 'string',
Expand All @@ -89,6 +90,7 @@ describe('resource invoices', () => {
postal_code: 'string',
country: 'string',
},
ledger_account_settlement_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
notification_email_addresses: ['string', 'string', 'string'],
notifications_enabled: true,
payment_effective_date: '2019-12-27',
Expand All @@ -97,7 +99,7 @@ describe('resource invoices', () => {
receiving_account_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
recipient_email: 'string',
recipient_name: 'string',
virtual_account_id: 'string',
virtual_account_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
});
});

Expand Down Expand Up @@ -196,6 +198,7 @@ describe('resource invoices', () => {
description: 'string',
due_date: '2019-12-27T18:11:19.117Z',
fallback_payment_method: 'string',
ingest_ledger_entries: true,
invoicer_address: {
line1: 'string',
line2: 'string',
Expand All @@ -204,6 +207,7 @@ describe('resource invoices', () => {
postal_code: 'string',
country: 'string',
},
ledger_account_settlement_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
notification_email_addresses: ['string', 'string', 'string'],
notifications_enabled: true,
originating_account_id: 'string',
Expand All @@ -214,7 +218,7 @@ describe('resource invoices', () => {
recipient_email: 'string',
recipient_name: 'string',
status: 'string',
virtual_account_id: 'string',
virtual_account_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
},
{ path: '/_stainless_unknown_path' },
),
Expand Down

0 comments on commit 583efb5

Please sign in to comment.