1. Go to this page and download the library: Download laratusk/cashflow 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/ */
use Laratusk\Cashflow\Concerns\HasBalanceTransactions;
class Account extends Model
{
use HasBalanceTransactions;
}
use Laratusk\Cashflow\Contracts\BalanceItem;
use Laratusk\Cashflow\Enums\Direction;
use Laratusk\Cashflow\Attributes\Rule;
final class Payment extends BalanceItem
{
public function __construct(
#[Rule('
#[Unique]
final class GatewayFee extends BalanceItem
{
public function __construct(
#[Rule('umeric', 'gt:0', 'max:100')]
private readonly ?float $percentage = null,
) {}
public function amount(): int
{
if ($this->amount !== null) {
return $this->amount;
}
return (int) ceil(
$this->balance()->amountOf(Payment::class) * $this->percentage / 100
);
}
public function direction(): Direction
{
return Direction::Debit;
}
}
// Hardcoded: always 2000, not overridable
final class EvidenceFee extends BalanceItem
{
public function amount(): int { return 2000; }
public function direction(): Direction { return Direction::Debit; }
}
// Overridable: amount comes from outside (auto-resolved from constructor)
final class Payment extends BalanceItem
{
public function __construct(private readonly int $amount) {}
public function direction(): Direction { return Direction::Credit; }
}
#[Unique]
final class DisputeFee extends BalanceItem
{
public function __construct(
private readonly float $exchangeRate,
private readonly Direction $direction = Direction::Debit,
) {}
public function amount(): int { return 2000; }
public function direction(): Direction { return $this->direction; }
public function exchangeRate(): float { return $this->exchangeRate; }
public function currency(): ?string { return 'EUR'; }
}
public function __construct(
#[Rule('
#[Unique]
final class GatewayFee extends BalanceItem { ... }
#[Requires(EvidenceFee::class)]
final class EvidenceFeeReversal extends BalanceItem { ... }
// Public property
$payment = new Payment(amount: 5000);
$payment->metadata = ['stripe_charge_id' => 'ch_123', 'source' => 'api'];
// Fluent setter
$balance->insert(
(new Payment(amount: 5000))->withMetadata(['stripe_charge_id' => 'ch_123'])
);