Digital storefront · Generic domain · EventStorming board

customer-payments

Holds the shopper's money: authorizes the total at checkout, captures it as groups ship, releases it on cancellation and refunds lost or returned packages.

GitHub ↗ · Documentation ↗ · Architecture check · Briefings

events published
8
commands
13
policies
10
read models
4
hot spots
4

The story in 4 key events

The pivotal events: the few that matter most, in the order they happen.

  1. Pivotal eventPaymentAuthorized
  2. Pivotal eventPaymentCaptured
  3. Pivotal eventPaymentReleased
  4. Pivotal eventRefundIssued

Listens to (3): contexts whose events this one reacts to

Tells (0): contexts that react to its events

none

The board, row by row

14 rows, in the order the business story happens: the main path first, then how this context reacts to the others, then the clock. Rows are small stories; read each one left to right.

  • Event
  • Command
  • Actor
  • Aggregate
  • Policy
  • Read model
  • External system
  • Hot spot
  • Opportunity
  1. Authorize a payment

    Checkout asks for the quote total to be held on the shopper's payment method, split by shipment group. The payment provider's answer decides: held or declined. A session that already has a live hold gets it back unchanged.

    ActorCheckout, for a shopper
    Read modelPayment provider's answer
    CommandAuthorizePaymentPOST /payment-authorizations
    AggregatePaymentAuthorization
    EventPaymentAuthorized
    EventPaymentDeclined

    Source: application/usecases/authorization.go · domain/paymentauthorization/create.go

  2. Cancel a hold that was never captured

    Checkout cancels a hold before anything has been captured. The payment provider voids it and every amount still waiting is released.

    ActorCheckout, for a shopper
    Read modelPayment provider's answer
    CommandVoidAuthorizationPOST /payment-authorizations/{authorizationId}/voids
    AggregatePaymentAuthorization
    EventPaymentReleased

    Source: application/usecases/authorization.go · domain/paymentauthorization/commands.go

  3. Tie the hold to the order

    checkout reports that the order was placed. The order is attached to the hold, and any shipping or tracking news that arrived before the order was known is now applied.

    Systemcheckout
    EventCheckoutCompleted
    PolicyWhenever a checkout completes, bind its order to the hold and apply the facts that waited
    Read modelFacts waiting for their order
    CommandBindOrderstarted by the policy
    AggregatePaymentAuthorization

    Source: application/usecases/consume.go · domain/paymentauthorization/commands.go · adapters/inbound/kafka/handlers.go

  4. Take the money when a group ships

    order-sourcing says a shipment group has shipped. Its share of the hold is captured at the payment provider and the tracking numbers are kept. If the order is not tied yet, the news waits.

    Systemorder-sourcing
    EventFulfillmentShipped
    PolicyWhenever a group ships, capture its share of the hold
    CommandCaptureOnShipmentstarted by the policy
    AggregatePaymentAuthorization
    EventPaymentCaptured
    Read model · kept up to dateFacts waiting for their order

    Source: application/usecases/facts.go · application/usecases/consume.go · domain/paymentauthorization/commands.go

  5. Release the money of a cancelled group

    order-sourcing says a group was cancelled. Its share of the hold is released and the hold at the payment provider shrinks, or is voided when nothing is left.

    Systemorder-sourcing
    EventFulfillmentCancelled
    PolicyWhenever a group is cancelled, release its share of the hold
    CommandReleaseOnCancellationstarted by the policy
    AggregatePaymentAuthorization
    EventPaymentReleased
    Read model · kept up to dateFacts waiting for their order

    Source: application/usecases/facts.go · application/usecases/consume.go · domain/paymentauthorization/commands.go

  6. Release the money of a group nobody can fill

    order-sourcing says no source can fulfil a group. It is handled like a cancellation: its share of the hold is released.

    Systemorder-sourcing
    EventFulfillmentUnsourceable
    PolicyWhenever a group cannot be sourced, release its share of the hold
    CommandReleaseOnCancellationstarted by the policy
    AggregatePaymentAuthorization
    EventPaymentReleased
    Read model · kept up to dateFacts waiting for their order

    Source: application/usecases/facts.go · application/usecases/consume.go · domain/paymentauthorization/commands.go

  7. Refund a lost package

    shipping-and-tracking says a package was lost. What was captured for the group that carried it goes back to the shopper, less anything already refunded.

    PolicyWhenever a package is lost, refund what was captured for its group
    Read modelCaptured amount of the group
    CommandRefundOnLostPackagestarted by the policy
    AggregateRefund
    EventRefundIssued
    EventRefundFailed

    Source: application/usecases/facts.go · application/usecases/refund.go · domain/refund/refund.go

  8. Refund a returned package

    shipping-and-tracking says a package came back to the sender. What was captured for its group is refunded, less anything already refunded.

    Systemshipping-and-tracking
    EventPackageReturned
    PolicyWhenever a package is returned, refund what was captured for its group
    Read modelCaptured amount of the group
    CommandRefundOnReturnToSenderstarted by the policy
    AggregateRefund
    EventRefundIssued
    EventRefundFailed

    Source: application/usecases/facts.go · application/usecases/refund.go · domain/refund/refund.go

  9. Refund by hand

    Operations request a refund for an order or one of its groups. It can never exceed what was captured. The payment provider is asked once; if it is unreachable the refund waits.

    ActorStorefront operations
    Read modelCaptured amount of the order
    CommandRequestRefundPOST /refunds
    AggregateRefund
    EventRefundIssued
    EventRefundFailed

    Source: application/usecases/refund.go · domain/refund/refund.go

  10. Try a failed refund again

    Operations send a failed refund back to the payment provider. A refund gets at most five attempts in all.

    ActorStorefront operations
    CommandRetryRefundPOST /refunds/{refundId}/retries
    AggregateRefund
    EventRefundIssued
    EventRefundFailed

    Source: application/usecases/refund.go · domain/refund/commands.go

  11. Finish refunds left waiting

    A sweep picks up refunds that sat requested for 30 seconds because the payment provider could not be reached, and asks the provider again.

    TimeRefund sweep
    PolicyEvery sweep, any refund requested for over 30 seconds is sent to the provider again
    CommandProcessRequestedRefundsstarted by the clock
    AggregateRefund
    EventRefundIssued
    EventRefundFailed

    Source: application/usecases/refund.go · cmd/api/policies.go

  12. Renew a hold before it lapses

    A sweep asks the payment provider for a fresh hold 24 hours before the old one ends. If the provider declines, or the hold already lapsed, the authorization expires and what was still waiting is released.

    TimeHold sweep
    PolicyEvery sweep, a hold within 24 hours of its end is renewed or, failing that, expired
    CommandReauthorizeBeforeExpirystarted by the clock
    AggregatePaymentAuthorization
    EventPaymentReauthorized
    EventPaymentAuthorizationExpired
    EventPaymentDeclined
    EventPaymentReleased

    Source: application/usecases/policies.go · domain/paymentauthorization/commands.go · cmd/api/policies.go

  13. Void holds nobody claimed

    A hold that no completed checkout tied to an order within 24 hours is voided. It is the safety net behind checkout's own give-up.

    TimeUnclaimed-hold sweep
    PolicyEvery sweep, a hold with no order after 24 hours is voided
    CommandVoidUnboundAuthorizationsstarted by the clock
    AggregatePaymentAuthorization
    EventPaymentReleased

    Source: application/usecases/policies.go · cmd/api/policies.go

  14. Tidy the facts that never found an order

    Facts still waiting for their order after 24 hours are escalated with an alert and never silently dropped. Facts older than 30 days are deleted.

    TimeHousekeeping sweep
    PolicyEvery sweep, escalate facts waiting over 24 hours and purge those older than 30 days
    CommandMaintainParkedFactsstarted by the clock
    Read model · kept up to dateFacts waiting for their order

    Source: application/usecases/policies.go · application/parked/parked.go

Hot spots and opportunities

Open questions and known gaps, each taken from a decision record or a document in the repository, never invented.

  • Hot spotAll eight events are analytics-only. No other context reacts to a payment or refund event.

    Source: docs/ddd/eventstorming.md

  • Hot spotNo alerting on declines, waiting facts, unpublished events or failed refunds. Only error log lines flag them.

    Source: docs/operations/observability.md

  • Hot spotA lost package whose shipment news never arrived is never refunded automatically. Its fact waits 24 hours, then is escalated.

    Source: docs/ddd/eventstorming.md

  • Hot spotA provider outage longer than the 24-hour lead lets a hold lapse. The next pass expires it without asking the provider.

    Source: docs/ddd/eventstorming.md

This board is a reconstruction from the code and documentation of customer-payments at origin/develop, not a workshop output. Roles are the ones the documentation names. How the boards were made.