Download the PHP package omacy/ledgerbeetle without Composer

On this page you can find all versions of the php package omacy/ledgerbeetle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ledgerbeetle

LedgerBeetle for Laravel

A double-entry ledger for Laravel with TigerBeetle as the source of truth.

Tests

Requires PHP 8.2+, ext-ffi, ext-bcmath (ext-gmp is faster if you have it), Laravel 10–13, and TigerBeetle 0.17.x. Laravel 10 is end-of-life, so prefer 11 or newer for new apps.

Install

Build the native client

PHP has no official TigerBeetle client. This package talks to TigerBeetle's official C client (tb_client) through PHP FFI, plus a small C shim (native/ledgerbeetle_tb.c) that makes its callback-based API synchronous.

Composer wipes vendor/ on every update, so build the libraries into a folder your app owns and point the package at it:

Without LEDGERBEETLE_LIB_DIR the script writes to the package's own resources/lib/<platform>/, where it's found automatically but lost on the next composer update.

The script:

  1. Downloads TigerBeetle's official tigerbeetle wheel from PyPI, which bundles prebuilt libtb_client shared libraries for every platform.
  2. Checks the wheel against the SHA-256 PyPI publishes.
  3. Writes the output folder with libtb_client.{so,dylib} and the shim libledgerbeetle_tb.{so,dylib}, which finds the client library next to itself.

It needs curl, unzip and a C compiler. It supports macOS and Linux (glibc or musl) on x86_64 and arm64. Build it for each platform you deploy to, for example in your Docker image.

The C header the shim compiles against, native/README.md says where it comes from.

Runtime requirements:

Configure

TigerBeetle only moves money between accounts on the same ledger, so each currency is its own ledger. config/ledger.php maps currencies to ledger ids (ISO 4217 numeric codes by default) and decimal scale. Never change a ledger id once accounts exist.

Use

Currency conversion

TigerBeetle only moves money within one ledger, so a conversion is a linked chain of transfers. All legs post or none do:

Leg From To Amount
fee (optional) payer fee account fee, source currency
1 payer FX.POSITION.<SRC> source amount
2 FX.POSITION.<TGT> payee source × rate, rounded down

How the rest of it works:

Balance history

New accounts get TigerBeetle's history flag (ledger.balance_history, default on). It can't be added to an existing account.

Batch posting

Every item has its own key, so a batch or a retried job never double-posts. Set the queue with LEDGER_QUEUE_CONNECTION and LEDGER_QUEUE.

HTTP API

Enable it with LEDGER_API=true. Routes go under /ledger with the middleware in ledger.api.middleware (default ['api', 'auth']).

The endpoints move money between any accounts they are given. Put your own authentication and per-account authorization in that middleware before enabling them.

Method Path Notes
POST /accounts code, name, type, currency?, parent?, prevent_overdraft?, balance_history?
GET /accounts/{code} Account plus live balance
GET /accounts/{code}/balance?at= Live, or as of a timestamp
GET /accounts/{code}/history?from=&to=&limit= Balance after each transfer
GET /accounts/{code}/transfers Paginated local records, including failed attempts
POST /transfers from, to, amount, reference?
GET /transfers/{id}
POST /transfers/{id}/reversals amount?, reason?
POST /transfer-batches items[] each with its own idempotency_key; returns 202 and queues the batch
POST /holds from, to, amount, timeout_seconds?
GET /holds/{id}
POST /holds/{id}/capture · /holds/{id}/release amount? on capture
POST /conversions from, to, amount, rate?, fee?, fee_account?
GET /conversions/{id}
POST /conversions/{id}/reversal

Request rules:

Status error.code Meaning
422 insufficient_funds The transfer would overdraw a guarded account
422 invalid_operation The ledger refused the operation
422 other TigerBeetle's own result name, e.g. pending_transfer_expired
409 idempotency_conflict Same key, different parameters
404 account_not_found
503 ledger_unavailable Outcome unknown; retry with the same key

Idempotency

Always pass an idempotencyKey derived from your own request, such as an order id or an Idempotency-Key header.

Every write first records a pending row with a fresh TigerBeetle id, then submits it. If the process dies between those steps, a retry resends the same id, and TigerBeetle answers EXISTS instead of posting twice.

Inside your own database transactions

TigerBeetle isn't part of your database transaction. Once it accepts a transfer, rolling back your transaction doesn't undo it.

By default the ledger's rows use your default connection, so they roll back with your transaction. A retry with the same key then gets a fresh TigerBeetle id and posts again. If you call the ledger inside your own transactions, give it a second connection to the same database:

Ledger rows then commit on their own:

Undoing the money movement itself, such as releasing a hold or reversing a transfer when your transaction fails, is up to your app.

Commands

Command What it does
ledger:seed-accounts --currency=USD Starter chart of accounts (ASSET.CASH.USD, REVENUE.FEES.USD, …). Safe to rerun.
ledger:sweep-holds Marks holds past their timeout as expired. Schedule it, e.g. every five minutes.
ledger:reconcile [--fix] [--deep] Compares local rows with TigerBeetle: missing accounts, transfers, holds and conversions stuck in pending, and (with --deep) the amount of every posted transfer.

Testing your app

Set LEDGER_GATEWAY=memory to use InMemoryGateway, an in-process fake that copies the TigerBeetle rules this package relies on:

Developing this package

The feature and integration suites run the same scenarios (tests/Scenarios.php), so the fake is checked against real TigerBeetle.

CI (.github/workflows/tests.yml) runs the feature suite on PHP 8.2–8.4. It then builds the shim on Linux x86_64, starts TigerBeetle with docker compose, and runs the integration suite against it.

Not in this version

License

MIT. See native/tb_client.h and the downloaded libtb_client are TigerBeetle's, under Apache-2.0.


All versions of ledgerbeetle with dependencies

PHP Build Version
Package Version
Requires ext-bcmath Version *
ext-ffi Version *
php Version ^8.2
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package omacy/ledgerbeetle contains the following files

Loading the files please wait ...