feat(subplat): add free access program to billing-and-subscriptions API#20859
Open
StaberindeZA wants to merge 1 commit into
Open
feat(subplat): add free access program to billing-and-subscriptions API#20859StaberindeZA wants to merge 1 commit into
StaberindeZA wants to merge 1 commit into
Conversation
Because: * Relying parties fetch current subscriptions via GET v1/billing-and-subscriptions, but Free Access Program grants were not represented. This commit: * Adds a `free_access` subscription type sourcing product identity from the related offering. * Filters grants by the projection's per-client capabilities. * Gates the code behind a FreeAccessProgramConfig feature flag (default off). Closes #PAY-3790
0f461d2 to
9d11d75
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the Payments “billing-and-subscriptions” response model to include Free Access Program (FAP) grants as a new free_access subscription type, gated behind a feature flag so relying parties can see non-Stripe access entitlements when enabled.
Changes:
- Add
free_accesssubscription schema + transformer, and append FAP-derived subscriptions to/v1/billing-and-subscriptionsoutput when enabled. - Add Free Access Program feature-flag configuration and wire the FAP projection manager into the Payments API.
- Add account-layer support to fetch a user’s current primary email (used to look up FAP membership), with tests.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/shared/account/account/src/lib/account.repository.ts | Adds repository query to fetch the current primary email row by uid. |
| libs/shared/account/account/src/lib/account.manager.ts | Exposes getPrimaryEmailByUid on AccountManager for service-layer use. |
| libs/shared/account/account/src/lib/account.manager.in.spec.ts | Integration tests for primary-email lookup behavior. |
| libs/payments/api-server/src/lib/util/transformToFreeAccessSubscription.ts | Adds mapping utility to build a free_access subscription record. |
| libs/payments/api-server/src/lib/util/transformToFreeAccessSubscription.spec.ts | Unit tests for the free-access subscription transformer. |
| libs/payments/api-server/src/lib/free-access-program.config.ts | Introduces feature-flag config class + mock provider for tests. |
| libs/payments/api-server/src/lib/billing-and-subscriptions.service.ts | Integrates FAP projection lookup and emits free_access subscriptions. |
| libs/payments/api-server/src/lib/billing-and-subscriptions.service.spec.ts | Adds test coverage for FAP-only and mixed subscription scenarios + flag gating. |
| libs/payments/api-server/src/lib/billing-and-subscriptions.schema.ts | Extends Zod discriminated union to include free_access subscriptions. |
| libs/payments/api-server/src/lib/billing-and-subscriptions.controller.spec.ts | Updates controller test module wiring for new dependencies/config. |
| libs/payments/api-server/src/index.ts | Exports the new Free Access Program config type/provider. |
| apps/payments/api/src/config/index.ts | Adds nested freeAccessProgramConfig to the Payments API root config schema. |
| apps/payments/api/src/app/app.module.ts | Registers FreeAccessProgramConfigurationManager in the Payments API module. |
| apps/payments/api/.env | Adds the env var scaffold for the feature flag (default false). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+285
to
+304
| // Free Access Program grants have no Stripe subscription or Price. The | ||
| // projection already maps client ids to the capabilities granted for this | ||
| // customer, so filter on it directly rather than re-deriving from Stripe | ||
| // prices. Product identity is sourced from the related offering; price data | ||
| // is dummy since there is no real subscription price. | ||
| if (freeAccessEntry && clientId.toLowerCase() in freeAccessEntry.capabilities) { | ||
| for (const apiIdentifier of freeAccessEntry.offeringApiIdentifiers) { | ||
| const offering = ( | ||
| await this.productConfigurationManager.getEligibilityContentByOffering( | ||
| apiIdentifier | ||
| ) | ||
| ).getOffering(); | ||
| subscriptions.push( | ||
| transformToFreeAccessSubscription({ | ||
| offeringApiIdentifier: apiIdentifier, | ||
| productId: offering.stripeProductId, | ||
| }) | ||
| ); | ||
| } | ||
| } |
Comment on lines
+104
to
+107
| @Type(() => FreeAccessProgramConfig) | ||
| @ValidateNested() | ||
| @IsDefined() | ||
| public readonly freeAccessProgramConfig!: Partial<FreeAccessProgramConfig>; |
Comment on lines
+9
to
+17
| export class FreeAccessProgramConfig { | ||
| @Transform(({ value }) => { | ||
| if (value === 'true' || value === true) return true; | ||
| if (value === 'false' || value === false) return false; | ||
| return value; | ||
| }) | ||
| @IsBoolean() | ||
| public readonly enabled: boolean; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Because
This pull request
free_accesssubscription type sourcing product identity from the related offering.Issue that this pull request solves
Closes: #PAY-3790
Checklist
Put an
xin the boxes that applyHow to review (Optional)
Screenshots (Optional)
Please attach the screenshots of the changes made in case of change in user interface.
Other information (Optional)
Any other information that is important to this pull request.