Skip to content

Commit 9cf48de

Browse files
committed
feat(subs): add BillingAnchor to API and DB
1 parent 3b4cfe9 commit 9cf48de

30 files changed

+2526
-2149
lines changed

api/api.gen.go

Lines changed: 1095 additions & 1080 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/client/go/client.gen.go

Lines changed: 1069 additions & 1054 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/client/javascript/src/client/schemas.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,12 @@ export interface components {
35543554
customerId?: string
35553555
/** @description The key of the customer. Provide either the key or ID. */
35563556
customerKey?: string
3557+
/**
3558+
* Format: date-time
3559+
* @description The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.
3560+
* @example 2023-01-01T01:01:01.001Z
3561+
*/
3562+
billingAnchor?: Date
35573563
}
35583564
/**
35593565
* @description A customer object.
@@ -8363,6 +8369,12 @@ export interface components {
83638369
customerId?: string
83648370
/** @description The key of the customer. Provide either the key or ID. */
83658371
customerKey?: string
8372+
/**
8373+
* Format: date-time
8374+
* @description The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.
8375+
* @example 2023-01-01T01:01:01.001Z
8376+
*/
8377+
billingAnchor?: Date
83668378
}
83678379
/** @description A consumer portal token.
83688380
*
@@ -9312,6 +9324,13 @@ export interface components {
93129324
* }
93139325
*/
93149326
readonly proRatingConfig?: components['schemas']['ProRatingConfig']
9327+
/**
9328+
* Billing anchor
9329+
* Format: date-time
9330+
* @description The normalizedbilling anchor of the subscription.
9331+
* @example 2023-01-01T01:01:01.001Z
9332+
*/
9333+
readonly billingAnchor: Date
93159334
}
93169335
/** @description A subscription add-on, represents concrete instances of an add-on for a given subscription. */
93179336
SubscriptionAddon: {
@@ -9681,6 +9700,13 @@ export interface components {
96819700
* }
96829701
*/
96839702
readonly proRatingConfig?: components['schemas']['ProRatingConfig']
9703+
/**
9704+
* Billing anchor
9705+
* Format: date-time
9706+
* @description The normalizedbilling anchor of the subscription.
9707+
* @example 2023-01-01T01:01:01.001Z
9708+
*/
9709+
readonly billingAnchor: Date
96849710
/** @description Alignment details enriched with the current billing period. */
96859711
alignment?: components['schemas']['SubscriptionAlignment']
96869712
/** @description The phases of the subscription. */

api/client/javascript/src/zod/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13832,6 +13832,12 @@ export const createSubscriptionBody = zod
1383213832
.describe('Alignment configuration for a plan or subscription.')
1383313833
.optional()
1383413834
.describe('What alignment settings the subscription should have.'),
13835+
billingAnchor: zod
13836+
.date()
13837+
.optional()
13838+
.describe(
13839+
'The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.'
13840+
),
1383513841
customerId: zod
1383613842
.string()
1383713843
.regex(createSubscriptionBodyCustomerIdRegExp)
@@ -13907,6 +13913,12 @@ export const createSubscriptionBody = zod
1390713913
.or(
1390813914
zod
1390913915
.object({
13916+
billingAnchor: zod
13917+
.date()
13918+
.optional()
13919+
.describe(
13920+
'The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.'
13921+
),
1391013922
customerId: zod
1391113923
.string()
1391213924
.regex(createSubscriptionBodyCustomerIdRegExpOne)

api/openapi.cloud.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13255,6 +13255,11 @@ components:
1325513255
minLength: 1
1325613256
maxLength: 256
1325713257
description: The key of the customer. Provide either the key or ID.
13258+
billingAnchor:
13259+
type: string
13260+
format: date-time
13261+
description: The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.
13262+
example: '2023-01-01T01:01:01.001Z'
1325813263
description: Create a custom subscription.
1325913264
Customer:
1326013265
type: object
@@ -19747,6 +19752,11 @@ components:
1974719752
minLength: 1
1974819753
maxLength: 256
1974919754
description: The key of the customer. Provide either the key or ID.
19755+
billingAnchor:
19756+
type: string
19757+
format: date-time
19758+
description: The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.
19759+
example: '2023-01-01T01:01:01.001Z'
1975019760
description: Create subscription based on plan.
1975119761
PortalToken:
1975219762
type: object
@@ -20849,6 +20859,7 @@ components:
2084920859
- customerId
2085020860
- currency
2085120861
- billingCadence
20862+
- billingAnchor
2085220863
properties:
2085320864
id:
2085420865
type: string
@@ -20951,6 +20962,13 @@ components:
2095120962
enabled: true
2095220963
mode: prorate_prices
2095320964
readOnly: true
20965+
billingAnchor:
20966+
type: string
20967+
format: date-time
20968+
description: The normalizedbilling anchor of the subscription.
20969+
example: '2023-01-01T01:01:01.001Z'
20970+
title: Billing anchor
20971+
readOnly: true
2095420972
description: Subscription is an exact subscription instance.
2095520973
SubscriptionAddon:
2095620974
type: object
@@ -21324,6 +21342,7 @@ components:
2132421342
- customerId
2132521343
- currency
2132621344
- billingCadence
21345+
- billingAnchor
2132721346
- phases
2132821347
properties:
2132921348
id:
@@ -21423,6 +21442,13 @@ components:
2142321442
enabled: true
2142421443
mode: prorate_prices
2142521444
readOnly: true
21445+
billingAnchor:
21446+
type: string
21447+
format: date-time
21448+
description: The normalizedbilling anchor of the subscription.
21449+
example: '2023-01-01T01:01:01.001Z'
21450+
title: Billing anchor
21451+
readOnly: true
2142621452
alignment:
2142721453
allOf:
2142821454
- $ref: '#/components/schemas/SubscriptionAlignment'

api/openapi.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13165,6 +13165,11 @@ components:
1316513165
minLength: 1
1316613166
maxLength: 256
1316713167
description: The key of the customer. Provide either the key or ID.
13168+
billingAnchor:
13169+
type: string
13170+
format: date-time
13171+
description: The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.
13172+
example: '2023-01-01T01:01:01.001Z'
1316813173
description: Create a custom subscription.
1316913174
Customer:
1317013175
type: object
@@ -20143,6 +20148,11 @@ components:
2014320148
minLength: 1
2014420149
maxLength: 256
2014520150
description: The key of the customer. Provide either the key or ID.
20151+
billingAnchor:
20152+
type: string
20153+
format: date-time
20154+
description: The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.
20155+
example: '2023-01-01T01:01:01.001Z'
2014620156
description: Create subscription based on plan.
2014720157
PortalToken:
2014820158
type: object
@@ -21383,6 +21393,7 @@ components:
2138321393
- customerId
2138421394
- currency
2138521395
- billingCadence
21396+
- billingAnchor
2138621397
properties:
2138721398
id:
2138821399
type: string
@@ -21485,6 +21496,13 @@ components:
2148521496
enabled: true
2148621497
mode: prorate_prices
2148721498
readOnly: true
21499+
billingAnchor:
21500+
type: string
21501+
format: date-time
21502+
description: The normalizedbilling anchor of the subscription.
21503+
example: '2023-01-01T01:01:01.001Z'
21504+
title: Billing anchor
21505+
readOnly: true
2148821506
description: Subscription is an exact subscription instance.
2148921507
SubscriptionAddon:
2149021508
type: object
@@ -21858,6 +21876,7 @@ components:
2185821876
- customerId
2185921877
- currency
2186021878
- billingCadence
21879+
- billingAnchor
2186121880
- phases
2186221881
properties:
2186321882
id:
@@ -21957,6 +21976,13 @@ components:
2195721976
enabled: true
2195821977
mode: prorate_prices
2195921978
readOnly: true
21979+
billingAnchor:
21980+
type: string
21981+
format: date-time
21982+
description: The normalizedbilling anchor of the subscription.
21983+
example: '2023-01-01T01:01:01.001Z'
21984+
title: Billing anchor
21985+
readOnly: true
2196021986
alignment:
2196121987
allOf:
2196221988
- $ref: '#/components/schemas/SubscriptionAlignment'

api/spec/src/productcatalog/subscription.tsp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ model Subscription {
112112
enabled: true,
113113
mode: ProRatingMode.proratePrices,
114114
};
115+
116+
/**
117+
* The normalizedbilling anchor of the subscription.
118+
*/
119+
@visibility(Lifecycle.Read)
120+
@summary("Billing anchor")
121+
billingAnchor: DateTime;
115122
}
116123

117124
/**
@@ -367,6 +374,11 @@ model CustomSubscriptionCreate {
367374
* The key of the customer. Provide either the key or ID.
368375
*/
369376
customerKey?: ExternalKey;
377+
378+
/**
379+
* The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.
380+
*/
381+
billingAnchor?: DateTime;
370382
}
371383

372384
/**
@@ -418,6 +430,11 @@ model PlanSubscriptionCreate {
418430
* The key of the customer. Provide either the key or ID.
419431
*/
420432
customerKey?: ExternalKey;
433+
434+
/**
435+
* The billing anchor of the subscription. The provided date will be normalized according to the billing cadence to the nearest recurrence before start time. If not provided, the subscription start time will be used.
436+
*/
437+
billingAnchor?: DateTime;
421438
}
422439

423440
/**

e2e/productcatalog_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,14 @@ func TestPlan(t *testing.T) {
417417
require.NoError(t, ct.FromSubscriptionTiming1(startTime))
418418

419419
create := api.SubscriptionCreate{}
420+
421+
anchorTime := time.Now().Add(-time.Hour).Truncate(time.Millisecond).UTC()
422+
420423
err := create.FromCustomSubscriptionCreate(api.CustomSubscriptionCreate{
421-
Timing: ct,
422-
CustomerKey: customer2.Key, // Let's use the key
423-
CustomPlan: customPlanInput, // For simplicity we can reuse the same plan input, we know its valid
424+
Timing: ct,
425+
CustomerKey: customer2.Key, // Let's use the key
426+
CustomPlan: customPlanInput, // For simplicity we can reuse the same plan input, we know its valid
427+
BillingAnchor: lo.ToPtr(anchorTime),
424428
})
425429
require.Nil(t, err)
426430

@@ -437,6 +441,7 @@ func TestPlan(t *testing.T) {
437441

438442
customSubscriptionId = subscription.Id
439443
require.Equal(t, "P1M", subscription.BillingCadence)
444+
require.True(t, anchorTime.UTC().Equal(subscription.BillingAnchor.UTC()), "billing anchor should be %s, got %s", anchorTime, subscription.BillingAnchor)
440445
require.Equal(t, api.ProRatingModeProratePrices, subscription.ProRatingConfig.Mode)
441446
require.True(t, subscription.ProRatingConfig.Enabled)
442447
})

openmeter/ent/db/migrate/schema.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)