Skip to content

Events

Events

These events are published through the events pipeline on the PAYMENT_REQUEST_EVENT_STREAM ("stream:payment_gateway:payment_request_events").

The stream contains events for all countries. Each consumer is responsible for filtering events relevant to its context (typically by checking account_id in the payload).

Messages

__all__ module-attribute

__all__ = [
    "PaymentRequestCreated",
    "PaymentRequestRefunded",
    "PaymentRequestUpdated",
]

PaymentRequestCreated dataclass

PaymentRequestCreated(
    occurred_at,
    workspace_key,
    payment_request_id,
    account_id,
    bank_transfer_id,
    transfer_update_id,
    reference,
    status,
)

Bases: Message, DataClassJsonMixin

This event is published when a payment request has been created.

account_id instance-attribute

account_id

bank_transfer_id instance-attribute

bank_transfer_id

occurred_at instance-attribute

occurred_at

payment_request_id instance-attribute

payment_request_id

reference instance-attribute

reference

status instance-attribute

status

transfer_update_id instance-attribute

transfer_update_id

workspace_key instance-attribute

workspace_key

PaymentRequestRefunded dataclass

PaymentRequestRefunded(
    occurred_at,
    workspace_key,
    payment_request_id,
    account_id,
    bank_transfer_id,
    reference,
    failure_reason_code=None,
)

Bases: Message, DataClassJsonMixin

This event is published when a payment request is refunded.

account_id instance-attribute

account_id

bank_transfer_id instance-attribute

bank_transfer_id

failure_reason_code class-attribute instance-attribute

failure_reason_code = None

occurred_at instance-attribute

occurred_at

payment_request_id instance-attribute

payment_request_id

reference instance-attribute

reference

workspace_key instance-attribute

workspace_key

PaymentRequestUpdated dataclass

PaymentRequestUpdated(
    occurred_at,
    workspace_key,
    payment_request_id,
    account_id,
    bank_transfer_id,
    transfer_update_id,
    reference,
    status,
    failure_reason_code=None,
    failure_status=None,
)

Bases: Message, DataClassJsonMixin

This event is published when a payment request has been updated.

account_id instance-attribute

account_id

bank_transfer_id instance-attribute

bank_transfer_id

failure_reason_code class-attribute instance-attribute

failure_reason_code = None

failure_status class-attribute instance-attribute

failure_status = None

occurred_at instance-attribute

occurred_at

payment_request_id instance-attribute

payment_request_id

reference instance-attribute

reference

status instance-attribute

status

transfer_update_id instance-attribute

transfer_update_id

workspace_key instance-attribute

workspace_key

Payment Request Statuses

Bases: AlanBaseEnum

Status of a payout bank transfer.

failed class-attribute instance-attribute

failed = 'failed'

pending class-attribute instance-attribute

pending = 'pending'

submission_failed class-attribute instance-attribute

submission_failed = 'submission_failed'

submitted class-attribute instance-attribute

submitted = 'submitted'

succeeded class-attribute instance-attribute

succeeded = 'succeeded'

Subscribing to Events

Use the @stream_consumer decorator to subscribe to the payment request event stream:

from components.events_pipeline.internal.consumer.event import StreamEvent
from components.events_pipeline.public.consumer import stream_consumer
from components.payment_gateway.public.events.event_streams import (
    PAYMENT_REQUEST_EVENT_STREAM,
)
from components.payment_gateway.public.messages import (
    PaymentRequestCreated,
    PaymentRequestRefunded,
    PaymentRequestUpdated,
)

@stream_consumer(PAYMENT_REQUEST_EVENT_STREAM, name="my_component_handle_payment_event")
def handle_payment_request_event(event: StreamEvent, session: Session) -> None:
    """Process Payment Gateway events."""
    match event.event_type:
        case "PaymentRequestCreated":
            message = PaymentRequestCreated.from_json(event.payload)
            # handle created ...
        case "PaymentRequestUpdated":
            message = PaymentRequestUpdated.from_json(event.payload)
            # handle updated ...
        case "PaymentRequestRefunded":
            message = PaymentRequestRefunded.from_json(event.payload)
            # handle refunded ...

The consumer receives a StreamEvent with: - event.event_type — the event class name (e.g. "PaymentRequestCreated") - event.payload — JSON string, deserializable via Message.from_json(event.payload)

The session is managed by the events pipeline worker (exactly-once delivery). Do not commit manually — the worker owns the transaction.