Skip to content

Stripe operations

The operation facade is included in 0.3.0. Existing 0.2.0 connector exports remain compatible. Facades, models, connectors and gateway protocols work with the base installation. SDK gateway classes and webhook parsing require the optional Stripe integration.

StripeActions

StripeActions(*, host: RefundHost | None = None, policy: RefundPolicy | None = None, settings: StripeRefundSettings | None = None, store: ActionStore, authority_evaluator: AuthorityEvaluatorPort, commitment_provider: CommitmentProviderPort, protection_codec: ProtectionCodecPort, retention_store: RetentionStore | None = None, clock: Clock | None = None, identifiers: IdentifierProvider | None = None, event_sink: EventSink | None = None, runtime_revision: str | None = None, client: StripeClient | None = None, gateway: StripeRefundGateway | None = None, subscriptions: SubscriptionCancellationConfig | None = None, credit_notes: CreditNoteConfig | None = None)

Compose Stripe operations once per host scope; SDK ownership stays with the caller.

Source code in src/threvo_actions/integrations/stripe/actions.py
def __init__(
    self,
    *,
    host: RefundHost | None = None,
    policy: RefundPolicy | None = None,
    settings: StripeRefundSettings | None = None,
    store: ActionStore,
    authority_evaluator: AuthorityEvaluatorPort,
    commitment_provider: CommitmentProviderPort,
    protection_codec: ProtectionCodecPort,
    retention_store: RetentionStore | None = None,
    clock: Clock | None = None,
    identifiers: IdentifierProvider | None = None,
    event_sink: EventSink | None = None,
    runtime_revision: str | None = None,
    client: stripe.StripeClient | None = None,
    gateway: StripeRefundGateway | None = None,
    subscriptions: SubscriptionCancellationConfig | None = None,
    credit_notes: CreditNoteConfig | None = None,
) -> None:
    self._refunds: StripeRefunds | None = None
    self._subscriptions: StripeSubscriptions | None = None
    self._credit_notes: StripeCreditNotes | None = None
    refund_configured = any(value is not None for value in (host, policy, settings, gateway))
    if not refund_configured and subscriptions is None and credit_notes is None:
        raise ValueError("configure at least one Stripe action group")
    runtime_clock = clock if clock is not None else SystemClock()
    runtime = ActionRuntime(
        store=store,
        retention_store=retention_store,
        clock=runtime_clock,
        identifiers=identifiers,
        event_sink=event_sink,
        runtime_revision=runtime_revision,
    )
    if refund_configured:
        if host is None or policy is None or settings is None:
            raise ValueError("refunds require host, policy and settings together")
        self._configure_refunds(
            host=host,
            policy=policy,
            settings=settings,
            store=store,
            authority_evaluator=authority_evaluator,
            commitment_provider=commitment_provider,
            protection_codec=protection_codec,
            client=client,
            gateway=gateway,
            runtime=runtime,
            clock=runtime_clock,
        )
    if subscriptions is not None:
        if (client is None) == (subscriptions.gateway is None):
            raise ValueError("provide exactly one Stripe client or subscription gateway")
        if client is None:
            subscription_gateway = subscriptions.gateway
        else:
            from .billing_gateway import StripeSubscriptionSDKGateway

            subscription_gateway = StripeSubscriptionSDKGateway(client)
        if subscription_gateway is None:
            raise ValueError("a subscription gateway is required")
        workflow = _SubscriptionWorkflow(
            config=subscriptions,
            gateway=subscription_gateway,
            store=store,
            clock=runtime_clock,
        )
        self._subscriptions = StripeSubscriptions(
            definition=_definition(
                workflow=workflow,
                action_type=workflow.action_type,
                settings=subscriptions.settings,
                command_model=SubscriptionCancellationRequest,
                snapshot_model=SubscriptionCancellationSnapshot,
                preview_model=SubscriptionCancellationPreview,
                result_model=SubscriptionCancellationOutcome,
                authority_evaluator=authority_evaluator,
                commitment_provider=commitment_provider,
                protection_codec=protection_codec,
            ),
            runtime=runtime,
            workflow=workflow,
        )
    if credit_notes is not None:
        if (client is None) == (credit_notes.gateway is None):
            raise ValueError("provide exactly one Stripe client or credit-note gateway")
        if client is None:
            credit_gateway = credit_notes.gateway
        else:
            from .billing_gateway import StripeCreditNoteSDKGateway

            credit_gateway = StripeCreditNoteSDKGateway(client)
        if credit_gateway is None:
            raise ValueError("a credit-note gateway is required")
        credit_workflow = _CreditNoteWorkflow(
            config=credit_notes,
            gateway=credit_gateway,
            store=store,
            clock=runtime_clock,
        )
        self._credit_notes = StripeCreditNotes(
            definition=_definition(
                workflow=credit_workflow,
                action_type=credit_workflow.action_type,
                settings=credit_notes.settings,
                command_model=CreditNoteRequest,
                snapshot_model=CreditNoteSnapshot,
                preview_model=CreditNotePreview,
                result_model=CreditNoteOutcome,
                authority_evaluator=authority_evaluator,
                commitment_provider=commitment_provider,
                protection_codec=protection_codec,
            ),
            runtime=runtime,
            workflow=credit_workflow,
        )

