The Sylius commerce service
Sylius sells; the LMS decides who has access. Sylius owns the catalogue, cart, checkout, taxes and payments. The LMS holds the prices it wants, mirrors them to Sylius as products, and grants access only after it has read a paid order back from Sylius (entitlements and order events).
Run it locally
Section titled “Run it locally”The service is optional and outside the default stack: one image, two services, in the compose profile commerce.
docker compose -f api/docker-compose.yml --profile commerce up -d sylius sylius-workersyliusmigrates its own database (sylius, on the shared PostgreSQL server), creates the one admin API user the LMS signs in with and serves the Admin and Shop APIs on port 8080 inside the network. Caddy does not route it.sylius-workerdelivers outbox events to the LMS (signed webhooks, retried for 72 hours).- Point the API (platform env) at it:
COMMERCE_PROVIDER=sylius,COMMERCE_SYLIUS_URL=http://sylius:8080,COMMERCE_SYLIUS_ADMIN_EMAILandCOMMERCE_SYLIUS_ADMIN_PASSWORD. The values in the compose file are development defaults; never reuse them. Tenant envs never hold Sylius credentials.
The native Sylius admin UI needs Webpack assets that are not built into the image yet (CM-8); the Admin API does not.
One channel per tenant
Section titled “One channel per tenant”One Sylius instance serves every tenant, with a channel per tenant (code = tenant slug, COMMERCE_CHANNEL). Sylius has
no tenant isolation of its own, so the adapter is bound to the tenant’s channel: product codes, prices, order reads
and the event feed all carry it, an order of another channel is reported with that channel and refused by the LMS, and
a customer linked in another channel counts as unlinked.
The channel is made when the tenant is
Section titled “The channel is made when the tenant is”With COMMERCE_PROVIDER=sylius in the platform env, ulams tenant create (and POST /api/platform/tenants) has a step
commerce_channel after permissions. It creates the channel (code = tenant slug) with:
- currency: PLN when the platform language is Polish, EUR otherwise; the base currency is fixed at creation. Override
once per tenant with
ulams:tenant:set-env <slug> --set=COMMERCE_CURRENCY=USDbefore the step runs; - locale from the platform language (
COMMERCE_LOCALEoverrides), the 27 EU countries plusCOMMERCE_EXTRA_COUNTRIES, the tenant’s front host as hostname, shipping skipped (digital products); - default tax zone of the seller country (
COMMERCE_SELLER_COUNTRY, defaultPL; confirm with the accountant); - the payment methods below, and the bridge link: the tenant’s webhook URL
(
<api host>/api/commerce/webhooks/sylius) and a webhook secret made once, kept encrypted in the platform database and written to the tenant env asCOMMERCE_CHANNELandCOMMERCE_WEBHOOK_SECRET.
It is idempotent. Tenants made before commerce was switched on get their channel from the upgrade step, or by hand with
php artisan ulams:tenant:commerce-channel [slug]. Deleting a tenant disables its channel and keeps its orders and
products. A different base currency for an existing channel is refused (HTTP 409 from the command’s point of view); the
channel stays as it was.
EU VAT
Section titled “EU VAT”php artisan ulams:commerce:seed-eu-vat (also run by the first channel) creates the 27 member states as countries, a
zone eu-<cc> each, the tax category e-service and one rate vat-<cc> per country, included in the price, from
api/packages/commerce-sylius/resources/eu-vat-rates.json. Sylius takes the zone from the billing address and falls back
to the channel’s default zone, so a Polish buyer pays 23 % and a German buyer 19 % of the same gross price (checked in a
real checkout). The rates are seed data marked unconfirmed: the seller’s accountant must confirm every rate and the
seller country before the first live sale. Nothing here files or collects evidence for the OSS return, and B2B reverse
charge is CM-9.
Payment methods
Section titled “Payment methods”| Method | Created when | Notes |
|---|---|---|
stripe (Stripe Checkout) |
COMMERCE_STRIPE_PUBLISHABLE_KEY and COMMERCE_STRIPE_SECRET_KEY are in the platform env |
Use pk_test_/sk_test_ keys first. BLIK and Przelewy24 are enabled in the Stripe dashboard |
offline (pay later) |
COMMERCE_SYLIUS_OFFLINE=true |
Development and tests only |
Keys rotated in the env reach the Sylius method the next time the channel step runs. Sylius stores the gateway keys and shows them to its admin API user: the Admin API is internal and only the LMS holds its credentials.
Catalogue sync
Section titled “Catalogue sync”The LMS keeps the intent in commerce_sellable_prices (a price and “for sale”). A sellable is a course, a bundle (a
set of courses bought once) or an access pass (a course or bundle for a number of days). The product at Sylius is
code ul-<channel>-<type>-<id> with one variant <code>-v that needs no shipping, carrying the channel price.
- A product is enabled only while the sellable is for sale and every course in it is published. Unpublishing a course disables its product, its bundles and its passes; publishing enables them again. Nothing is ever deleted, because orders reference the variant.
- A price change or a course status change queues
SyncSellableJob(retried with backoff while Sylius is down). An unchanged product is not sent again; the failure reason stays on the product link (sync_error). - A bundle grants one entitlement per course (
<provider>:<channel>:order_item:<item>:course:<course>); courses added later are not granted to past buyers. An access pass ends the access that many days after the purchase.
Manage them with the admin API (permission commerce_prices_manage, scope area commerce):
| Request | What it does |
|---|---|
GET /api/admin/commerce/products |
Prices and the state of each product (last sync, last error) |
PUT /api/admin/commerce/products/{type}/{id} |
Set the price (price_minor, currency) and for_sale |
POST /api/admin/commerce/bundles |
Create a bundle of courses |
POST /api/admin/commerce/access-passes |
Create an access pass on a course or bundle |
CLI: ulams commerce products-list, products-set-price, bundles-create, access-passes-create.
php artisan ulams:commerce:sync # push what is not yet in stepphp artisan ulams:commerce:sync --check # report drift, exit 1 when there is anyphp artisan ulams:commerce:sync --check --repair # and push the drifted sellablesNightly drift check and full sweep
Section titled “Nightly drift check and full sweep”With COMMERCE_NIGHTLY=true the scheduler runs, per tenant, ulams:commerce:reconcile --full (03:10) and
ulams:commerce:sync --check --repair (03:40). Both store a row in commerce_drift_reports.
- The catalogue check reads every product back and reports a product that was deleted (
missing), re-priced (price), enabled or disabled by hand (enabled), renamed (name) or that failed its last sync (error). - The order sweep lists the channel’s completed orders of the last 35 days (
--since=for a longer look) and repairs both directions without reading any event: a paid line without an entitlement is granted, a refunded or cancelled line that still grants access is revoked.--dry-runonly reports. The 5-minuteulams:commerce:reconcilereads the bridge’s event feed instead.
The ulams bridge bundle
Section titled “The ulams bridge bundle”api/sylius/bundles/UlamsBridgeBundle adds what stock Sylius lacks:
- a transactional outbox: every payment transition (paid, refunded, partially refunded, cancelled after payment) writes an event in the same database transaction as the transition, so an event exists if and only if the transition committed;
- a pull feed
GET /api/v2/admin/ulams/events?channel=&after=&limit=that does not depend on delivery; - signed delivery to the URL in the channel’s link (HMAC over
<t>.<body>, the same scheme as the other ulams webhooks), retried with exponential backoff for 72 hours. Links are written only by the LMS provisioner throughPUT /api/v2/admin/ulams/channel-links/{channel}; the secret is sealed at rest and never returned; - the customer field
ulamsUserRef(<channel>:<LMS user id>), written by the LMS, which is how an order is tied to an LMS user (never by e-mail address); ulams:admin-api-user:ensure, which creates the admin API user from the environment.
Tests, and what needs a live Sylius
Section titled “Tests, and what needs a live Sylius”| Suite | Runs | Proves |
|---|---|---|
commerce provider contract (WellmsProviderContractTest) |
always | The Wellms adapter meets the contract |
commerce-sylius with an in-memory Sylius |
always | Request shapes, token handling, errors, channel binding |
commerce-sylius TenantCreateMakesChannelTest |
always | ulams tenant create through the real provisioner makes the channel, link and env |
commerce-sylius Live/* |
with COMMERCE_SYLIUS_LIVE_URL and the live admin credentials |
The same contract and the whole flow (sync, checkout, access, refund, sweep, drift) against a real Sylius 2.3 |
api/sylius bridge tests |
always (CI job sylius) |
Outbox recording, feed, delivery signing and retry, channel links, sealing |
The signature the bridge produces and the LMS verifies is checked against one recorded vector in both suites. Not verified without a real service: payment through Stripe, BLIK or Przelewy24 (needs a Stripe account), delivery from the bridge to a running LMS over the network (the delivery request and its signature are tested on both sides, not the connection), and the native admin UI.