Refund Intent Routing

Sprint 03 (2026-05-19) introduced a centralized refund-routing mechanism. Consumer modules (e.g. opalreturns) emit a high-level “I want to refund contract X” intent; payment-base decides which low-level verb to invoke on the PSP — refund, cancel-auth or partial-capture — based on the current contract state.

This keeps return / refund modules free of PSP-specific knowledge: they never need to inspect whether a payment was captured, partially captured, or only authorized.

The routing decision

Given a refund intent for a contract, the RefundIntentHandler resolves the verb roughly as follows:

Contract / capture state

Routed verb

PSP-side effect

Authorized, nothing captured

cancel-auth

Release the authorization, no money moved.

Fully captured

refund

Standard refund flow.

Partially captured, intent equals captured amount

refund

Refund what was actually captured.

Partially captured, intent < captured amount

partial-capture

Refund a slice of the captured total.

The exact decision logic lives in RefundIntentHandler and reads from PaymentCaptureStatusQueryInterface plus the contract’s OXCAPTUREDAMOUNT / OXREFUNDEDAMOUNT columns.

How consumers participate

Listener binding is the consumer’s responsibility. The consumer’s own services.yaml tags kernel.event_listener against its own concrete event class. This is because Symfony’s EventDispatcher resolves listeners by exact dispatched class name, not by interface walk — so the consumer module is the place that knows which event(s) it dispatches.

Reference DI wiring in payment-base

The handler is registered with optional dependencies, so the module activates standalone even when no consumer is present:

OxidEsales\PaymentBase\EventSystem\Handler\RefundIntentHandler:
  arguments:
    $contractRepository: '@?OxidEsales\PaymentBase\Repository\ContractRepositoryInterface'
    $broker:             '@?OxidEsales\PaymentBase\EventSystem\Broker\EventBrokerInterface'
    $captureStatusQuery: '@?OxidEsales\PaymentBase\Service\PaymentCaptureStatusQueryInterface'
    $logger:             '@?Psr\Log\LoggerInterface'
  public: true

Consumer wiring (example)

A returns module defines its own RefundIntentEvent and binds the payment-base handler as a listener against that concrete class:

services:
  OxidEsales\PaymentBase\EventSystem\Handler\RefundIntentHandler:
    tags:
      - name: kernel.event_listener
        event: YourCompany\Returns\Event\RefundIntentEvent
        method: handle

Dispatching the intent then becomes a one-liner in the consumer’s domain code:

use YourCompany\Returns\Event\RefundIntentEvent;

$this->eventDispatcher->dispatch(
    new RefundIntentEvent(
        contractId: $contract->getId(),
        amount:     $refundAmount,
        reason:     'customer-request',
    )
);

payment-base routes the verb, dispatches it through the broker to the active PSP, and emits a PaymentRefundedEvent on success.