Commission Payment Gateway
A custom payment gateway for handling commissions automatically in the context of an ecommerce store.
by EDFX Labs · github.com/maxxheth/commission-payment-gateway · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/maxxheth/commission-payment-gateway/archive/refs/heads/master.zipWooCommerce commission and merchant payout automation for a perfume store.
This plugin is designed around a strict accounting model:
- commission is locked from the original qualifying subtotal
- commission is not recalculated from later order edits, refunds, or chargebacks
- the plugin keeps an internal SQLite ledger as the source of truth for financial events
- merchant payout processing is separate from order state and is retryable
- sensitive ledger access is primarily operational and WP-CLI driven
Architecture
The intended implementation follows this layout:
src/Bootstrap/plugin bootstrapping and service wiringsrc/Admin/settings and operational status pagessrc/CLI/WP-CLI commandssrc/Database/SQLite connection and migrationssrc/Domain/commission, payout, and eligibility rulessrc/Ledger/SQLite ledger repository and audit trailsrc/Payout/payout coordinator and provider abstractionssrc/Security/capabilities, roles, and permission checkssrc/WooCommerce/WooCommerce hooks and order integration
The ledger is stored in a private SQLite database file controlled by the plugin. WooCommerce orders remain in WordPress/MySQL; only immutable financial events are persisted in SQLite.
Core Workflow
- WooCommerce marks an order as paid.
- The plugin checks whether the order is eligible for commission locking.
- The original qualifying subtotal is captured and commission is locked.
- A ledger entry is written to SQLite with immutable values.
- The payout workflow is queued asynchronously.
- The payout provider sends the merchant payout.
- Every state transition is recorded in the SQLite audit trail.
Commission Rules
- Default commission rate:
8% - Commission basis: original qualifying product subtotal at lock time
- Commission does not change because of:
- discounts
- returns
- refunds
- chargebacks
- order edits
- processing fees
Qualifying products are intended to support:
- all products
- products with a specific meta flag
- products in selected categories
Capabilities
The plugin is designed around custom capabilities instead of hardcoded administrator checks.
Expected capabilities include:
manage_perfume_payout_settingsview_perfume_ledger_summaryview_perfume_ledger_detailmanage_perfume_payoutsrun_perfume_reconciliationexport_perfume_ledgeruse_perfume_cli_sensitive_ops
Admin pages, manual actions, and CLI-sensitive operations should enforce these capabilities plus nonce or confirmation checks where appropriate.
SQLite Ledger
The SQLite database is the authoritative store for:
- ledger entries
- payout attempts
- payout state transitions
- retry counters
- errors
- audit events
- reconciliation snapshots
Expected tables:
ledger_entriespayout_eventsaudit_log
The SQLite store should be kept in a plugin-controlled private path and hardened against accidental web access.
Docker-Based Local Setup
The recommended local workflow is Docker-first so the same PHP and SQLite extensions are available everywhere.
Typical services:
- a custom WordPress PHP 8.2 Apache image with
pdo_sqliteenabled for plugin runtime - MariaDB for normal WordPress content storage
- a CLI/test container with Composer, Pest, WP-CLI, and PDO SQLite enabled
Typical flow:
- Start the stack with Docker Compose.
- Let the one-shot
site-initcontainer provision WordPress, WooCommerce, and activate this plugin into the shared volume. - Run Composer install inside the PHP/CLI container.
- Run Pest inside the same container.
- Use WP-CLI from the container for operational checks.
If this repository includes Docker files, the common pattern is:
docker compose up -d --build
docker compose run --rm tools composer install
docker compose run --rm tools vendor/bin/pest
docker compose run --rm tools wp plugin status commission-payment-gateway --path=/var/www/html
Default local site credentials after docker compose up -d --build:
- URL:
http://localhost:8080 - Admin user:
admin - Admin password:
admin1234
WP-CLI
The plugin is expected to expose a perfume-ledger command namespace.
Examples:
wp perfume-ledger status
wp perfume-ledger list
wp perfume-ledger show 123
wp perfume-ledger retry-payout 42
wp perfume-ledger export --format=csv
wp perfume-ledger reconcile
wp perfume-ledger lock-order 123
wp perfume-ledger payout-order 123
wp perfume-ledger audit-log --limit=100
Operational rules:
- all CLI actions should be recorded in the audit log
- sensitive operations should require capability checks or explicit confirmation flags
- command output should support table and JSON-friendly formats where useful
Payout Provider
The payout layer is built around a provider interface so payment rails can change later without rewriting ledger logic.
Expected abstractions:
PayoutProviderInterfacePayPalPayoutProvider
PayPal support should include:
- sandbox and live mode support
- credentials in plugin settings
- recipient configuration
- request/response logging with sanitization
- idempotency handling where possible
- clear retry and failure handling
Testing
Pest is the expected test framework.
Core test coverage should include:
- commission calculation
- order eligibility detection
- immutable ledger snapshots
- payout state transitions
- duplicate prevention and idempotency
- retry behavior
- capability enforcement
- CLI command behavior
- SQLite repository behavior
- payout provider abstraction behavior
- audit logging behavior
Suggested structure:
tests/Unittests/Featuretests/Integration
Run tests from the Docker container that has PHP extensions and SQLite enabled:
docker compose run --rm tools composer test
Production Notes
Before production use:
- verify the SQLite path is private and writable
- validate WooCommerce status hooks against the merchant's order flow
- confirm capability mapping for each delegated role
- verify PayPal credentials and sandbox/live environment settings
- test duplicate payout prevention with real retry scenarios
- confirm logs do not expose secrets or full payment payloads