Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions api/spec/packages/aip/src/customers/credits/adjustment.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import "../../shared/index.tsp";
import "../../currencies/index.tsp";

/**
* A credit adjustment can be used to make manual adjustments to a customer's credit balance.
*
* Supported use-cases:
* - Usage correction
*/
@friendlyName("BillingCreditAdjustment")
@summary("Credit adjustment")
model CreditAdjustment {
...PickProperties<Shared.Resource, "name" | "description" | "labels">;

/**
* The currency of the granted credits.
*/
@visibility(Lifecycle.Create)
currency: Currencies.CurrencyCode;

/**
* Granted credit amount.
*/
@visibility(Lifecycle.Create)
amount: Shared.Numeric;
}
52 changes: 26 additions & 26 deletions api/spec/packages/aip/src/customers/credits/grant.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ enum CreditAvailabilityPolicy {
// Credits become eligible when the grant is created
OnCreation: "on_creation",

// Credits become eligible when payment is authorized
OnAuthorization: "on_authorization",
// // Credits become eligible when payment is authorized
// OnAuthorization: "on_authorization",

// Credits become eligible when payment is settled
OnSettlement: "on_settlement",
// // Credits become eligible when payment is settled
// OnSettlement: "on_settlement",
}

/**
Expand Down Expand Up @@ -255,28 +255,28 @@ model CreditGrant {
@maxValue(1000)
priority?: int16 = 10;

/**
* The timestamp when the credit grant becomes effective.
*
* Defaults to the current date and time.
*/
@visibility(Lifecycle.Create, Lifecycle.Read)
effective_at?: Shared.DateTime;

/**
* The duration after which the credit grant expires.
*
* Defaults to never expiring.
*/
@visibility(Lifecycle.Create, Lifecycle.Read)
expires_after?: Shared.ISO8601Duration;

/**
* The timestamp when the credit grant expires.
* Calculated from `effective_at` and `expires_after` if provided.
*/
@visibility(Lifecycle.Read)
expires_at?: Shared.DateTime;
// /**
// * The timestamp when the credit grant becomes effective.
// *
// * Defaults to the current date and time.
// */
// @visibility(Lifecycle.Create, Lifecycle.Read)
// effective_at?: Shared.DateTime;

// /**
// * The duration after which the credit grant expires.
// *
// * Defaults to never expiring.
// */
// @visibility(Lifecycle.Create, Lifecycle.Read)
// expires_after?: Shared.ISO8601Duration;

// /**
// * The timestamp when the credit grant expires.
// * Calculated from `effective_at` and `expires_after` if provided.
// */
// @visibility(Lifecycle.Read)
// expires_at?: Shared.DateTime;

/**
* Timestamp when the grant was voided.
Expand Down
58 changes: 33 additions & 25 deletions api/spec/packages/aip/src/customers/credits/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../../shared/index.tsp";
import "./grant.tsp";
import "./balance.tsp";
import "./ledger.tsp";
import "./adjustment.tsp";

using TypeSpec.Http;
using TypeSpec.OpenAPI;
Expand All @@ -19,11 +20,6 @@ namespace Customers;
*/
@friendlyName("ListCreditGrantsParamsFilter")
model ListCreditGrantsParamsFilter {
/**
* Filter credit grants by funding method.
*/
funding_method?: CreditFundingMethod;

/**
* Filter credit grants by status.
*/
Expand Down Expand Up @@ -77,24 +73,24 @@ interface CustomerCreditGrantsOperations {
): Shared.PagePaginatedResponse<CreditGrant> | Common.NotFound | Common.ErrorResponses;
}

