PHP code example of ledgercore / sdk

1. Go to this page and download the library: Download ledgercore/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ledgercore / sdk example snippets


use LedgerCore\LedgerCore;
use LedgerCore\Money;

$lc = new LedgerCore(['api_key' => 'lk_sandbox_...', 'base_url' => 'http://localhost:8080']);
$ledger = $lc->ledgers->create(['name' => 'main']);
$wallet = $lc->accounts->create(['ledger_id' => $ledger['id'], 'name' => 'customer:42:wallet', 'type' => 'liability', 'normal_balance' => 'CREDIT']);
$txn = $lc->transactions->create(['ledger_id' => $ledger['id'], 'postings' => [/* débitos = créditos */]]);

Money::fromDecimal('100.50', 'USD', 2); // ['asset' => 'USD', 'amount' => '10050']
Money::toDecimal('10050', 2);           // "100.50"

use LedgerCore\Webhook;

$ok = Webhook::verifySignature($rawBody, $_SERVER['HTTP_X_LEDGERCORE_SIGNATURE'] ?? null, 'lcwh_...');

$cursor = null;
do {
    $page = $lc->transactions->list(limit: 100, cursor: $cursor);
    $cursor = $page['next_cursor'];
} while ($cursor !== null);

// o autopaginación:
foreach ($lc->transactions->listAll($ledgerId) as $txn) { /* ... */ }

use LedgerCore\LedgerCore;
use LedgerCore\Money;

$lc = new LedgerCore(['api_key' => 'lk_sandbox_...']);
$ledger = $lc->ledgers->create(['name' => 'main']);
$wallet = $lc->accounts->create(['ledger_id' => $ledger['id'], 'name' => 'customer:42:wallet', 'type' => 'liability', 'normal_balance' => 'CREDIT']);
$txn = $lc->transactions->create(['ledger_id' => $ledger['id'], 'postings' => [/* debits = credits */]]);
bash
composer install && composer test    # PHPUnit
php examples/quickstart.php          # smoke E2E contra el stack local