›
byrcsc/laravel-payrex · 1.x
Install Laravel PayRex, add test credentials, and verify the configured client.
Laravel PayRex requires Laravel 12 or 13. Laravel 12 is supported on PHP 8.2 through 8.5, and Laravel 13 on PHP 8.3 through 8.5. Install it with Composer:
composer require byrcsc/laravel-payrexLaravel discovers the package service provider and Payrex facade
automatically.
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. PayRex calls the public key the publishable key. It is the only
credential intended for PayRex Elements in the browser. These docs call it the
public key throughout, matching PAYREX_PUBLIC_KEY and Payrex::publicKey().
| 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.
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:clearThe 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 adds a nullable, indexed payrex_customer_id column to
the users table by default. Review and edit the table name or column
definition before running it:
php artisan migrateResolve 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.