Skip to content

Commit

Permalink
feat(api): add get spend_limits endpoints to cards and accounts (
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Nov 28, 2023
1 parent 6d51f8c commit b1acf04
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 104
configured_endpoints: 106
4 changes: 4 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ Types:
Types:

- <code><a href="./src/resources/accounts/accounts.ts">Account</a></code>
- <code><a href="./src/resources/accounts/accounts.ts">AccountSpendLimits</a></code>
- <code><a href="./src/resources/accounts/accounts.ts">BusinessAccount</a></code>

Methods:

- <code title="get /accounts/{account_token}">client.accounts.<a href="./src/resources/accounts/accounts.ts">retrieve</a>(accountToken) -> Account</code>
- <code title="patch /accounts/{account_token}">client.accounts.<a href="./src/resources/accounts/accounts.ts">update</a>(accountToken, { ...params }) -> Account</code>
- <code title="get /accounts">client.accounts.<a href="./src/resources/accounts/accounts.ts">list</a>({ ...params }) -> AccountsCursorPage</code>
- <code title="get /accounts/{account_token}/spend_limits">client.accounts.<a href="./src/resources/accounts/accounts.ts">retrieveSpendLimits</a>(accountToken) -> AccountSpendLimits</code>

## CreditConfigurations

Expand Down Expand Up @@ -118,6 +120,7 @@ Methods:
Types:

- <code><a href="./src/resources/cards/cards.ts">Card</a></code>
- <code><a href="./src/resources/cards/cards.ts">CardSpendLimits</a></code>
- <code><a href="./src/resources/cards/cards.ts">EmbedRequestParams</a></code>
- <code><a href="./src/resources/cards/cards.ts">SpendLimitDuration</a></code>
- <code><a href="./src/resources/cards/cards.ts">CardEmbedResponse</a></code>
Expand All @@ -132,6 +135,7 @@ Methods:
- <code title="get /embed/card">client.cards.<a href="./src/resources/cards/cards.ts">embed</a>({ ...params }) -> string</code>
- <code title="post /cards/{card_token}/provision">client.cards.<a href="./src/resources/cards/cards.ts">provision</a>(cardToken, { ...params }) -> CardProvisionResponse</code>
- <code title="post /cards/{card_token}/reissue">client.cards.<a href="./src/resources/cards/cards.ts">reissue</a>(cardToken, { ...params }) -> Card</code>
- <code title="get /cards/{card_token}/spend_limits">client.cards.<a href="./src/resources/cards/cards.ts">retrieveSpendLimits</a>(cardToken) -> CardSpendLimits</code>
- <code>client.cards.<a href="./src/resources/cards/cards.ts">getEmbedHTML</a>(...args) -> Promise&lt;string&gt;</code>
- <code>client.cards.<a href="./src/resources/cards/cards.ts">getEmbedURL</a>(...args) -> string</code>

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions src/resources/accounts/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountSpendLimits> {
return this._client.get(`/accounts/${accountToken}/spend_limits`, options);
}
}

export class AccountsCursorPage extends CursorPage<Account> {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/resources/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export {
Account,
AccountSpendLimits,
BusinessAccount,
AccountUpdateParams,
AccountListParams,
Expand Down
36 changes: 36 additions & 0 deletions src/resources/cards/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ export class Cards extends APIResource {
reissue(cardToken: string, body: CardReissueParams, options?: Core.RequestOptions): Core.APIPromise<Card> {
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<CardSpendLimits> {
return this._client.get(`/cards/${cardToken}/spend_limits`, options);
}
}

export class CardsCursorPage extends CursorPage<Card> {}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/resources/cards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {
export { BalanceListParams, Balances } from './balances';
export {
Card,
CardSpendLimits,
EmbedRequestParams,
SpendLimitDuration,
CardEmbedResponse,
Expand Down
2 changes: 2 additions & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './shared';
export { APIStatus } from './top-level';
export {
Account,
AccountSpendLimits,
BusinessAccount,
AccountUpdateParams,
AccountListParams,
Expand Down Expand Up @@ -51,6 +52,7 @@ export {
export { Balance, BalanceListParams, BalancesSinglePage, Balances } from './balances';
export {
Card,
CardSpendLimits,
EmbedRequestParams,
SpendLimitDuration,
CardEmbedResponse,
Expand Down
20 changes: 20 additions & 0 deletions tests/api-resources/accounts/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
20 changes: 20 additions & 0 deletions tests/api-resources/cards/cards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit b1acf04

Please sign in to comment.