Looking to hire Laravel developers? Try LaraJobs

laravel-fortis-client maintained by hyrograsper

Description
A typed Laravel client for the Fortis payments API.
Author
Last update
2026/12/01 23:59 (dev-main)
License
Downloads
13

Comments
comments powered by Disqus

Laravel Fortis Client

A typed Laravel client for the Fortis payments API. It is a pure API client: no database, no UI and no e-commerce framework.

Status: alpha. The API will change before 1.0. Pin an exact version.

Requirements

  • PHP 8.4+
  • Laravel 12 or 13

Installation

composer require hyrograsper/laravel-fortis-client
php artisan vendor:publish --tag=fortis-client-config

Configuration

Set your credentials in the environment:

FORTIS_ENVIRONMENT=sandbox
FORTIS_USER_ID=
FORTIS_USER_API_KEY=
FORTIS_DEVELOPER_ID=
FORTIS_LOCATION_ID=
FORTIS_PRODUCT_TRANSACTION_ID=

Timeouts, retries and debug logging are documented in config/fortis.php. Debug logging records the method, path and status only, never headers or bodies.

Usage

use Hyrograsper\Fortis\Enums\ElementsAction;
use Hyrograsper\Fortis\Enums\TransactionExpand;
use Hyrograsper\Fortis\Facades\Fortis;

$token = Fortis::createClientToken(amount: 1500, action: ElementsAction::AuthOnly);

$transaction = Fortis::getTransaction($transactionId);

if ($transaction->isSuccessful()) {
    Fortis::captureTransaction($transactionId, amount: 1500);
}

// Releases the hold of an authorization that will not be captured. Returns only
// when Fortis confirms the void (status 201); otherwise it throws.
Fortis::voidTransaction($transactionId);

$refund = Fortis::refundTransaction($transactionId, amount: 500, transactionApiId: "refund-{$refundId}-1");

if (! $refund->isRefunded()) {
    // Not refunded: declined ($refund->isDeclined(), status 301, still HTTP 200)
    // or an unknown status. Never treat a returned refund as approved by default.
}

Amounts are integers in the smallest currency unit. Every operation is also an action you can resolve from the container, for example app(GetTransaction::class)->handle($id).

Failed requests throw FortisApiException, which carries the HTTP status, the decoded error body, a kind (Privilege for 403, Validation for 422, and so on) and the per-field validation messages (fieldErrors(), hasFieldError()).

Refunds: check the status, and send an idempotency key

  • Fortis answers a declined refund with HTTP 200 (status_code 301). Never treat a returned refund as approved: check isRefunded() (status 111) or isDeclined().
  • refundTransaction() requires a transactionApiId you choose: 1 to 36 letters, digits, ., _ or -. Fortis keeps it unique per location and rejects a second refund with the same id, which is what makes a retried refund safe. Fortis ignores an Idempotency-Key header.
  • A declined refund uses up its id. Use a new id for each deliberate attempt (for example refund-{id}-{attempt}), and the same id only when replaying the same attempt.
  • findTransactionByApiId($transactionApiId) returns the transaction with that id in the configured location, or null.

Expanding a transaction

$sale = Fortis::getTransaction($id, TransactionExpand::TransactionReferences, TransactionExpand::IsRefundable);

$sale->transactionReferences; // approved refunds of this sale (declined ones are not listed)
$sale->refundable;            // ?bool, only when expanded

The expansions are sent as one comma separated expand parameter, because Fortis applies only the last of repeated expand[] parameters.

Retries

Reads (GET) are retried on connection errors and on the statuses in retry.on_status_codes (429, 502, 503 and 504 by default), up to retry.attempts.

Writes are never retried blindly. With retry.writes = safe (the default):

Failure Meaning Refund / capture / void Client token
429, or refused before sending (cURL couldn't resolve, connect or handshake) not processed resent resent
timeout after sending (cURL 28), dropped connection, 5xx outcome unknown resent not resent
any other 4xx rejected thrown thrown

A refund resend reuses your transactionApiId. If Fortis answers it with "transaction_api_id already exists", the earlier attempt went through, so the client looks that refund up and returns it (approved or declined). A capture can only happen once per authorization. If a resend gets "Cannot Auth complete a non-auth-only transaction", the client reads the transaction and returns it when it is captured (status 101) for the same amount. A void can also only happen once. If a resend gets "Transaction is not voidable", the client reads the transaction and returns it when it is voided (status 201).

A write that may have been processed and cannot be settled this way throws FortisOutcomeUnknown (with method and path). Reconcile before you try again: findTransactionByApiId() for a refund, getTransaction() for a capture or void. Connection failures carry an outcome (RequestOutcome::NotProcessed or Unknown), and FortisApiException::outcome() says the same for a status.

Set FORTIS_HTTP_RETRY_WRITES=off to send every write once. Unknown outcomes still throw FortisOutcomeUnknown.

Testing

composer check

License

MIT. See LICENSE.md.