refunds property

refunds: StripeRefunds

subscriptions property

subscriptions: StripeSubscriptions

credit_notes property

credit_notes: StripeCreditNotes

from_services classmethod

from_services(services: StripeServices, *, refunds: RefundConfig | None = None, subscriptions: SubscriptionCancellationConfig | None = None, credit_notes: CreditNoteConfig | None = None) -> StripeActions

Compose through the progressive typed service/configuration layer.

Source code in src/threvo_actions/integrations/stripe/actions.py
@classmethod
def from_services(
    cls,
    services: StripeServices,
    *,
    refunds: RefundConfig | None = None,
    subscriptions: SubscriptionCancellationConfig | None = None,
    credit_notes: CreditNoteConfig | None = None,
) -> StripeActions:
    """Compose through the progressive typed service/configuration layer."""

    from .composition import from_services

    return from_services(
        services,
        refunds=refunds,
        subscriptions=subscriptions,
        credit_notes=credit_notes,
    )

StripeRefunds

StripeRefunds(*, definition: ActionDefinition[RefundRequest, RefundSnapshot, RefundPreview, RefundOutcome], runtime: ActionRuntime, workflow: _RefundWorkflow)

Governed refunds. Identity arguments must come from authenticated host context.

Expose definition through ActionToolBinding for agents; never expose these server-side methods or authority arguments as raw model tools.

Source code in src/threvo_actions/integrations/stripe/actions.py
def __init__(
    self,
    *,
    definition: ActionDefinition[RefundRequest, RefundSnapshot, RefundPreview, RefundOutcome],
    runtime: ActionRuntime,
    workflow: _RefundWorkflow,
) -> None:
    self.definition = definition
    self.runtime = runtime
    self._workflow = workflow

definition instance-attribute

definition = definition

runtime instance-attribute

runtime = runtime

prepare async

prepare(request: RefundRequest, *, tenant_reference: str, requesting_principal: RequestingPrincipal, proposing_agent: ProposingAgent | None = None) -> ActionOperationResult
Source code in src/threvo_actions/integrations/stripe/actions.py
async def prepare(
    self,
    request: RefundRequest,
    *,
    tenant_reference: str,
    requesting_principal: RequestingPrincipal,
    proposing_agent: ProposingAgent | None = None,
) -> ActionOperationResult:
    return await self.runtime.prepare(
        self.definition,
        tenant_reference=tenant_reference,
        command=request,
        requesting_principal=requesting_principal,
        proposing_agent=proposing_agent,
    )

record_authority async

record_authority(evidence: AuthorityEvidence, *, authenticated_authority: ConfirmingAuthority) -> ActionOperationResult
Source code in src/threvo_actions/integrations/stripe/actions.py
async def record_authority(
    self, evidence: AuthorityEvidence, *, authenticated_authority: ConfirmingAuthority
) -> ActionOperationResult:
    return await self.runtime.record_authority(
        self.definition, evidence=evidence, authenticated_authority=authenticated_authority
    )

execute async

