Smart-Contract Lifecycle

Payment Base inverts the traditional “place order, then handle failures” pattern. A click on Place Order creates a contract, not an order. The order is materialized only when all contract conditions (payment authorized, fraud check passed, stock reserved …) have been fulfilled.

Traditional vs Smart-Contract

Traditional:    Click "Order" → Order created → Payment → Roll back on failure
Smart-Contract: Click "Order" → Contract created → Conditions resolved → Order created

The Smart-Contract pattern removes complex rollback logic by deferring order creation. Failed contracts simply expire; no order ever exists for them.

States and transitions

DRAFT ──▶ PENDING ──▶ READY_TO_COMMIT ──▶ COMMITTED ──▶ FULFILLED
                       │
                       ├─▶ CANCELLED
                       ├─▶ EXPIRED
                       └─▶ FAILED

State

Meaning

DRAFT

Contract initialized, basket snapshot captured, conditions defined.

PENDING

At least one condition is awaiting resolution (payment authorization, fraud check, stock reservation, …).

READY_TO_COMMIT

All conditions fulfilled. The contract is ready to materialize an order.

COMMITTED

The OXID order has been created from the basket snapshot. The contract carries the OXORDERID.

FULFILLED

Payment captured, fulfillment complete.

CANCELLED

Cancelled by the user or by an admin before fulfillment.

EXPIRED

Reached OXEXPIRESAT without all conditions being fulfilled (default expiration: 24 h after creation).

FAILED

A condition failed permanently (e.g. fraud check rejected, payment authorization declined).

The state column is stored as oe_payments_contract.OXSTATE (see Database Schema) and is the canonical source of truth for contract status.

Conditions API

Contracts track an open-ended set of conditions. Each condition has a name and a fulfilled flag; transitions to READY_TO_COMMIT happen automatically once every condition is satisfied.

use OxidEsales\PaymentBase\Contract\PaymentContract;
use OxidEsales\PaymentBase\Contract\BasketSnapshot;

// 1. Capture basket state immutably.
$basketSnapshot = BasketSnapshot::fromBasket($basket);

// 2. Create the contract.
$contract = new PaymentContract(
    shopId:         $shopId,
    userId:         $userId,
    basketSnapshot: $basketSnapshot,
);

// 3. Add conditions that must be satisfied before the order is created.
$contract->addCondition('payment_authorized');
$contract->addCondition('fraud_check_passed');
$contract->addCondition('stock_reserved');

// 4. Persist.
$contractRepository->save($contract);

Conditions are fulfilled asynchronously, usually from a webhook handler or event listener:

$contract->fulfillCondition('payment_authorized');
$contractRepository->save($contract);

// When the LAST open condition is fulfilled, payment-base dispatches
// ContractReadyToCommitEvent automatically.

Each fulfilled condition fires a ContractConditionFulfilledEvent (see Available Events), giving consumers a hook for observability or condition-specific side effects.

Common condition names

These are the conditions used by the shipped PSP modules. They are plain strings — your module is free to define its own.

Condition

Fulfilled when

payment_authorized

PSP confirms funds are reserved (typically via webhook).

fraud_check_passed

Fraud engine returns a pass verdict.

stock_reserved

Inventory module successfully reserves the basket items.

terms_accepted

Customer confirmed terms & conditions at checkout.

Persistence

The contract aggregate is persisted to oe_payments_contract (see Database Schema). Conditions are stored as JSON in the OXCONDITIONS column; status transitions are stored in OXSTATE with an optional OXSTATEREASON for failure / cancellation diagnostics.

Capture and refund totals live on the contract itself (OXCAPTUREDAMOUNT, OXREFUNDEDAMOUNT, OXCAPTUREDAT, OXREFUNDEDAT), making per-contract financial state queryable without joining the transaction table.