Domain pipeline
How it works
DomainMiddleware
Runs on every request in theglobal middleware group:
- Resolves
HTTP_HOSTagainstop_domainstable - Injects
merchant_id,custom_domain,domain_typeinto request attributes - Blocks
/admin/*on custom domains (returns 404) - Uses
APP_DOMAINenv var to identify the master domain
DomainUrlService
Central URL resolver for all customer-facing and gateway-facing URLs:buildCheckoutUrl()- Checkout page URLbuildCallbackUrl()- Gateway callback URLbuildLegacyCallbackUrl()- Legacy callback URL
GATEWAY_CALLBACK_URL env > brand custom domain > APP_URL > request host
BrandThemeService
Loads per-brand visual identity (logo, colors, CSS/JS) based on the resolved domain.Configuration
Adding a custom domain
- Go to System > Domains
- Click Add Domain
- Enter the domain (e.g.,
pay.yourdomain.com) - Configure DNS to point to your OwnPay server
- Click Verify DNS
- Set domain type to
checkout
DNS requirements
Domain types
- checkout - Serves checkout, invoice, and payment pages
- api - Serves API endpoints only
Security rules
- Admin panel is only accessible on the master
APP_DOMAIN /admin/*paths return 404 on custom domains- Custom domains require
dns_verified = 1before serving content - DNS verification failure returns 503
Important rules
- Never hardcode
APP_URLor domain names for checkout/callback URLs - Always use
DomainUrlServicemethods for URL construction APP_DOMAINmust be a bare hostname (e.g.,ownpay.test), not a full URL
Further reading
- Custom domain setup - Step-by-step guide to mapping and verifying a domain
- Brands - Understand how brands isolate data and configuration
- Troubleshooting domains - Fix common DNS and verification issues