byrcsc/laravel-payrex · 1.x
Installation and setup.
Install Laravel PayRex, publish its configuration, add credentials, and understand every supported environment option.
Laravel PayRex requires PHP 8.3 or 8.4 and Laravel 12 or 13. Install it with Composer:
composer require byrcsc/laravel-payrexLaravel discovers the package service provider and Payrex facade
automatically.
Publishing the configuration
Publish config/payrex.php:
php artisan vendor:publish --tag="payrex-config"Add your test credentials to .env:
PAYREX_SECRET_KEY=sk_test_...
PAYREX_PUBLIC_KEY=pk_test_...
PAYREX_WEBHOOK_SECRET=whsk_test_...Use live credentials only in the live environment. Laravel PayRex sends the secret key as the username in HTTP Basic authentication. It must remain on the server. The public key is the only credential intended for PayRex Elements in the browser.
Environment reference
| Variable | Default | Purpose |
|---|---|---|
PAYREX_SECRET_KEY | none | Authenticates server-side API requests |
PAYREX_PUBLIC_KEY | none | Initializes PayRex Elements in the browser |
PAYREX_WEBHOOK_SECRET | none | Verifies inbound webhook signatures |
PAYREX_BASE_URL | https://api.payrexhq.com | Points the client at PayRex, a proxy, or a local stub |
PAYREX_TIMEOUT | 30 | Total outbound request timeout in seconds |
PAYREX_CONNECT_TIMEOUT | 10 | Connection timeout in seconds |
PAYREX_RETRY_TIMES | 1 | Attempts for retryable GET requests |
PAYREX_RETRY_SLEEP | 200 | Delay between attempts in milliseconds |
PAYREX_WEBHOOKS_ENABLED | true | Registers the package webhook route |
PAYREX_WEBHOOK_PATH | payrex/webhook | URI for inbound deliveries |
PAYREX_WEBHOOK_TOLERANCE | 300 | Maximum signature age in seconds; 0 disables the age check |
PAYREX_WEBHOOK_HEADER | Payrex-Signature | Header containing the signature |
Additional webhook middleware and the event-to-class map live directly in
config/payrex.php.
Configuration caching
After changing environment values on a deployed application, rebuild Laravel's configuration cache:
php artisan config:cacheIf the client reports that no secret key is configured, first confirm the value is present in the deployed environment and then clear stale cached configuration:
php artisan optimize:clearOptional customer migration
The Eloquent customer concern stores a PayRex customer ID on one of your models. Publish the migration only if you plan to use that concern:
php artisan vendor:publish --tag="payrex-migrations"The generated migration targets the users table by default. Review and edit
the table name or column definition before running it:
php artisan migrateVerify the installation
Resolve the client and read the configured public key without making a network request:
use ByRcsc\LaravelPayrex\PayrexClient;
$payrex = app(PayrexClient::class);
$payrex->publicKey(); // "pk_test_..."The facade and the injected client resolve to the same singleton for the current application process.