›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-payrex
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Client and resources
  • Data objects and enums
  • Errors and retries
  • Pagination

Accepting payments

  • Payment intents
  • Checkout sessions
  • Setup intents
  • Payments and refunds

Customers and billing

  • Customers
  • Eloquent customers
  • Billing statements
  • Payouts

Webhooks

  • Receiving webhooks
  • Events and listeners
  • Managing endpoints

Advanced usage

  • Testing
  • Security and operations
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Client and resources
  • Data objects and enums
  • Errors and retries
  • Pagination

Accepting payments

  • Payment intents
  • Checkout sessions
  • Setup intents
  • Payments and refunds

Customers and billing

  • Customers
  • Eloquent customers
  • Billing statements
  • Payouts

Webhooks

  • Receiving webhooks
  • Events and listeners
  • Managing endpoints

Advanced usage

  • Testing
  • Security and operations
  • Troubleshooting

byrcsc/laravel-payrex · 1.x

Errors and retries.

Handle PayRex failures and retries without duplicating payment mutations.

Every package error extends PayrexException. Catch the base class for a single application-level failure path or a subclass when the response needs special handling:

use ByRcsc\LaravelPayrex\Exceptions\InvalidRequestException;
use ByRcsc\LaravelPayrex\Exceptions\PayrexException;

try {
    $intent = Payrex::paymentIntents()->create(
        amount: 2_000,
        paymentMethods: ['card'],
    );
} catch (InvalidRequestException $exception) {
    $detail = $exception->firstError()?->detail;
    $amountErrors = $exception->errorsFor('amount');
} catch (PayrexException $exception) {
    report($exception);
}

Exception reference

ExceptionMeaning
InvalidConfigurationExceptionA required key is absent or package configuration is invalid
ApiConnectionExceptionDNS, TLS, connection, or timeout failure before a response
InvalidRequestExceptionHTTP 400 or 422
AuthenticationExceptionHTTP 401
PermissionExceptionHTTP 403
ResourceNotFoundExceptionHTTP 404 for a missing record
RouteNotFoundExceptionHTTP 404 for a missing API route
RateLimitExceptionHTTP 429
ApiErrorExceptionAny other non-successful API response
UnexpectedResponseExceptionA successful response had malformed JSON or a non-object JSON body
SignatureVerificationExceptionAn inbound webhook signature was absent, invalid, or stale
InvalidPayloadExceptionA verified webhook body was not a valid PayRex event
CustomerAlreadyCreatedExceptionAn Eloquent model already has a PayRex customer
CustomerNotCreatedExceptionAn Eloquent model has no PayRex customer yet

An invalid payment-intent amount outside the package's documented local range throws PHP's InvalidArgumentException before any network request.

Inspecting API errors

API exceptions expose the HTTP status, decoded response, and typed errors:

try {
    Payrex::paymentIntents()->retrieve('pi_...');
} catch (PayrexException $exception) {
    $exception->statusCode;
    $exception->response;
    $exception->errors();
    $exception->firstError();
    $exception->errorsFor('amount');
    $exception->hasErrorCode('parameter_invalid');
}

Each PayrexError has code, detail, parameter, meta, and raw properties. Its type() helper reads a type value from meta when available.

Response headers after a failure

lastResponse() is updated before an API exception is thrown, so response headers remain available:

use ByRcsc\LaravelPayrex\Exceptions\RateLimitException;

try {
    Payrex::customers()->list();
} catch (RateLimitException $exception) {
    $response = Payrex::lastResponse();

    logger()->warning('PayRex rate limit reached', [
        'status' => $response?->status,
        'headers' => $response?->headers,
    ]);
}

PayRex does not guarantee particular response-header names. Read headers defensively and allow for null.

Retry behavior

Only GET requests can retry automatically. A configured attempt count above one retries after:

  • a connection exception;
  • HTTP 429; or
  • HTTP 5xx.

Configure attempts and the delay:

PAYREX_RETRY_TIMES=3
PAYREX_RETRY_SLEEP=250

Set attempts to 1 to disable retries.

POST, PUT, and DELETE requests are never retried automatically. PayRex does not document idempotency keys, so replaying a mutation after an ambiguous timeout could duplicate a payment, refund, or other resource.

Handling ambiguous mutations

When a mutation times out, do not blindly repeat it. Record the local operation and reconcile it using a safe retrieval endpoint, a webhook, the PayRex dashboard, or PayRex support. Design local state transitions so a later verified webhook can finish the operation without duplicating it.

What to read next

  • Security and operations to design production recovery and monitoring.
  • Receiving webhooks to reconcile mutations from signed events.
  • Troubleshooting to diagnose specific exception messages.
PreviousData objects and enumsNextPagination

Laravel PayRex is an unofficial community SDK and is not affiliated with PayRex.

View source

On this page

  1. Exception reference
  2. Inspecting API errors
  3. Response headers after a failure
  4. Retry behavior
  5. Handling ambiguous mutations
  6. What to read next