Skip to content

Commit

Permalink
feat(api): introduce bulk transaction create (#365)
Browse files Browse the repository at this point in the history
feat(api): add line item metadata
  • Loading branch information
stainless-app[bot] committed Mar 21, 2024
1 parent 770f57a commit 1114cc5
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 5 deletions.
61 changes: 58 additions & 3 deletions src/resources/bulk-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface BulkRequest {
/**
* One of payment_order, expected_payment, or ledger_transaction.
*/
resource_type: 'payment_order' | 'ledger_transaction' | 'expected_payment';
resource_type: 'payment_order' | 'ledger_transaction' | 'transaction' | 'expected_payment';

/**
* One of pending, processing, or completed.
Expand Down Expand Up @@ -120,7 +120,7 @@ export interface BulkRequestCreateParams {
/**
* One of payment_order, expected_payment, or ledger_transaction.
*/
resource_type: 'payment_order' | 'ledger_transaction' | 'expected_payment';
resource_type: 'payment_order' | 'ledger_transaction' | 'transaction' | 'expected_payment';

/**
* An array of objects where each object contains the input params for a single
Expand All @@ -130,6 +130,7 @@ export interface BulkRequestCreateParams {
| BulkRequestCreateParams.PaymentOrderAsyncCreateRequest
| BulkRequestCreateParams.ExpectedPaymentCreateRequest
| BulkRequestCreateParams.LedgerTransactionCreateRequest
| BulkRequestCreateParams.TransactionCreateRequest
| BulkRequestCreateParams.PaymentOrderUpdateRequestWithID
| BulkRequestCreateParams.ExpectedPaymentUpdateRequestWithID
| BulkRequestCreateParams.LedgerTransactionUpdateRequestWithID
Expand Down Expand Up @@ -1171,6 +1172,60 @@ export namespace BulkRequestCreateParams {
}
}

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

/**
* The date on which the transaction occurred.
*/
as_of_date: string | null;

/**
* Either `credit` or `debit`.
*/
direction: string;

/**
* The ID of the relevant Internal Account.
*/
internal_account_id: string;

/**
* When applicable, the bank-given code that determines the transaction's category.
* For most banks this is the BAI2/BTRS transaction code.
*/
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`, `us_bank`, or others.
*/
vendor_code_type: string;

/**
* Additional data represented as key-value pairs. Both the key and value must be
* strings.
*/
metadata?: Record<string, string>;

/**
* This field will be `true` if the transaction has posted to the account.
*/
posted?: boolean;

/**
* The transaction detail text that often appears in on your bank statement and in
* your banking portal.
*/
vendor_description?: string | null;
}

export interface PaymentOrderUpdateRequestWithID {
id?: string;

Expand Down Expand Up @@ -1883,7 +1938,7 @@ export interface BulkRequestListParams extends PageParams {
/**
* One of payment_order, expected_payment, or ledger_transaction.
*/
resource_type?: 'payment_order' | 'ledger_transaction' | 'expected_payment';
resource_type?: 'payment_order' | 'ledger_transaction' | 'transaction' | 'expected_payment';

/**
* One of pending, processing, or completed.
Expand Down
6 changes: 4 additions & 2 deletions src/resources/bulk-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as BulkResultsAPI from 'modern-treasury/resources/bulk-results';
import * as ExpectedPaymentsAPI from 'modern-treasury/resources/expected-payments';
import * as LedgerTransactionsAPI from 'modern-treasury/resources/ledger-transactions/ledger-transactions';
import * as PaymentOrdersAPI from 'modern-treasury/resources/payment-orders/payment-orders';
import * as TransactionsAPI from 'modern-treasury/resources/transactions/transactions';
import { Page, type PageParams } from 'modern-treasury/pagination';

export class BulkResults extends APIResource {
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface BulkResult {
| PaymentOrdersAPI.PaymentOrder
| ExpectedPaymentsAPI.ExpectedPayment
| LedgerTransactionsAPI.LedgerTransaction
| TransactionsAPI.Transaction
| BulkResult.BulkError;

/**
Expand All @@ -64,7 +66,7 @@ export interface BulkResult {
* same as the `resource_type` of the bulk request. For a failed bulk result, this
* is always bulk_error
*/
entity_type: 'payment_order' | 'ledger_transaction' | 'expected_payment' | 'bulk_error';
entity_type: 'payment_order' | 'ledger_transaction' | 'transaction' | 'expected_payment' | 'bulk_error';

/**
* This field will be true if this object exists in the live environment or false
Expand Down Expand Up @@ -141,7 +143,7 @@ export interface BulkResultListParams extends PageParams {
* The type of the request that created this result. bulk_request is the only
* supported `request_type`
*/
entity_type?: 'payment_order' | 'ledger_transaction' | 'expected_payment' | 'bulk_error';
entity_type?: 'payment_order' | 'ledger_transaction' | 'transaction' | 'expected_payment' | 'bulk_error';

/**
* Unique identifier for the request that created this bulk result. This is the ID
Expand Down
18 changes: 18 additions & 0 deletions src/resources/invoices/line-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export interface InvoiceLineItem {
*/
live_mode: boolean;

/**
* Additional data represented as key-value pairs. Both the key and value must be
* strings.
*/
metadata: Record<string, string>;

/**
* The name of the line item, typically a product or SKU name.
*/
Expand Down Expand Up @@ -176,6 +182,12 @@ export interface LineItemCreateParams {
*/
direction?: string;

/**
* Additional data represented as key-value pairs. Both the key and value must be
* strings.
*/
metadata?: Record<string, string>;

/**
* The number of units of a product or service that this line item is for. Must be
* a whole number. Defaults to 1 if not provided.
Expand Down Expand Up @@ -203,6 +215,12 @@ export interface LineItemUpdateParams {
*/
direction?: string;

/**
* Additional data represented as key-value pairs. Both the key and value must be
* strings.
*/
metadata?: Record<string, string>;

/**
* The name of the line item, typically a product or SKU name.
*/
Expand Down
51 changes: 51 additions & 0 deletions src/resources/transactions/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ export interface Transaction {

discarded_at: string | null;

/**
* Associated serialized foreign exchange rate information.
*/
foreign_exchange_rate: Transaction.ForeignExchangeRate | null;

/**
* The ID of the relevant Internal Account.
*/
Expand Down Expand Up @@ -254,6 +259,52 @@ export interface Transaction {
vendor_description?: string | null;
}

export namespace Transaction {
/**
* Associated serialized foreign exchange rate information.
*/
export interface ForeignExchangeRate {
/**
* Amount in the lowest denomination of the `base_currency` to convert, often
* called the "sell" amount.
*/
base_amount: number;

/**
* Currency to convert, often called the "sell" currency.
*/
base_currency: Shared.Currency | null;

/**
* The exponent component of the rate. The decimal is calculated as `value` / (10 ^
* `exponent`).
*/
exponent: number;

/**
* A string representation of the rate.
*/
rate_string: string;

/**
* Amount in the lowest denomination of the `target_currency`, often called the
* "buy" amount.
*/
target_amount: number;

/**
* Currency to convert the `base_currency` to, often called the "buy" currency.
*/
target_currency: Shared.Currency | null;

/**
* The whole number component of the rate. The decimal is calculated as `value` /
* (10 ^ `exponent`).
*/
value: number;
}
}

export interface TransactionCreateParams {
/**
* Value in specified currency's smallest unit. e.g. $10 would be represented
Expand Down
2 changes: 2 additions & 0 deletions tests/api-resources/invoices/line-items.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('resource lineItems', () => {
unit_amount: 0,
description: 'string',
direction: 'string',
metadata: { key: 'value', foo: 'bar', modern: 'treasury' },
quantity: 0,
unit_amount_decimal: 'string',
});
Expand Down Expand Up @@ -80,6 +81,7 @@ describe('resource lineItems', () => {
{
description: 'string',
direction: 'string',
metadata: { key: 'value', foo: 'bar', modern: 'treasury' },
name: 'string',
quantity: 0,
unit_amount: 0,
Expand Down

0 comments on commit 1114cc5

Please sign in to comment.