NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Credits for Laravel

Custom currencies & redemption

Custom currencies come from money-for-laravel. Declare them in money’s config:

// config/money.php — inside 'currencies'
'custom' => [
    'PTS' => ['exponent' => 0, 'name' => 'Loyalty points', 'symbol' => 'pts'],
],

Or register them in code, in your provider’s boot():

use RoundlyConsulting\Money\Currency;
use RoundlyConsulting\Money\Facades\Currencies;

// In your AppServiceProvider::boot()
Currencies::register(Currency::custom('PTS', 0, 'Loyalty points'));

Credits resolves credits.currencies lazily, on first use, so a registration in a provider that boots after credits’ is accepted. Then map a bucket to the code and use it:

// config/credits.php
'currencies' => ['points' => 'PTS'],

// anywhere
$points = Credits::for($user)->bucket('points');
$points->addMoney(Money::ofMinor(1250, 'PTS'), 'order reward');

$points->money()->minor(); // "1250"
$points->format();         // "1250" — PTS has exponent 0

Precision limit

The ledger column is a signed 64-bit integer, so a denominated bucket holds at most 9223372036854775807 minor units. That is irrelevant for fiat and points, but an 18-decimal currency such as ETH tops out at about 9.22 units — denominate large crypto balances in a coarser custom unit (a lower exponent). An amount beyond the range throws money’s AmountOverflow and writes nothing.

Recipe: redeem points for money

Credits does not convert between buckets, but money’s exchange layer makes a fixed redemption rate a two-liner — here 100 points = 1 EUR:

use RoundlyConsulting\Money\Exchange\Converter;
use RoundlyConsulting\Money\Exchange\Providers\ArrayExchangeRateProvider;

$redemption = new Converter(new ArrayExchangeRateProvider(['PTS/EUR' => '0.01'], pivot: null));

$eur = $redemption->convert(Credits::for($user)->bucket('points')->money(), 'EUR', rounding: \RoundingMode::TowardsZero);
// 1250 PTS -> Money EUR 12.50

To move the value, debit one bucket and credit the other inside one transaction — each write still passes through the overdraft guard:

use Illuminate\Support\Facades\DB;

DB::transaction(function () use ($user, $redemption): void {
    $points = Credits::for($user)->bucket('points');
    $balance = $points->money();
    $eur = $redemption->convert($balance, 'EUR', rounding: \RoundingMode::TowardsZero);

    $points->deductMoney($balance, 'redeemed for store credit');
    Credits::for($user)->bucket('store_credit')->addMoney($eur, 'redeemed from points');
});

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.