diff --git a/.stats.yml b/.stats.yml index 771d33ac..d2f44f94 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 104 +configured_endpoints: 106 diff --git a/api.md b/api.md index 9edf0531..314dba0e 100644 --- a/api.md +++ b/api.md @@ -21,6 +21,7 @@ Types: Types: - Account +- AccountSpendLimits - BusinessAccount Methods: @@ -28,6 +29,7 @@ Methods: - client.accounts.retrieve(accountToken) -> Account - client.accounts.update(accountToken, { ...params }) -> Account - client.accounts.list({ ...params }) -> AccountsCursorPage +- client.accounts.retrieveSpendLimits(accountToken) -> AccountSpendLimits ## CreditConfigurations @@ -118,6 +120,7 @@ Methods: Types: - Card +- CardSpendLimits - EmbedRequestParams - SpendLimitDuration - CardEmbedResponse @@ -132,6 +135,7 @@ Methods: - client.cards.embed({ ...params }) -> string - client.cards.provision(cardToken, { ...params }) -> CardProvisionResponse - client.cards.reissue(cardToken, { ...params }) -> Card +- client.cards.retrieveSpendLimits(cardToken) -> CardSpendLimits - client.cards.getEmbedHTML(...args) -> Promise<string> - client.cards.getEmbedURL(...args) -> string diff --git a/src/index.ts b/src/index.ts index 0a57f390..579c295c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -248,6 +248,7 @@ export namespace Lithic { export import Accounts = API.Accounts; export import Account = API.Account; + export import AccountSpendLimits = API.AccountSpendLimits; export import BusinessAccount = API.BusinessAccount; export import AccountsCursorPage = API.AccountsCursorPage; export import AccountUpdateParams = API.AccountUpdateParams; @@ -293,6 +294,7 @@ export namespace Lithic { export import Cards = API.Cards; export import Card = API.Card; + export import CardSpendLimits = API.CardSpendLimits; export import EmbedRequestParams = API.EmbedRequestParams; export import SpendLimitDuration = API.SpendLimitDuration; export import CardEmbedResponse = API.CardEmbedResponse; diff --git a/src/resources/accounts/accounts.ts b/src/resources/accounts/accounts.ts index b7b0c4d4..174f1577 100644 --- a/src/resources/accounts/accounts.ts +++ b/src/resources/accounts/accounts.ts @@ -50,6 +50,20 @@ export class Accounts extends APIResource { } return this._client.getAPIList('/accounts', AccountsCursorPage, { query, ...options }); } + + /** + * Get an Account's available spend limits, which is based on the spend limit + * configured on the Account and the amount already spent over the spend limit's + * duration. For example, if the Account has a daily spend limit of $1000 + * configured, and has spent $600 in the last 24 hours, the available spend limit + * returned would be $400. + */ + retrieveSpendLimits( + accountToken: string, + options?: Core.RequestOptions, + ): Core.APIPromise { + return this._client.get(`/accounts/${accountToken}/spend_limits`, options); + } } export class AccountsCursorPage extends CursorPage {} @@ -176,6 +190,33 @@ export namespace Account { } } +export interface AccountSpendLimits { + available_spend_limit?: AccountSpendLimits.AvailableSpendLimit; + + required?: unknown; +} + +export namespace AccountSpendLimits { + export interface AvailableSpendLimit { + /** + * The available spend limit relative to the daily limit configured on the Account. + */ + daily?: number; + + /** + * The available spend limit relative to the lifetime limit configured on the + * Account. + */ + lifetime?: number; + + /** + * The available spend limit relative to the monthly limit configured on the + * Account. + */ + monthly?: number; + } +} + export interface BusinessAccount { /** * Account token @@ -281,6 +322,7 @@ export interface AccountListParams extends CursorPageParams { export namespace Accounts { export import Account = AccountsAPI.Account; + export import AccountSpendLimits = AccountsAPI.AccountSpendLimits; export import BusinessAccount = AccountsAPI.BusinessAccount; export import AccountsCursorPage = AccountsAPI.AccountsCursorPage; export import AccountUpdateParams = AccountsAPI.AccountUpdateParams; diff --git a/src/resources/accounts/index.ts b/src/resources/accounts/index.ts index 0de6b0ab..a1dcfbc1 100644 --- a/src/resources/accounts/index.ts +++ b/src/resources/accounts/index.ts @@ -2,6 +2,7 @@ export { Account, + AccountSpendLimits, BusinessAccount, AccountUpdateParams, AccountListParams, diff --git a/src/resources/cards/cards.ts b/src/resources/cards/cards.ts index b8afb9a7..600fd14b 100644 --- a/src/resources/cards/cards.ts +++ b/src/resources/cards/cards.ts @@ -180,6 +180,16 @@ export class Cards extends APIResource { reissue(cardToken: string, body: CardReissueParams, options?: Core.RequestOptions): Core.APIPromise { return this._client.post(`/cards/${cardToken}/reissue`, { body, ...options }); } + + /** + * Get a Card's available spend limit, which is based on the spend limit configured + * on the Card and the amount already spent over the spend limit's duration. For + * example, if the Card has a monthly spend limit of $1000 configured, and has + * spent $600 in the last month, the available spend limit returned would be $400. + */ + retrieveSpendLimits(cardToken: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.get(`/cards/${cardToken}/spend_limits`, options); + } } export class CardsCursorPage extends CursorPage {} @@ -362,6 +372,31 @@ export namespace Card { } } +export interface CardSpendLimits { + available_spend_limit?: CardSpendLimits.AvailableSpendLimit; + + required?: unknown; +} + +export namespace CardSpendLimits { + export interface AvailableSpendLimit { + /** + * The available spend limit relative to the annual limit configured on the Card. + */ + annually?: number; + + /** + * The available spend limit relative to the forever limit configured on the Card. + */ + forever?: number; + + /** + * The available spend limit relative to the monthly limit configured on the Card. + */ + monthly?: number; + } +} + export interface EmbedRequestParams { /** * Globally unique identifier for the card to be displayed. @@ -779,6 +814,7 @@ export interface CardReissueParams { export namespace Cards { export import Card = CardsAPI.Card; + export import CardSpendLimits = CardsAPI.CardSpendLimits; export import EmbedRequestParams = CardsAPI.EmbedRequestParams; export import SpendLimitDuration = CardsAPI.SpendLimitDuration; export import CardEmbedResponse = CardsAPI.CardEmbedResponse; diff --git a/src/resources/cards/index.ts b/src/resources/cards/index.ts index f623b43a..0b30c544 100644 --- a/src/resources/cards/index.ts +++ b/src/resources/cards/index.ts @@ -9,6 +9,7 @@ export { export { BalanceListParams, Balances } from './balances'; export { Card, + CardSpendLimits, EmbedRequestParams, SpendLimitDuration, CardEmbedResponse, diff --git a/src/resources/index.ts b/src/resources/index.ts index fa3a343d..6fd1761b 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -4,6 +4,7 @@ export * from './shared'; export { APIStatus } from './top-level'; export { Account, + AccountSpendLimits, BusinessAccount, AccountUpdateParams, AccountListParams, @@ -51,6 +52,7 @@ export { export { Balance, BalanceListParams, BalancesSinglePage, Balances } from './balances'; export { Card, + CardSpendLimits, EmbedRequestParams, SpendLimitDuration, CardEmbedResponse, diff --git a/tests/api-resources/accounts/accounts.test.ts b/tests/api-resources/accounts/accounts.test.ts index 81a5b16a..1285c7de 100644 --- a/tests/api-resources/accounts/accounts.test.ts +++ b/tests/api-resources/accounts/accounts.test.ts @@ -72,4 +72,24 @@ describe('resource accounts', () => { ), ).rejects.toThrow(Lithic.NotFoundError); }); + + test('retrieveSpendLimits', async () => { + const responsePromise = lithic.accounts.retrieveSpendLimits('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + 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('retrieveSpendLimits: 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( + lithic.accounts.retrieveSpendLimits('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + path: '/_stainless_unknown_path', + }), + ).rejects.toThrow(Lithic.NotFoundError); + }); }); diff --git a/tests/api-resources/cards/cards.test.ts b/tests/api-resources/cards/cards.test.ts index 11337dcd..90ef8d1b 100644 --- a/tests/api-resources/cards/cards.test.ts +++ b/tests/api-resources/cards/cards.test.ts @@ -163,4 +163,24 @@ describe('resource cards', () => { expect(dataAndResponse.data).toBe(response); expect(dataAndResponse.response).toBe(rawResponse); }); + + test('retrieveSpendLimits', async () => { + const responsePromise = lithic.cards.retrieveSpendLimits('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + 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('retrieveSpendLimits: 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( + lithic.cards.retrieveSpendLimits('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + path: '/_stainless_unknown_path', + }), + ).rejects.toThrow(Lithic.NotFoundError); + }); });