Hooks
Purpose
Hooks let application code validate or adjust proposed changes before saving and react after saving. Handlers run sequentially in registration order. A thrown error stops later handlers; after-hook failure does not undo an already-saved operation.
Access and initialization
Access
TypeScript registers events through on; .NET provides one named registration method per event. Construction-time registration uses HooksConfig. Domain events have old/new snapshots; accounting events have input/result payloads.
Method catalog
| Method | Purpose |
|---|---|
on | Registers a handler and returns an unsubscribe function. |
off | Removes a handler. |
hasListeners | Checks registrations for diagnostics. |
emit | Dispatches a payload without persisting data. |
| Method | Purpose |
|---|---|
OnCustomerCreatedBefore | Registers a before handler. |
OnCustomerCreatedAfter | Registers an after handler. |
OnCustomerUpdatedBefore | Registers a before handler. |
OnCustomerUpdatedAfter | Registers an after handler. |
OnCustomerArchivedBefore | Registers a before handler. |
OnCustomerArchivedAfter | Registers an after handler. |
OnCustomerUnarchivedBefore | Registers a before handler. |
OnCustomerUnarchivedAfter | Registers an after handler. |
OnCustomerDeletedBefore | Registers a before handler. |
OnCustomerDeletedAfter | Registers an after handler. |
OnSubscriptionCreatedBefore | Registers a before handler. |
OnSubscriptionCreatedAfter | Registers an after handler. |
OnSubscriptionUpdatedBefore | Registers a before handler. |
OnSubscriptionUpdatedAfter | Registers an after handler. |
OnSubscriptionArchivedBefore | Registers a before handler. |
OnSubscriptionArchivedAfter | Registers an after handler. |
OnSubscriptionUnarchivedBefore | Registers a before handler. |
OnSubscriptionUnarchivedAfter | Registers an after handler. |
OnSubscriptionDeletedBefore | Registers a before handler. |
OnSubscriptionDeletedAfter | Registers an after handler. |
OnSubscriptionFeatureOverrideAddedBefore | Registers a before handler. |
OnSubscriptionFeatureOverrideAddedAfter | Registers an after handler. |
OnSubscriptionFeatureOverrideRemovedBefore | Registers a before handler. |
OnSubscriptionFeatureOverrideRemovedAfter | Registers an after handler. |
OnSubscriptionTemporaryOverridesClearedBefore | Registers a before handler. |
OnSubscriptionTemporaryOverridesClearedAfter | Registers an after handler. |
OnStripeReceivedBefore | Registers a before handler. |
OnStripeReceivedAfter | Registers an after handler. |
OnSubscriptionAddonAttachedBefore | Registers a before handler. |
OnSubscriptionAddonAttachedAfter | Registers an after handler. |
OnSubscriptionAddonDetachedBefore | Registers a before handler. |
OnSubscriptionAddonDetachedAfter | Registers an after handler. |
OnUsageReportedBefore | Registers a before handler. |
OnUsageReportedAfter | Registers an after handler. |
OnCreditConsumedBefore | Registers a before handler. |
OnCreditConsumedAfter | Registers an after handler. |
OnCreditGrantedBefore | Registers a before handler. |
OnCreditGrantedAfter | Registers an after handler. |
OnCreditAdjustedBefore | Registers a before handler. |
OnCreditAdjustedAfter | Registers an after handler. |
HasListeners | Checks registrations for diagnostics. |
EmitCustomerBeforeAsync | Dispatch helper for custom integrations. |
EmitCustomerAfterAsync | Dispatch helper for custom integrations. |
EmitSubscriptionBeforeAsync | Dispatch helper for custom integrations. |
EmitSubscriptionAfterAsync | Dispatch helper for custom integrations. |
EmitStripeReceivedAsync | Dispatch helper for custom integrations. |
Method details
on
Register one handler for an event. Registering the same function for the same event twice keeps one registration. .NET uses the event-specific methods shown in its language view.
Parameters
event: HookEventName.handler: HookHandler receiving the event-specific payload.
Returns () => void: Call this function to unsubscribe.
Example
off
Remove a previously registered function. Unknown registrations are ignored. .NET uses the Action returned by its registration method.
Parameters
event: Registered event name.handler: The same function reference originally registered.
Returns No returned value.
Example
OnCustomerCreatedBefore
Register a handler before customer.created. A thrown error prevents the pending mutation.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerCreatedAfter
Register a handler after customer.created. A thrown error propagates after the change has been saved.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerUpdatedBefore
Register a handler before customer.updated. A thrown error prevents the pending mutation.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerUpdatedAfter
Register a handler after customer.updated. A thrown error propagates after the change has been saved.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerArchivedBefore
Register a handler before customer.archived. A thrown error prevents the pending mutation.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerArchivedAfter
Register a handler after customer.archived. A thrown error propagates after the change has been saved.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerUnarchivedBefore
Register a handler before customer.unarchived. A thrown error prevents the pending mutation.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerUnarchivedAfter
Register a handler after customer.unarchived. A thrown error propagates after the change has been saved.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerDeletedBefore
Register a handler before customer.deleted. A thrown error prevents the pending mutation.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCustomerDeletedAfter
Register a handler after customer.deleted. A thrown error propagates after the change has been saved.
Parameters
handler: CustomerHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionCreatedBefore
Register a handler before subscription.created. A thrown error prevents the pending mutation.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionCreatedAfter
Register a handler after subscription.created. A thrown error propagates after the change has been saved.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionUpdatedBefore
Register a handler before subscription.updated. A thrown error prevents the pending mutation.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionUpdatedAfter
Register a handler after subscription.updated. A thrown error propagates after the change has been saved.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionArchivedBefore
Register a handler before subscription.archived. A thrown error prevents the pending mutation.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionArchivedAfter
Register a handler after subscription.archived. A thrown error propagates after the change has been saved.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionUnarchivedBefore
Register a handler before subscription.unarchived. A thrown error prevents the pending mutation.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionUnarchivedAfter
Register a handler after subscription.unarchived. A thrown error propagates after the change has been saved.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionDeletedBefore
Register a handler before subscription.deleted. A thrown error prevents the pending mutation.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionDeletedAfter
Register a handler after subscription.deleted. A thrown error propagates after the change has been saved.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionFeatureOverrideAddedBefore
Register a handler before subscription.featureOverrideAdded. A thrown error prevents the pending mutation.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionFeatureOverrideAddedAfter
Register a handler after subscription.featureOverrideAdded. A thrown error propagates after the change has been saved.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionFeatureOverrideRemovedBefore
Register a handler before subscription.featureOverrideRemoved. A thrown error prevents the pending mutation.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionFeatureOverrideRemovedAfter
Register a handler after subscription.featureOverrideRemoved. A thrown error propagates after the change has been saved.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionTemporaryOverridesClearedBefore
Register a handler before subscription.temporaryOverridesCleared. A thrown error prevents the pending mutation.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionTemporaryOverridesClearedAfter
Register a handler after subscription.temporaryOverridesCleared. A thrown error propagates after the change has been saved.
Parameters
handler: SubscriptionHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnStripeReceivedBefore
Register a handler before Stripe event processing. Throwing stops processing; changing the snapshot does not rewrite the incoming event.
Parameters
handler: StripeReceivedHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnStripeReceivedAfter
Register a handler after Stripe event processing. The handler runs after successful processing, including ignored event types.
Parameters
handler: StripeReceivedHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionAddonAttachedBefore
Register a handler before subscription.addonAttached. A thrown error prevents the pending mutation. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionAddonAttachedAfter
Register a handler after subscription.addonAttached. A thrown error propagates after the change has been saved. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionAddonDetachedBefore
Register a handler before subscription.addonDetached. A thrown error prevents the pending mutation. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnSubscriptionAddonDetachedAfter
Register a handler after subscription.addonDetached. A thrown error propagates after the change has been saved. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnUsageReportedBefore
Register a handler before usage.reported. A thrown error prevents the pending mutation. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnUsageReportedAfter
Register a handler after usage.reported. A thrown error propagates after the change has been saved. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCreditConsumedBefore
Register a handler before credit.consumed. A thrown error prevents the pending mutation. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCreditConsumedAfter
Register a handler after credit.consumed. A thrown error propagates after the change has been saved. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCreditGrantedBefore
Register a handler before credit.granted. A thrown error prevents the pending mutation. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCreditGrantedAfter
Register a handler after credit.granted. A thrown error propagates after the change has been saved. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCreditAdjustedBefore
Register a handler before credit.adjusted. A thrown error prevents the pending mutation. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
OnCreditAdjustedAfter
Register a handler after credit.adjusted. A thrown error propagates after the change has been saved. See the accounting payload for allowed changes and commit-error handling.
Parameters
handler: AccountingHookHandler delegate. Registering twice adds two invocations.
Returns Action: Invoke it to remove this registration.
Example
hasListeners
Check whether an event has registered handlers. This diagnostic does not invoke them.
Parameters
event: HookEventName.
Returns boolean: Whether at least one handler is registered.
Example
Parameters
eventName: Event string from HookEvents.
Returns bool: Whether at least one handler is registered.
Example
emit
Dispatch a payload to the registered handlers without saving an entity. This helper is for custom integrations; normal library methods emit their own events. Handler errors propagate.
Parameters
event: HookEventName.payload: Corresponding HookEventMap payload.
Returns No returned value.
Example
EmitCustomerBeforeAsync
Dispatch a payload for a custom integration without saving a database record. Handler exceptions propagate. Ordinary library operations call the dispatcher themselves.
Parameters
eventName: Matching event name.source: HookSource identifying the initiator.entityId: Database entity ID, or null before creation.oldDto,newDto: Previous and proposed or saved CustomerDto snapshots. Null old means creation; null new means deletion.cancellationToken: Optional cancellation token; defaults to default.
Returns CustomerDto?: Proposed customer after handlers; unchanged when no listeners exist.
Example
EmitCustomerAfterAsync
Dispatch a payload for a custom integration without saving a database record. Handler exceptions propagate. Ordinary library operations call the dispatcher themselves.
Parameters
eventName: Matching event name.source: HookSource identifying the initiator.entityId: Database entity ID, or null before creation.oldDto,newDto: Previous and proposed or saved CustomerDto snapshots. Null old means creation; null new means deletion.cancellationToken: Optional cancellation token; defaults to default.
Returns No returned value.
Example
EmitSubscriptionBeforeAsync
Dispatch a payload for a custom integration without saving a database record. Handler exceptions propagate. Ordinary library operations call the dispatcher themselves.
Task<SubscriptionMutationHookEvent?> EmitSubscriptionBeforeAsync(string eventName, HookSource source, long? entityId, long? customerId, SubscriptionDto? oldDto, SubscriptionDto? newDto, string? featureKey, string? value, string? overrideType, CancellationToken cancellationToken, DateTime? expiresAt)
Parameters
eventName: Matching event name.source: HookSource identifying the initiator.entityId: Database entity ID, or null before creation.customerId: Database customer ID, or null when unavailable.oldDto,newDto: Previous and proposed or saved SubscriptionDto snapshots. Null old means creation; null new means deletion.featureKey,value,overrideType: Optional override context; defaults to null.expiresAt: Optional timed-override expiry; defaults to null.cancellationToken: Optional cancellation token; defaults to default.
Returns SubscriptionMutationHookEvent?: Mutable payload, or null when no listeners exist.
Example
EmitSubscriptionAfterAsync
Dispatch a payload for a custom integration without saving a database record. Handler exceptions propagate. Ordinary library operations call the dispatcher themselves.
Parameters
eventName: Matching event name.source: HookSource identifying the initiator.entityId: Database entity ID, or null before creation.customerId: Database customer ID, or null when unavailable.oldDto,newDto: Previous and proposed or saved SubscriptionDto snapshots. Null old means creation; null new means deletion.featureKey,value,overrideType: Optional override context; defaults to null.expiresAt: Optional timed-override expiry; defaults to null.cancellationToken: Optional cancellation token; defaults to default.
Returns No returned value.
Example
EmitStripeReceivedAsync
Dispatch a payload for a custom integration without saving a database record. Handler exceptions propagate. Ordinary library operations call the dispatcher themselves.
Parameters
eventName: Matching event name.phase: Before or After from HookPhase.stripeEvent: Parsed Stripe event to snapshot.cancellationToken: Optional cancellation token; defaults to default.
Returns No returned value.
Example
Data types
Hook payloads are snapshots. Editing an after payload does not persist changes. Before handlers must use the fields supported by their event; relationship keys do not remap customer, plan, or billing-cycle relationships.
HooksConfig
Optional construction-time registration. Each field defaults to no handler. Runtime registration is also supported.
| Field | Type | Required | Default | Meaning |
|---|---|---|---|---|
| Each event name | HookHandler<E> | HookHandler<E>[] | No | None | One handler or ordered list for that event. |
| Property | Type | Required | Default | Meaning |
|---|---|---|---|---|
OnCustomerCreatedBefore | CustomerHookHandler? | No | null | Handler for customer.created.before. |
OnCustomerCreatedAfter | CustomerHookHandler? | No | null | Handler for customer.created.after. |
OnCustomerUpdatedBefore | CustomerHookHandler? | No | null | Handler for customer.updated.before. |
OnCustomerUpdatedAfter | CustomerHookHandler? | No | null | Handler for customer.updated.after. |
OnCustomerArchivedBefore | CustomerHookHandler? | No | null | Handler for customer.archived.before. |
OnCustomerArchivedAfter | CustomerHookHandler? | No | null | Handler for customer.archived.after. |
OnCustomerUnarchivedBefore | CustomerHookHandler? | No | null | Handler for customer.unarchived.before. |
OnCustomerUnarchivedAfter | CustomerHookHandler? | No | null | Handler for customer.unarchived.after. |
OnCustomerDeletedBefore | CustomerHookHandler? | No | null | Handler for customer.deleted.before. |
OnCustomerDeletedAfter | CustomerHookHandler? | No | null | Handler for customer.deleted.after. |
OnSubscriptionCreatedBefore | SubscriptionHookHandler? | No | null | Handler for subscription.created.before. |
OnSubscriptionCreatedAfter | SubscriptionHookHandler? | No | null | Handler for subscription.created.after. |
OnSubscriptionUpdatedBefore | SubscriptionHookHandler? | No | null | Handler for subscription.updated.before. |
OnSubscriptionUpdatedAfter | SubscriptionHookHandler? | No | null | Handler for subscription.updated.after. |
OnSubscriptionArchivedBefore | SubscriptionHookHandler? | No | null | Handler for subscription.archived.before. |
OnSubscriptionArchivedAfter | SubscriptionHookHandler? | No | null | Handler for subscription.archived.after. |
OnSubscriptionUnarchivedBefore | SubscriptionHookHandler? | No | null | Handler for subscription.unarchived.before. |
OnSubscriptionUnarchivedAfter | SubscriptionHookHandler? | No | null | Handler for subscription.unarchived.after. |
OnSubscriptionDeletedBefore | SubscriptionHookHandler? | No | null | Handler for subscription.deleted.before. |
OnSubscriptionDeletedAfter | SubscriptionHookHandler? | No | null | Handler for subscription.deleted.after. |
OnSubscriptionFeatureOverrideAddedBefore | SubscriptionHookHandler? | No | null | Handler for subscription.featureOverrideAdded.before. |
OnSubscriptionFeatureOverrideAddedAfter | SubscriptionHookHandler? | No | null | Handler for subscription.featureOverrideAdded.after. |
OnSubscriptionFeatureOverrideRemovedBefore | SubscriptionHookHandler? | No | null | Handler for subscription.featureOverrideRemoved.before. |
OnSubscriptionFeatureOverrideRemovedAfter | SubscriptionHookHandler? | No | null | Handler for subscription.featureOverrideRemoved.after. |
OnSubscriptionTemporaryOverridesClearedBefore | SubscriptionHookHandler? | No | null | Handler for subscription.temporaryOverridesCleared.before. |
OnSubscriptionTemporaryOverridesClearedAfter | SubscriptionHookHandler? | No | null | Handler for subscription.temporaryOverridesCleared.after. |
OnStripeReceivedBefore | StripeReceivedHookHandler? | No | null | Handler for stripe.received.before. |
OnStripeReceivedAfter | StripeReceivedHookHandler? | No | null | Handler for stripe.received.after. |
OnSubscriptionAddonAttachedBefore | AccountingHookHandler? | No | null | Handler for subscription.addonAttached.before. |
OnSubscriptionAddonAttachedAfter | AccountingHookHandler? | No | null | Handler for subscription.addonAttached.after. |
OnSubscriptionAddonDetachedBefore | AccountingHookHandler? | No | null | Handler for subscription.addonDetached.before. |
OnSubscriptionAddonDetachedAfter | AccountingHookHandler? | No | null | Handler for subscription.addonDetached.after. |
OnUsageReportedBefore | AccountingHookHandler? | No | null | Handler for usage.reported.before. |
OnUsageReportedAfter | AccountingHookHandler? | No | null | Handler for usage.reported.after. |
OnCreditConsumedBefore | AccountingHookHandler? | No | null | Handler for credit.consumed.before. |
OnCreditConsumedAfter | AccountingHookHandler? | No | null | Handler for credit.consumed.after. |
OnCreditGrantedBefore | AccountingHookHandler? | No | null | Handler for credit.granted.before. |
OnCreditGrantedAfter | AccountingHookHandler? | No | null | Handler for credit.granted.after. |
OnCreditAdjustedBefore | AccountingHookHandler? | No | null | Handler for credit.adjusted.before. |
OnCreditAdjustedAfter | AccountingHookHandler? | No | null | Handler for credit.adjusted.after. |
HookEventName
Supported event constants and payloads. TypeScript uses their string-value union; .NET uses the same strings through HookEvents.
| Value | Meaning |
|---|---|
HookEvents.SubscriptionAddonAttachedBefore | subscription.addonAttached.before; AccountingMutationHookEvent. |
HookEvents.SubscriptionAddonAttachedAfter | subscription.addonAttached.after; AccountingMutationHookEvent. |
HookEvents.SubscriptionAddonDetachedBefore | subscription.addonDetached.before; AccountingMutationHookEvent. |
HookEvents.SubscriptionAddonDetachedAfter | subscription.addonDetached.after; AccountingMutationHookEvent. |
HookEvents.UsageReportedBefore | usage.reported.before; AccountingMutationHookEvent. |
HookEvents.UsageReportedAfter | usage.reported.after; AccountingMutationHookEvent. |
HookEvents.CreditConsumedBefore | credit.consumed.before; AccountingMutationHookEvent. |
HookEvents.CreditConsumedAfter | credit.consumed.after; AccountingMutationHookEvent. |
HookEvents.CreditGrantedBefore | credit.granted.before; AccountingMutationHookEvent. |
HookEvents.CreditGrantedAfter | credit.granted.after; AccountingMutationHookEvent. |
HookEvents.CreditAdjustedBefore | credit.adjusted.before; AccountingMutationHookEvent. |
HookEvents.CreditAdjustedAfter | credit.adjusted.after; AccountingMutationHookEvent. |
HookEvents.CustomerCreatedBefore | customer.created.before; CustomerMutationHookEvent. |
HookEvents.CustomerCreatedAfter | customer.created.after; CustomerMutationHookEvent. |
HookEvents.CustomerUpdatedBefore | customer.updated.before; CustomerMutationHookEvent. |
HookEvents.CustomerUpdatedAfter | customer.updated.after; CustomerMutationHookEvent. |
HookEvents.CustomerArchivedBefore | customer.archived.before; CustomerMutationHookEvent. |
HookEvents.CustomerArchivedAfter | customer.archived.after; CustomerMutationHookEvent. |
HookEvents.CustomerUnarchivedBefore | customer.unarchived.before; CustomerMutationHookEvent. |
HookEvents.CustomerUnarchivedAfter | customer.unarchived.after; CustomerMutationHookEvent. |
HookEvents.CustomerDeletedBefore | customer.deleted.before; CustomerMutationHookEvent. |
HookEvents.CustomerDeletedAfter | customer.deleted.after; CustomerMutationHookEvent. |
HookEvents.SubscriptionCreatedBefore | subscription.created.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionCreatedAfter | subscription.created.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionUpdatedBefore | subscription.updated.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionUpdatedAfter | subscription.updated.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionArchivedBefore | subscription.archived.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionArchivedAfter | subscription.archived.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionUnarchivedBefore | subscription.unarchived.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionUnarchivedAfter | subscription.unarchived.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionDeletedBefore | subscription.deleted.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionDeletedAfter | subscription.deleted.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionFeatureOverrideAddedBefore | subscription.featureOverrideAdded.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionFeatureOverrideAddedAfter | subscription.featureOverrideAdded.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionFeatureOverrideRemovedBefore | subscription.featureOverrideRemoved.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionFeatureOverrideRemovedAfter | subscription.featureOverrideRemoved.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionTemporaryOverridesClearedBefore | subscription.temporaryOverridesCleared.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionTemporaryOverridesClearedAfter | subscription.temporaryOverridesCleared.after; SubscriptionMutationHookEvent. |
HookEvents.StripeReceivedBefore | stripe.received.before; StripeReceivedHookEvent. |
HookEvents.StripeReceivedAfter | stripe.received.after; StripeReceivedHookEvent. |
| Value | Meaning |
|---|---|
HookEvents.SubscriptionAddonAttachedBefore | subscription.addonAttached.before; AccountingMutationHookEvent. |
HookEvents.SubscriptionAddonAttachedAfter | subscription.addonAttached.after; AccountingMutationHookEvent. |
HookEvents.SubscriptionAddonDetachedBefore | subscription.addonDetached.before; AccountingMutationHookEvent. |
HookEvents.SubscriptionAddonDetachedAfter | subscription.addonDetached.after; AccountingMutationHookEvent. |
HookEvents.UsageReportedBefore | usage.reported.before; AccountingMutationHookEvent. |
HookEvents.UsageReportedAfter | usage.reported.after; AccountingMutationHookEvent. |
HookEvents.CreditConsumedBefore | credit.consumed.before; AccountingMutationHookEvent. |
HookEvents.CreditConsumedAfter | credit.consumed.after; AccountingMutationHookEvent. |
HookEvents.CreditGrantedBefore | credit.granted.before; AccountingMutationHookEvent. |
HookEvents.CreditGrantedAfter | credit.granted.after; AccountingMutationHookEvent. |
HookEvents.CreditAdjustedBefore | credit.adjusted.before; AccountingMutationHookEvent. |
HookEvents.CreditAdjustedAfter | credit.adjusted.after; AccountingMutationHookEvent. |
HookEvents.CustomerCreatedBefore | customer.created.before; CustomerMutationHookEvent. |
HookEvents.CustomerCreatedAfter | customer.created.after; CustomerMutationHookEvent. |
HookEvents.CustomerUpdatedBefore | customer.updated.before; CustomerMutationHookEvent. |
HookEvents.CustomerUpdatedAfter | customer.updated.after; CustomerMutationHookEvent. |
HookEvents.CustomerArchivedBefore | customer.archived.before; CustomerMutationHookEvent. |
HookEvents.CustomerArchivedAfter | customer.archived.after; CustomerMutationHookEvent. |
HookEvents.CustomerUnarchivedBefore | customer.unarchived.before; CustomerMutationHookEvent. |
HookEvents.CustomerUnarchivedAfter | customer.unarchived.after; CustomerMutationHookEvent. |
HookEvents.CustomerDeletedBefore | customer.deleted.before; CustomerMutationHookEvent. |
HookEvents.CustomerDeletedAfter | customer.deleted.after; CustomerMutationHookEvent. |
HookEvents.SubscriptionCreatedBefore | subscription.created.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionCreatedAfter | subscription.created.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionUpdatedBefore | subscription.updated.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionUpdatedAfter | subscription.updated.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionArchivedBefore | subscription.archived.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionArchivedAfter | subscription.archived.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionUnarchivedBefore | subscription.unarchived.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionUnarchivedAfter | subscription.unarchived.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionDeletedBefore | subscription.deleted.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionDeletedAfter | subscription.deleted.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionFeatureOverrideAddedBefore | subscription.featureOverrideAdded.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionFeatureOverrideAddedAfter | subscription.featureOverrideAdded.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionFeatureOverrideRemovedBefore | subscription.featureOverrideRemoved.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionFeatureOverrideRemovedAfter | subscription.featureOverrideRemoved.after; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionTemporaryOverridesClearedBefore | subscription.temporaryOverridesCleared.before; SubscriptionMutationHookEvent. |
HookEvents.SubscriptionTemporaryOverridesClearedAfter | subscription.temporaryOverridesCleared.after; SubscriptionMutationHookEvent. |
HookEvents.StripeReceivedBefore | stripe.received.before; StripeReceivedHookEvent. |
HookEvents.StripeReceivedAfter | stripe.received.after; StripeReceivedHookEvent. |
HookHandler
TypeScript handler: (event: HookEventMap[E]) => void | Promise<void>. E extends HookEventName. The library awaits asynchronous handlers. .NET uses the named delegates below.
CustomerHookHandler
The .NET delegate receives CustomerMutationHookEvent and CancellationToken, and returns Task. TypeScript uses HookHandler with the corresponding event.
SubscriptionHookHandler
The .NET delegate receives SubscriptionMutationHookEvent and CancellationToken, and returns Task. TypeScript uses HookHandler with the corresponding event.
StripeReceivedHookHandler
The .NET delegate receives StripeReceivedHookEvent and CancellationToken, and returns Task. TypeScript uses HookHandler with the corresponding event.
AccountingMutationHookEvent
Payload for add-on attachments, usage, and credit changes.
| Field | Type | Required | Default | Meaning |
|---|---|---|---|---|
type | HookEventName | Yes | Not applicable | Event name from HookEvents. |
phase | HookPhase | Yes | Not applicable | before or after. |
source | HookSource | Yes | Not applicable | api, stripe, or system. |
occurredAt | string | Yes | Not applicable | UTC event timestamp. |
input | Record<string, unknown> | Yes | Not applicable | Operation input with camelCase keys in both libraries. |
result | unknown | No | Not applicable | After-event result; absent before the operation. |
| Property | Type | Required | Default | Meaning |
|---|---|---|---|---|
Type | string | Yes | Not applicable | Event name from HookEvents. |
Phase | string | Yes | Not applicable | before or after. |
Source | string | Yes | Not applicable | api, stripe, or system. |
OccurredAt | string | Yes | Not applicable | UTC event timestamp. |
Input | JsonObject | Yes | Not applicable | Operation input with camelCase keys in both libraries. |
Result | JsonElement? | Yes | Not applicable | After-event result; absent before the operation. |
Allowed before-hook input changes are limited to the following fields; changing other fields raises a validation error.
| Event | Editable input fields |
|---|---|
| subscription.addonAttached | quantity |
| subscription.addonDetached | None |
| usage.reported | quantity, metadata |
| credit.granted | amount, priority, expiresAt, metadata; scheduled grants permit amount, priority, metadata |
| credit.consumed | units, metadata |
| credit.adjusted | amount, reason |
Accounting after-hook failure raises CommittedOperationHookError in TypeScript or CommittedOperationHookException in .NET. The operation already committed; its result / Result is available on the error. For idempotent operations, retry the identical request and key to recover the saved result.
AccountingHookHandler
The .NET delegate receives AccountingMutationHookEvent and CancellationToken, and returns Task. TypeScript uses HookHandler with the corresponding event.
HookEventMap
TypeScript maps each event name to the payload shown in HookEventName. .NET registration delegates select the corresponding payload type.
HookSource
Event origin.
| Value | Meaning |
|---|---|
api | A public API mutation; accounting hooks currently use this source for scheduled issuance too. |
stripe | A Stripe-driven entity mutation. |
system | A system lifecycle transition. |
| Value | Meaning |
|---|---|
HookSource.Api | A public API mutation; accounting hooks currently use this source for scheduled issuance too. |
HookSource.Stripe | A Stripe-driven entity mutation. |
HookSource.System | A system lifecycle transition. |
SubscriptionMutationHookEvent
Payload for subscription changes.
| Field | Type | Required | Default | Meaning |
|---|---|---|---|---|
type | HookEventName | Yes | Not applicable | Event name from HookEvents. |
phase | HookPhase | Yes | Not applicable | before or after. |
source | HookSource | Yes | Not applicable | api, stripe, or system. |
occurredAt | string | Yes | Not applicable | UTC event timestamp. |
entityId | number | null | Yes | Not applicable | Numeric database ID: null before creation, known after creation and on existing records. |
customerId | number | null | undefined | No | Not applicable | Owning customer database ID when available. |
old | SubscriptionDto | null | Yes | Not applicable | Previous snapshot; null for creation. |
new | SubscriptionDto | null | Yes | Not applicable | Proposed before snapshot or saved after snapshot; null for deletion. |
featureKey | string | undefined | No | Not applicable | Feature involved in an override event. |
value | string | undefined | No | Not applicable | Proposed override value. |
overrideType | string | undefined | No | Not applicable | permanent, temporary, or timed. |
expiresAt | string | null | undefined | No | Not applicable | UTC expiry for a timed override. |
| Property | Type | Required | Default | Meaning |
|---|---|---|---|---|
Type | string | Yes | Not applicable | Event name from HookEvents. |
Phase | string | Yes | Not applicable | before or after. |
Source | string | Yes | Not applicable | api, stripe, or system. |
OccurredAt | string | Yes | Not applicable | UTC event timestamp. |
EntityId | long? | Yes | Not applicable | Numeric database ID: null before creation, known after creation and on existing records. |
CustomerId | long? | Yes | Not applicable | Owning customer database ID when available. |
Old | SubscriptionDto? | Yes | Not applicable | Previous snapshot; null for creation. |
New | SubscriptionDto? | Yes | Not applicable | Proposed before snapshot or saved after snapshot; null for deletion. |
FeatureKey | string? | Yes | Not applicable | Feature involved in an override event. |
Value | string? | Yes | Not applicable | Proposed override value. |
OverrideType | string? | Yes | Not applicable | permanent, temporary, or timed. |
ExpiresAt | DateTime? | Yes | Not applicable | UTC expiry for a timed override. |
Before hooks may change new.expirationDate, cancellationDate, trialEndDate, currentPeriodStart, currentPeriodEnd, stripeSubscriptionId, and metadata. Creation also permits key. Override-add events permit value, overrideType, and expiresAt. Activation and archive flags are not copied from this payload.
Before hooks may change New.ActivationDate, ExpirationDate, CancellationDate, TrialEndDate, CurrentPeriodStart, CurrentPeriodEnd, StripeSubscriptionId, Metadata, and IsArchived; archive/unarchive operations enforce their own final archive flag. Creation also permits Key. Override-add events permit Value, OverrideType, and ExpiresAt.
HookPhase
Event phase.
| Value | Meaning |
|---|---|
before | Before the operation saves or processes data. |
after | After the operation saves or finishes processing. |
| Value | Meaning |
|---|---|
HookPhase.Before | Before the operation saves or processes data. |
HookPhase.After | After the operation saves or finishes processing. |
CustomerMutationHookEvent
Payload for customer changes.
| Field | Type | Required | Default | Meaning |
|---|---|---|---|---|
type | HookEventName | Yes | Not applicable | Event name from HookEvents. |
phase | HookPhase | Yes | Not applicable | before or after. |
source | HookSource | Yes | Not applicable | api, stripe, or system. |
occurredAt | string | Yes | Not applicable | UTC event timestamp. |
entityId | number | null | Yes | Not applicable | Numeric database ID: null before creation, known after creation and on existing records. |
customerId | number | null | undefined | No | Not applicable | Inherited optional field; customer events do not populate it. |
old | CustomerDto | null | Yes | Not applicable | Previous snapshot; null for creation. |
new | CustomerDto | null | Yes | Not applicable | Proposed before snapshot or saved after snapshot; null for deletion. |
| Property | Type | Required | Default | Meaning |
|---|---|---|---|---|
Type | string | Yes | Not applicable | Event name from HookEvents. |
Phase | string | Yes | Not applicable | before or after. |
Source | string | Yes | Not applicable | api, stripe, or system. |
OccurredAt | string | Yes | Not applicable | UTC event timestamp. |
EntityId | long? | Yes | Not applicable | Numeric database ID: null before creation, known after creation and on existing records. |
Old | CustomerDto? | Yes | Not applicable | Previous snapshot; null for creation. |
New | CustomerDto? | Yes | Not applicable | Proposed before snapshot or saved after snapshot; null for deletion. |
Before hooks may change new.displayName, email, externalBillingId, and metadata; key may change only during creation. Status changes are controlled by the operation.
Before hooks may change New.DisplayName, Email, ExternalBillingId, and Metadata; Key may change only during creation. Status changes are controlled by the operation.
StripeReceivedHookEvent
Payload for Stripe intake.
| Field | Type | Required | Default | Meaning |
|---|---|---|---|---|
type | HookEventName | Yes | Not applicable | Event name from HookEvents. |
phase | HookPhase | Yes | Not applicable | before or after. |
occurredAt | string | Yes | Not applicable | UTC event timestamp. |
data | Stripe.Event | Yes | Not applicable | Snapshot of the parsed provider event. |
stripeCustomerId | string | undefined | No | Not applicable | Provider customer ID when extractable. |
stripeSubscriptionId | string | undefined | No | Not applicable | Provider subscription ID when extractable. |
| Property | Type | Required | Default | Meaning |
|---|---|---|---|---|
Type | string | Yes | Not applicable | Event name from HookEvents. |
Phase | string | Yes | Not applicable | before or after. |
OccurredAt | string | Yes | Not applicable | UTC event timestamp. |
Data | Stripe.Event | Yes | Not applicable | Snapshot of the parsed provider event. |
StripeCustomerId | string? | Yes | Not applicable | Provider customer ID when extractable. |
StripeSubscriptionId | string? | Yes | Not applicable | Provider subscription ID when extractable. |
Related guides
- Extending Subscrio: integration and audit patterns.
- Customers: customer mutations.
- Subscriptions: lifecycle and override mutations.
- Stripe Integration: provider event processing.
- Credits: transactional accounting and retries.