execute(*, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
Source code in src/threvo_actions/integrations/stripe/actions.py
async def execute(
    self, *, tenant_reference: str, proposal_reference: str
) -> ActionOperationResult:
    return await self.runtime.execute(
        self.definition,
        tenant_reference=tenant_reference,
        proposal_reference=proposal_reference,
    )

reconcile async

reconcile(*, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
Source code in src/threvo_actions/integrations/stripe/actions.py
async def reconcile(
    self, *, tenant_reference: str, proposal_reference: str
) -> ActionOperationResult:
    return await self.runtime.reconcile(
        self.definition,
        tenant_reference=tenant_reference,
        proposal_reference=proposal_reference,
    )

expire_due async

expire_due(*, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
Source code in src/threvo_actions/integrations/stripe/actions.py
async def expire_due(
    self, *, tenant_reference: str, proposal_reference: str
) -> ActionOperationResult:
    return await self.runtime.expire_due(
        self.definition,
        tenant_reference=tenant_reference,
        proposal_reference=proposal_reference,
    )

read async

read(proposal_reference: str, *, context: ReadContext) -> ProposalView
Source code in src/threvo_actions/integrations/stripe/actions.py
async def read(self, proposal_reference: str, *, context: ReadContext) -> ProposalView:
    return await self.runtime.read(
        self.definition, proposal_reference=proposal_reference, context=context
    )

read_recovery async

read_recovery(proposal_reference: str, *, context: ReadContext) -> ActionRecoveryView
Source code in src/threvo_actions/integrations/stripe/actions.py
async def read_recovery(
    self, proposal_reference: str, *, context: ReadContext
) -> ActionRecoveryView:
    return await self.runtime.read_recovery(
        self.definition, proposal_reference=proposal_reference, context=context
    )

export_evidence async

export_evidence(proposal_reference: str, *, context: ReadContext) -> ActionEvidenceBundle
Source code in src/threvo_actions/integrations/stripe/actions.py
async def export_evidence(
    self, proposal_reference: str, *, context: ReadContext
) -> ActionEvidenceBundle:
    return await self.runtime.export_evidence(
        self.definition, proposal_reference=proposal_reference, context=context
    )

observe_effect async

observe_effect(proposal_reference: str, *, context: ReadContext) -> StripeEffectObservation
Source code in src/threvo_actions/integrations/stripe/actions.py
async def observe_effect(
    self, proposal_reference: str, *, context: ReadContext
) -> StripeEffectObservation:
    observation_context = await self.runtime.observation_context(
        self.definition,
        proposal_reference=proposal_reference,
        context=context,
    )
    result = await self._workflow.observe(context=observation_context)
    return StripeEffectObservation(
        action_group=StripeHostActionGroup.REFUNDS,
        proposal_reference=proposal_reference,
        semantic_effect_reference=observation_context.semantic_effect_reference,
        observed_at=observation_context.observed_at,
        verification_status=result.status,
        outcome=(
            None
            if result.result is None
            else StripeObservedOutcome(
                status=result.result.status,
                amount=result.result.amount,
            )
        ),
        external_reference=result.external_reference,
        reason_code=result.reason_code,
    )

RefundPolicy

Bases: ExperimentalModel

Explicit per-currency ceilings; hosts separately authorize every operation.

model_config class-attribute instance-attribute

model_config = ConfigDict(validate_default=True, hide_input_in_errors=True)

limits instance-attribute

limits: Annotated[tuple[Money, ...], Field(min_length=1)]

allow_live class-attribute instance-attribute

allow_live: bool = False

fingerprint property

fingerprint: str

unique_positive_limits

unique_positive_limits() -> RefundPolicy
Source code in src/threvo_actions/integrations/stripe/models.py
@model_validator(mode="after")
def unique_positive_limits(self) -> RefundPolicy:
    if len({limit.currency for limit in self.limits}) != len(self.limits):
        raise ValueError("refund limits must name each currency once")
    if any(not limit.amount.is_finite() or limit.amount <= 0 for limit in self.limits):
        raise ValueError("refund limits must be finite and positive")
    return self

permits

permits(amount: Money, *, livemode: bool) -> bool
Source code in src/threvo_actions/integrations/stripe/models.py
def permits(self, amount: Money, *, livemode: bool) -> bool:
    return (
        (not livemode or self.allow_live)
        and amount.amount.is_finite()
        and any(
            limit.currency == amount.currency and 0 < amount.amount <= limit.amount
            for limit in self.limits
        )
    )

RefundRequest

Bases: ExperimentalModel

Model-visible intent. Resolve payment_reference through the authenticated host.

intent_reference class-attribute instance-attribute

intent_reference: SafeReference = Field(description='Stable reference for this business intent.')

payment_reference class-attribute instance-attribute

payment_reference: SafeReference = Field(description='Host payment reference, not a Stripe ID.')

amount class-attribute instance-attribute

amount: Money = Field(description='Exact positive refund; encode decimal amounts as strings.')

RefundPayment

Bases: ExperimentalModel

Canonical host payment; version changes whenever its refund binding changes.

model_config class-attribute instance-attribute

model_config = ConfigDict(hide_input_in_errors=True)

tenant_reference instance-attribute

tenant_reference: SafeReference

payment_reference instance-attribute

payment_reference: SafeReference

version instance-attribute

version: Annotated[int, Field(ge=1)]

account instance-attribute

account: StripeAccount

charge_id class-attribute instance-attribute

charge_id: StripeChargeId = Field(repr=False)

currency instance-attribute

currency: CurrencyCode

currency_exponent instance-attribute

currency_exponent: Annotated[int, Field(ge=0, le=3)]

RefundSnapshot

Bases: ExperimentalModel

model_config class-attribute instance-attribute

model_config = ConfigDict(hide_input_in_errors=True)

intent instance-attribute

intent: RefundIntent

payment_reference instance-attribute

payment_reference: SafeReference

payment_version instance-attribute

payment_version: Annotated[int, Field(ge=1)]

refunded_minor instance-attribute

refunded_minor: Annotated[int, Field(ge=0)]

policy_fingerprint instance-attribute

policy_fingerprint: Annotated[str, Field(pattern='^[a-f0-9]{64}$')]

effect_reference property

effect_reference: str

RefundPreview

Bases: ExperimentalModel

payment_reference instance-attribute

payment_reference: SafeReference

amount instance-attribute

amount: Money

StripeRefundSettings

Bases: ExperimentalModel

Host authority identity is explicit; execution always uses the existing runtime.

model_config class-attribute instance-attribute

model_config = ConfigDict(validate_default=True)

action_type class-attribute instance-attribute

action_type: ActionType = ActionType(namespace='stripe.refunds', name='create', version=1)

executor_identity instance-attribute

executor_identity: GovernedExecutor

authority_audience instance-attribute

authority_audience: SafeReference

authority_channel_assurance class-attribute instance-attribute

authority_channel_assurance: SafeReference = 'authenticated_host_session'

proposal_ttl class-attribute instance-attribute

proposal_ttl: Annotated[timedelta, Field(gt=timedelta(0))] = timedelta(minutes=10)

verification_delay class-attribute instance-attribute

verification_delay: Annotated[timedelta, Field(ge=timedelta(0))] = timedelta(seconds=10)

verification_lease_duration class-attribute instance-attribute

verification_lease_duration: Annotated[timedelta, Field(gt=timedelta(0))] = timedelta(minutes=2)

max_verification_attempts class-attribute instance-attribute

max_verification_attempts: Annotated[int, Field(gt=0)] = 30

RefundHost dataclass

RefundHost(repository: RefundRepository, authorization: AuthorizationPort[RefundRequest, RefundSnapshot])

repository instance-attribute

repository: RefundRepository

authorization instance-attribute

RefundRepository

Bases: Protocol

payment async

payment(tenant_reference: str, payment_reference: str) -> RefundPayment
Source code in src/threvo_actions/integrations/stripe/ports.py
async def payment(self, tenant_reference: str, payment_reference: str) -> RefundPayment: ...

remember async

remember(snapshot: RefundSnapshot, requester: str) -> None

Durably bind intent + requester; refuse different parameters for an existing intent.

Source code in src/threvo_actions/integrations/stripe/ports.py
async def remember(self, snapshot: RefundSnapshot, requester: str) -> None:
    """Durably bind intent + requester; refuse different parameters for an existing intent."""
    ...

load async

load(tenant_reference: str, effect_reference: str) -> RefundSnapshot
Source code in src/threvo_actions/integrations/stripe/ports.py
async def load(self, tenant_reference: str, effect_reference: str) -> RefundSnapshot: ...

reserve async

reserve(snapshot: RefundSnapshot, *, not_after: datetime) -> RefundReservationStatus

Atomically compare payment/intent, deadline and unresolved attempts before claiming.

Coordinate with all payment writers. ALREADY_SUBMITTED never permits resend. An uncertain reservation acknowledgement must raise and retain the durable claim.

Source code in src/threvo_actions/integrations/stripe/ports.py
async def reserve(
    self, snapshot: RefundSnapshot, *, not_after: datetime
) -> RefundReservationStatus:
    """Atomically compare payment/intent, deadline and unresolved attempts before claiming.

    Coordinate with all payment writers. ALREADY_SUBMITTED never permits resend.
    An uncertain reservation acknowledgement must raise and retain the durable claim.
    """
    ...

record_no_submission async

record_no_submission(tenant_reference: str, effect_reference: str) -> None

Mark this intent resolved without submission; never erase/reopen its identity.

Source code in src/threvo_actions/integrations/stripe/ports.py
async def record_no_submission(self, tenant_reference: str, effect_reference: str) -> None:
    """Mark this intent resolved without submission; never erase/reopen its identity."""
    ...

record_outcome async

record_outcome(tenant_reference: str, effect_reference: str, outcome: RefundOutcome) -> None

Persist a terminal provider observation without rewriting runtime receipts.

Source code in src/threvo_actions/integrations/stripe/ports.py
async def record_outcome(
    self, tenant_reference: str, effect_reference: str, outcome: RefundOutcome
) -> None:
    """Persist a terminal provider observation without rewriting runtime receipts."""
    ...

Billing operations

See the billing guide for composition, supported scope and host obligations. Both groups expose the same prepare, record_authority, execute, reconcile and read methods as refunds.

StripeSubscriptions

StripeSubscriptions(*, definition: ActionDefinition[CommandT, SnapshotT, PreviewT, ResultT], runtime: ActionRuntime, workflow: _Workflow[CommandT, SnapshotT, PreviewT, ResultT])

Bases: _StripeOperation[SubscriptionCancellationRequest, SubscriptionCancellationSnapshot, SubscriptionCancellationPreview, SubscriptionCancellationOutcome]

Prepare schedule/withdrawal proposals; host authority and verification remain required.

Source code in src/threvo_actions/integrations/stripe/_operation.py
def __init__(
    self,
    *,
    definition: ActionDefinition[CommandT, SnapshotT, PreviewT, ResultT],
    runtime: ActionRuntime,
    workflow: _Workflow[CommandT, SnapshotT, PreviewT, ResultT],
) -> None:
    self.definition = definition
    self.runtime = runtime
    self._workflow = workflow

observe_effect async

observe_effect(proposal_reference: str, *, context: ReadContext) -> StripeEffectObservation
Source code in src/threvo_actions/integrations/stripe/subscriptions.py
async def observe_effect(
    self, proposal_reference: str, *, context: ReadContext
) -> StripeEffectObservation:
    observation_context = await self.runtime.observation_context(
        self.definition,
        proposal_reference=proposal_reference,
        context=context,
    )
    result = await self._workflow.observe(context=observation_context)
    return StripeEffectObservation(
        action_group=StripeHostActionGroup.SUBSCRIPTIONS,
        proposal_reference=proposal_reference,
        semantic_effect_reference=observation_context.semantic_effect_reference,
        observed_at=observation_context.observed_at,
        verification_status=result.status,
        outcome=(
            None
            if result.result is None
            else StripeObservedOutcome(status=result.result.status)
        ),
        external_reference=result.external_reference,
        reason_code=result.reason_code,
    )

SubscriptionCancellationConfig dataclass

SubscriptionCancellationConfig(host: SubscriptionCancellationHost, policy: SubscriptionCancellationPolicy, settings: StripeActionSettings, gateway: StripeSubscriptionGateway | None = None)

host instance-attribute

host: SubscriptionCancellationHost

policy instance-attribute

settings instance-attribute

gateway class-attribute instance-attribute

gateway: StripeSubscriptionGateway | None = None

SubscriptionCancellationRequest

Bases: ExperimentalModel

intent_reference class-attribute instance-attribute

intent_reference: SafeReference = Field(description='Stable business intent; never reuse for a different operation.')

subscription_reference class-attribute instance-attribute

subscription_reference: SafeReference = Field(description='Host subscription reference, not a Stripe ID.')

operation class-attribute instance-attribute

operation: SubscriptionOperation = Field(description='Schedule cancellation at current period end, or withdraw that schedule. Does not end service immediately.')

SubscriptionCancellationPolicy

Bases: ExperimentalModel

allow_live class-attribute instance-attribute

allow_live: bool = False

allow_withdrawal class-attribute instance-attribute

allow_withdrawal: bool = True

fingerprint property

fingerprint: str

permits

permits(operation: SubscriptionOperation, *, livemode: bool) -> bool
Source code in src/threvo_actions/integrations/stripe/subscriptions.py
def permits(self, operation: SubscriptionOperation, *, livemode: bool) -> bool:
    return (not livemode or self.allow_live) and (
        operation is SubscriptionOperation.SCHEDULE or self.allow_withdrawal
    )

SubscriptionCancellationRepository

Bases: StripeActionRepository[SubscriptionCancellationSnapshot, SubscriptionCancellationOutcome], Protocol

subscription async

subscription(tenant_reference: str, subscription_reference: str) -> SubscriptionBinding
Source code in src/threvo_actions/integrations/stripe/subscriptions.py
async def subscription(
    self, tenant_reference: str, subscription_reference: str
) -> SubscriptionBinding: ...

SubscriptionBinding

Bases: ExperimentalModel

model_config class-attribute instance-attribute

model_config = ConfigDict(hide_input_in_errors=True)

tenant_reference instance-attribute

tenant_reference: SafeReference

subscription_reference instance-attribute

subscription_reference: SafeReference

version instance-attribute

version: Annotated[int, Field(ge=1)]

account instance-attribute

account: StripeAccount

subscription_id class-attribute instance-attribute

subscription_id: StripeSubscriptionId = Field(repr=False)

customer_id class-attribute instance-attribute

customer_id: StripeCustomerId = Field(repr=False)

SubscriptionCancellationOutcome

Bases: ExperimentalModel

subscription_reference instance-attribute

subscription_reference: SafeReference

status instance-attribute

status: Literal['scheduled', 'withdrawn']

scheduled_end instance-attribute

scheduled_end: AwareDatetime | None

StripeCreditNotes

StripeCreditNotes(*, definition: ActionDefinition[CommandT, SnapshotT, PreviewT, ResultT], runtime: ActionRuntime, workflow: _Workflow[CommandT, SnapshotT, PreviewT, ResultT])

Bases: _StripeOperation[CreditNoteRequest, CreditNoteSnapshot, CreditNotePreview, CreditNoteOutcome]

Issue a line-bound credit; cash refunds and mixed allocation are unsupported.

Source code in src/threvo_actions/integrations/stripe/_operation.py
def __init__(
    self,
    *,
    definition: ActionDefinition[CommandT, SnapshotT, PreviewT, ResultT],
    runtime: ActionRuntime,
    workflow: _Workflow[CommandT, SnapshotT, PreviewT, ResultT],
) -> None:
    self.definition = definition
    self.runtime = runtime
    self._workflow = workflow

observe_effect async

observe_effect(proposal_reference: str, *, context: ReadContext) -> StripeEffectObservation
Source code in src/threvo_actions/integrations/stripe/credit_notes.py
async def observe_effect(
    self, proposal_reference: str, *, context: ReadContext
) -> StripeEffectObservation:
    observation_context = await self.runtime.observation_context(
        self.definition,
        proposal_reference=proposal_reference,
        context=context,
    )
    result = await self._workflow.observe(context=observation_context)
    return StripeEffectObservation(
        action_group=StripeHostActionGroup.CREDIT_NOTES,
        proposal_reference=proposal_reference,
        semantic_effect_reference=observation_context.semantic_effect_reference,
        observed_at=observation_context.observed_at,
        verification_status=result.status,
        outcome=(
            None
            if result.result is None
            else StripeObservedOutcome(
                status=result.result.status,
                amount=result.result.total,
            )
        ),
        external_reference=result.external_reference,
        reason_code=result.reason_code,
    )

CreditNoteConfig dataclass

CreditNoteConfig(host: CreditNoteHost, policy: CreditNotePolicy, settings: StripeActionSettings, gateway: StripeCreditNoteGateway | None = None)

host instance-attribute

host: CreditNoteHost

policy instance-attribute

settings instance-attribute

gateway class-attribute instance-attribute

gateway: StripeCreditNoteGateway | None = None

CreditNoteRequest

Bases: ExperimentalModel

intent_reference instance-attribute

intent_reference: SafeReference

invoice_reference instance-attribute

invoice_reference: SafeReference

lines instance-attribute

lines: Annotated[tuple[CreditNoteLineRequest, ...], Field(min_length=1, max_length=10)]

expected_total class-attribute instance-attribute

expected_total: Money = Field(description='Exact expected final credit including Stripe-computed tax and discounts. A different preview total is refused.')

disposition class-attribute instance-attribute

disposition: CreditDisposition = Field(description="Reduce an open invoice or credit a paid invoice customer's future balance. Neither returns cash.")

reason instance-attribute

reason: CreditNoteReason

consistent_lines

consistent_lines() -> CreditNoteRequest
Source code in src/threvo_actions/integrations/stripe/credit_notes.py
@model_validator(mode="after")
def consistent_lines(self) -> CreditNoteRequest:
    if len({line.line_reference for line in self.lines}) != len(self.lines):
        raise ValueError("credit lines must be distinct")
    if any(line.amount.currency != self.expected_total.currency for line in self.lines):
        raise ValueError("credit lines and total must use the same currency")
    if any(
        not amount.amount.is_finite() or amount.amount <= 0
        for amount in (self.expected_total, *(line.amount for line in self.lines))
    ):
        raise ValueError("credit amounts must be finite and positive")
    return self

CreditNotePolicy

Bases: ExperimentalModel

model_config class-attribute instance-attribute

model_config = ConfigDict(validate_default=True)

limits instance-attribute

limits: Annotated[tuple[Money, ...], Field(min_length=1)]

allow_live class-attribute instance-attribute

allow_live: bool = False

allow_customer_balance class-attribute instance-attribute

allow_customer_balance: bool = True

fingerprint property

fingerprint: str

unique_positive_limits

unique_positive_limits() -> CreditNotePolicy
Source code in src/threvo_actions/integrations/stripe/credit_notes.py
@model_validator(mode="after")
def unique_positive_limits(self) -> CreditNotePolicy:
    if len({limit.currency for limit in self.limits}) != len(self.limits) or any(
        not limit.amount.is_finite() or limit.amount <= 0 for limit in self.limits
    ):
        raise ValueError("credit limits must be unique, finite and positive")
    return self

permits

permits(request: CreditNoteRequest, *, livemode: bool) -> bool
Source code in src/threvo_actions/integrations/stripe/credit_notes.py
def permits(self, request: CreditNoteRequest, *, livemode: bool) -> bool:
    return (
        (not livemode or self.allow_live)
        and (
            request.disposition is CreditDisposition.INVOICE_REDUCTION
            or self.allow_customer_balance
        )
        and any(
            limit.currency == request.expected_total.currency
            and 0 < request.expected_total.amount <= limit.amount
            for limit in self.limits
        )
    )

CreditNoteRepository

Bases: StripeActionRepository[CreditNoteSnapshot, CreditNoteOutcome], Protocol

invoice async

invoice(tenant_reference: str, invoice_reference: str) -> CreditNoteInvoice
Source code in src/threvo_actions/integrations/stripe/credit_notes.py
async def invoice(self, tenant_reference: str, invoice_reference: str) -> CreditNoteInvoice: ...

CreditNoteInvoice

Bases: ExperimentalModel

model_config class-attribute instance-attribute

model_config = ConfigDict(hide_input_in_errors=True)

tenant_reference instance-attribute

tenant_reference: SafeReference

invoice_reference instance-attribute

invoice_reference: SafeReference

version instance-attribute

version: Annotated[int, Field(ge=1)]

account instance-attribute

account: StripeAccount

invoice_id class-attribute instance-attribute

invoice_id: StripeInvoiceId = Field(repr=False)

customer_id class-attribute instance-attribute

customer_id: StripeCustomerId = Field(repr=False)

currency instance-attribute

currency: CurrencyCode

currency_exponent instance-attribute

currency_exponent: Annotated[int, Field(ge=0, le=3)]

lines instance-attribute

lines: Annotated[tuple[InvoiceLineBinding, ...], Field(min_length=1)]

unique_lines

unique_lines() -> CreditNoteInvoice
Source code in src/threvo_actions/integrations/stripe/credit_notes.py
@model_validator(mode="after")
def unique_lines(self) -> CreditNoteInvoice:
    if len({line.line_reference for line in self.lines}) != len(self.lines) or len(
        {line.invoice_line_id for line in self.lines}
    ) != len(self.lines):
        raise ValueError("invoice line bindings must be unique")
    return self

CreditNoteOutcome

Bases: ExperimentalModel

invoice_reference instance-attribute

invoice_reference: SafeReference

total instance-attribute

total: Money

disposition instance-attribute

disposition: CreditDisposition

status instance-attribute

status: Literal['issued', 'void']

cash_refunded class-attribute instance-attribute

cash_refunded: Literal[False] = False

StripeActionSettings

Bases: ExperimentalModel

model_config class-attribute instance-attribute

model_config = ConfigDict(validate_default=True)

executor_identity instance-attribute

executor_identity: GovernedExecutor

authority_audience instance-attribute

authority_audience: SafeReference

authority_channel_assurance class-attribute instance-attribute

authority_channel_assurance: SafeReference = 'authenticated_host_session'

proposal_ttl class-attribute instance-attribute

proposal_ttl: Annotated[timedelta, Field(gt=timedelta(0))] = timedelta(minutes=10)

verification_delay class-attribute instance-attribute

verification_delay: Annotated[timedelta, Field(ge=timedelta(0))] = timedelta(seconds=10)

verification_lease_duration class-attribute instance-attribute

verification_lease_duration: Annotated[timedelta, Field(gt=timedelta(0))] = timedelta(minutes=2)

max_verification_attempts class-attribute instance-attribute

max_verification_attempts: Annotated[int, Field(gt=0)] = 30

StripeActionRepository

Bases: Protocol[SnapshotT, ResultContraT]

remember async

remember(snapshot: SnapshotT, requester: str) -> None

Durably bind tenant + intent + requester; reject any different rebinding.

Source code in src/threvo_actions/integrations/stripe/_operation.py
async def remember(self, snapshot: SnapshotT, requester: str) -> None:
    """Durably bind tenant + intent + requester; reject any different rebinding."""
    ...

load async

load(tenant_reference: str, effect_reference: str) -> SnapshotT
Source code in src/threvo_actions/integrations/stripe/_operation.py
async def load(self, tenant_reference: str, effect_reference: str) -> SnapshotT: ...

reserve async

reserve(snapshot: SnapshotT, *, not_after: datetime) -> StripeReservationStatus

Atomically compare binding/version/deadline and serialize all resource writers.

Exclude unresolved operations across intents and action groups. Preserve the claim if acknowledgement is uncertain; raise rather than claiming refusal. ALREADY_SUBMITTED never permits dispatch. Never reopen a consumed intent.

Source code in src/threvo_actions/integrations/stripe/_operation.py
async def reserve(self, snapshot: SnapshotT, *, not_after: datetime) -> StripeReservationStatus:
    """Atomically compare binding/version/deadline and serialize all resource writers.

    Exclude unresolved operations across intents and action groups. Preserve the
    claim if acknowledgement is uncertain; raise rather than claiming refusal.
    ALREADY_SUBMITTED never permits dispatch. Never reopen a consumed intent.
    """
    ...

record_no_submission async

record_no_submission(tenant_reference: str, effect_reference: str) -> None

Close a known no-dispatch attempt without reopening its intent identity.

Source code in src/threvo_actions/integrations/stripe/_operation.py
async def record_no_submission(self, tenant_reference: str, effect_reference: str) -> None:
    """Close a known no-dispatch attempt without reopening its intent identity."""
    ...

record_outcome async

record_outcome(tenant_reference: str, effect_reference: str, outcome: ResultContraT) -> None

Record the independently verified outcome and release the resource claim.

Source code in src/threvo_actions/integrations/stripe/_operation.py
async def record_outcome(
    self, tenant_reference: str, effect_reference: str, outcome: ResultContraT
) -> None:
    """Record the independently verified outcome and release the resource claim."""
    ...