PHPackages                             tapakan/yii2-balance - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tapakan/yii2-balance

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tapakan/yii2-balance
====================

Supports user balance and transactions, calculating actual balance from history

0.3.2(9y ago)61.3k2MITPHPPHP &gt;=5.6

Since Feb 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Tapakan/yii2-balance)[ Packagist](https://packagist.org/packages/tapakan/yii2-balance)[ Docs](https://github.com/Tapakan/yii2-balance.git)[ RSS](/packages/tapakan-yii2-balance/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)DependenciesVersions (6)Used By (0)

Yii2 Balance Manager
====================

[](#yii2-balance-manager)

[![Build Status](https://camo.githubusercontent.com/9546d934915ee04b1e4806544574ca65ac9edc7239aefec6305e526493380649/68747470733a2f2f7472617669732d63692e6f72672f546170616b616e2f796969322d62616c616e63652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Tapakan/yii2-balance) [![Coverage Status](https://camo.githubusercontent.com/1018bdcd4153985a5545c9a5e9d3c3c40e2b1f9d5686a1c4aef3d7e795e9d3fb/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f546170616b616e2f796969322d62616c616e63652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Tapakan/yii2-balance?branch=master) [![Dependency Status](https://camo.githubusercontent.com/e128cb0504d63298d4034aebbcf434467c3f4e6a20b709deea50ea5a032bc7d7/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3538613139336533393430623233303033326461353932352f62616467652e7376673f7374796c653d666c61742d737175617265)](https://www.versioneye.com/user/projects/58a193e3940b230032da5925) [![Latest Stable Version](https://camo.githubusercontent.com/9d3e5816ed60b423ccf209c6c745ecb0615f7b076a1859c3f4e5cde543adfbfd/68747470733a2f2f706f7365722e707567782e6f72672f746170616b616e2f796969322d62616c616e63652f762f737461626c65)](https://packagist.org/packages/tapakan/yii2-balance) [![Total Downloads](https://camo.githubusercontent.com/7e50dfec529dddd6df7a144c4031565d826ede9a02515d3c26778bacdc1609ba/68747470733a2f2f706f7365722e707567782e6f72672f746170616b616e2f796969322d62616c616e63652f646f776e6c6f616473)](https://packagist.org/packages/tapakan/yii2-balance)

Yii2 Balance can perform simple operations with the user's balance. History of operations remains.

\##Installation

Run following command

```
composer require tapakan/yii2-balance

```

or add

```
"tapakan/yii2-balance": "*"

```

to the require section of your composer.json

\##Configuration

```
    'components' => [
        'balance' => [
            'class'                  => 'Tapakan\Balance\ManagerActiveRecord',
            'accountClass'           => 'common\models\UserBalance',
            'transactionClass'       => 'common\models\UserBalanceHistory',
            'accountLinkAttribute'   => 'account_id',
            'amountAttribute'        => 'value',
            'balanceAttribute'       => 'value',
            'accountUserIdAttribute' => 'user_id'
        ],
    ],

```

\##Usage Add some value to user

```
Yii:$app->balance->increase($accountId_OR_userId_OR_condition, 500);
```

Or take

```
Yii:$app->balance->decrease($accountId_OR_userId_OR_condition, 100);
```

Calculate balance from history

```
echo Yii:$app->balance->calculateBalance($accountId_OR_userId); // 400
```

With additional information that may be stored in the balance history table

```
Yii:$app->balance->increase($accountId_OR_userId_OR_condition, 750, [
    'order_id' => 1,
    // other usefull info
]);
```

\#####Since 0.1.1 version you can revert a transaction. Let's allow transaction #35 it is removal of 200 points from the account of the user. The following command will return them into the account.

```
Yii:$app->balance->revert($transactionId)
```

#### Example of table structure

[](#example-of-table-structure)

```
        // History of operations
        $this->createTable('balance_history', [
            'account_id' => $this->integer(),
            'value'      => $this->decimal(13, 4),
            'order_id'   => $this->integer(),
            // Other usefull information
        ]);

        // Calculated balance
        $this->createTable('balance', [
            'id'         => $this->primaryKey(),
            'user_id'    => $this->integer(),
            'value'      => $this->decimal(13, 4)
        ]);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Total

4

Last Release

3305d ago

### Community

---

Top Contributors

[![Tapakan](https://avatars.githubusercontent.com/u/6270205?v=4)](https://github.com/Tapakan "Tapakan (36 commits)")

---

Tags

balanceyii2yii2-extension

### Embed Badge

![Health badge](/badges/tapakan-yii2-balance/health.svg)

```
[![Health](https://phpackages.com/badges/tapakan-yii2-balance/health.svg)](https://phpackages.com/packages/tapakan-yii2-balance)
```

###  Alternatives

[ziming/laravel-scrapingbee

A PHP Laravel Library for ScrapingBee

4310.6k](/packages/ziming-laravel-scrapingbee)[winteragency/acf-native-fields

An interface to move native WordPress fields and options into ACF for a cleaner editor layout

2511.8k](/packages/winteragency-acf-native-fields)[jameshalsall/licenser

Adds license headers to your source files

143.3k3](/packages/jameshalsall-licenser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