interface CustomerCreditGrantVoidOperations {
/**
* Void a credit grant, forfeiting the remaining unused balance.
*
* Voiding is a forward-looking, irreversible operation. Credits already
* consumed by usage remain unaffected — only the remaining balance is
* forfeited. The grant transitions to `voided` status and a breakage
* ledger entry is recorded for the forfeited amount. Only `pending`
* and `active` grants can be voided.
*/
@post
@operationId("void-credit-grant")
@summary("Void credit grant")
voidGrant(
@path customerId: Shared.ULID,
@path creditGrantId: Shared.ULID,
): Shared.UpdateResponse<CreditGrant> | Common.NotFound | Common.ErrorResponses;
}
// interface CustomerCreditGrantVoidOperations {
// /**
// * Void a credit grant, forfeiting the remaining unused balance.
// *
// * Voiding is a forward-looking, irreversible operation. Credits already
// * consumed by usage remain unaffected — only the remaining balance is
// * forfeited. The grant transitions to `voided` status and a breakage
// * ledger entry is recorded for the forfeited amount. Only `pending`
// * and `active` grants can be voided.
// */
// @post
// @operationId("void-credit-grant")
// @summary("Void credit grant")
// voidGrant(
// @path customerId: Shared.ULID,
// @path creditGrantId: Shared.ULID,
// ): Shared.UpdateResponse<CreditGrant> | Common.NotFound | Common.ErrorResponses;
// }

/**
* Request body for updating the external payment settlement status of a credit grant.
Expand Down Expand Up @@ -196,6 +192,18 @@ interface CustomerCreditTransactionOperations {
): Shared.PagePaginatedResponse<CreditTransaction> | Common.NotFound | Common.ErrorResponses;
}

interface CustomerCreditAdjustmentOperations {
// TODO: add operations for credit adjustments
interface CustomerCreditAdjustmentsOperations {
/**
* A credit adjustment can be used to make manual adjustments to a customer's credit balance.
*
* Supported use-cases:
* - Usage correction
*/
@post
@operationId("create-credit-adjustment")
@summary("Create a credit adjustment")
create(
@path customerId: Shared.ULID,
@body credit_adjustment: Shared.CreateRequest<CreditAdjustment>,
): Shared.CreateResponse<CreditAdjustment> | Common.NotFound | Common.ErrorResponses;
}
9 changes: 7 additions & 2 deletions api/spec/packages/aip/src/konnect.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ interface CustomerCreditGrantsEndpoints
interface CustomerCreditBalanceEndpoints
extends Customers.CustomerCreditBalancesOperations {}

@route("/openmeter/customers/{customerId}/credits/adjustments")
@tag(Shared.CustomersTag)
interface CustomerCreditAdjustmentsEndpoints
extends Customers.CustomerCreditAdjustmentsOperations {}

@route("/openmeter/customers/{customerId}/credits/grants/{creditGrantId}")
@tag(Shared.CustomersTag)
interface CustomerCreditGrantEndpoints {
@route("/void")
voidGrant is Customers.CustomerCreditGrantVoidOperations.voidGrant;
// @route("/void")
// voidGrant is Customers.CustomerCreditGrantVoidOperations.voidGrant;

@route("/settlement/external")
updateExternalSettlement is Customers.CustomerCreditGrantExternalSettlementOperations.updateExternalSettlement;
Expand Down
9 changes: 7 additions & 2 deletions api/spec/packages/aip/src/openmeter.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ interface CustomerCreditGrantsEndpoints
interface CustomerCreditBalanceEndpoints
extends Customers.CustomerCreditBalancesOperations {}

@route("/openmeter/customers/{customerId}/credits/adjustments")
@tag(Shared.CustomersTag)
interface CustomerCreditAdjustmentsEndpoints
extends Customers.CustomerCreditAdjustmentsOperations {}

@route("/openmeter/customers/{customerId}/credits/grants/{creditGrantId}")
@tag(Shared.CustomersTag)
interface CustomerCreditGrantEndpoints {
@route("/void")
voidGrant is Customers.CustomerCreditGrantVoidOperations.voidGrant;
// @route("/void")
// voidGrant is Customers.CustomerCreditGrantVoidOperations.voidGrant;

@route("/settlement/external")
updateExternalSettlement is Customers.CustomerCreditGrantExternalSettlementOperations.updateExternalSettlement;
Expand Down
12 changes: 0 additions & 12 deletions api/types/entitlement.go

This file was deleted.

Loading
Loading