Validation System
Checkout forms collect free text — names, streets, company names, refund reasons — and hand it to a PSP, which forwards it into its own metadata fields. Payment Base ships a shared, character-level validator so every PSP constrains that text the same way, instead of each module inventing its own regular expressions.
The system has two halves:
The validator (
ValidationBase) — decides whether a field value is acceptable, based on per-field allow and block lists that each PSP declares.The endpoint (
ValidationApiController) — a single frontend URL that all PSP modules call, protected by a chain of eight guards.
Declaring rules
Each PSP module ships one rule file at a fixed path inside its own source tree:
<pluginRoot>/src/Resources/validation-rules.php
The file returns an array of field definitions:
<?php
declare(strict_types=1);
return [
'fields' => [
[
'field' => 'firstName',
'rules' => [
'allow' => "UNICODE_LETTERS SPACES ' - .",
'block' => ': ; < > { } [ ] ( ) | \\ / ~ ! @ # $ % ^ * = + " ? , & _',
],
],
[
'field' => 'postalCode',
'rules' => [
'allow' => 'UNICODE_LETTERS NUMBERS SPACES -',
],
],
],
];
Token grammar
Tokens are separated by spaces; consecutive spaces are collapsed. A token is either a character class (uppercase) or a single literal character:
Class token |
Matches |
|---|---|
|
Any Unicode letter ( |
|
ASCII letters only. |
|
Digits. |
|
Space characters. |
Anything else in the token list is a literal character. block is optional;
allow alone is enough for narrow fields such as postal codes or phone
numbers.
Validation order
ValidationBase::validateField() applies these rules in order:
Empty or null value → valid. Requiredness is OXID’s
RequiredFieldsValidatorconcern, not this validator’s.Unknown field name → valid. This is a documented contract: a typo in a field name must not silently reject user input.
Universal blocklist scan. Control characters and invisible codepoints are rejected regardless of the per-field rules.
Per-character scan. Block tokens are checked before allow tokens, so a character listed in both is rejected.
All characters pass → valid.
The result is a FieldValidationResult, not a boolean, so the caller can
report which character failed and why.
Obtaining a validator
ValidationBase is bound to exactly one module id — that is how it finds
the right rule file — so it is not registered as a shared service. Create
instances through the factory:
use OxidEsales\PaymentBase\Validation\ValidationBaseFactory;
final class MyCheckoutService
{
public function __construct(
private readonly ValidationBaseFactory $validationFactory
) {
}
public function check(string $street): bool
{
$validator = $this->validationFactory->create('my_psp_module_id');
return $validator->validateField('street', $street)->isValid();
}
}
The factory keeps ValidationBaseInterface defined once in payment-base
rather than duplicated per provider, and guarantees that several active PSP
modules do not collide over each other’s rule files. Rules are loaded lazily
on the first validateField() call and then cached per instance.
The validation endpoint
Frontend code validates against a single shared URL:
/index.php?cl=oepaymentvalidationapi&fnc=validate
The request carries the plugin module id, so the endpoint loads that module’s rules and no other.
Guard chain
Every request passes eight guards in priority order. The first failure ends the request; no rules are evaluated:
# |
Guard |
Rejects |
|---|---|---|
1 |
|
Any request that is not HTTP POST. |
2 |
|
Requests exceeding the body size or field count limits. |
3 |
|
Requests without an active OXID session. |
4 |
|
Cross-origin requests. |
5 |
|
Requests with a missing or invalid CSRF token. |
6 |
|
Requests naming an unknown or inactive plugin module id (HTTP 422). |
7 |
|
Requests naming an active module that ships no validation rules, for example payment-base itself (HTTP 422). |
8 |
|
Requests over the limit per visitor address and minute (HTTP 429). |
Guards are ordered cheapest-first: a wrong HTTP verb is rejected before the session is touched. The allowlist and the rules check run before the rate limit, so a request naming an invented plugin id is refused without writing a row to the rate-limit store.
Extending the chain
Register an additional guard by implementing ValidationGuardInterface and
tagging the service with oe.payment_base.validation_guard. The tag’s
priority places it in the chain — lower numbers run earlier:
services:
MyPsp\Validation\MyGuard:
tags:
- { name: oe.payment_base.validation_guard, priority: 25 }
Rate limiting
The rate-limit guard reads its budget from RateLimitConfigInterface::getLimitPerMinute(),
implemented by ModuleSettingRateLimitConfig, which returns the shop-wide
iValidationApiRatePerMinute setting (see Module Settings). A value that is
not a positive number fails the request.
The guard counts per visitor address and minute. The address is resolved by
TrustedProxyClientIp, the same service the providers’ webhook limiters use (see Webhooks and caller addresses). The plugin id and the session no longer form part of the key, so neither an invented plugin id nor a fresh session restarts the count.The limit is the same for every PSP. The former per-module override (
RateLimitOverrideInterface, tagoe.payment_base.rate_limit_override) no longer exists.DoctrineRateLimitStorecounts with one atomicINSERT … ON DUPLICATE KEY UPDATE. A database error fails the request instead of letting it through. Tests use the in-memory doubleInMemoryRateLimitStorefromtests/Support.