PHP code example of tapakan / yii2-balance

1. Go to this page and download the library: Download tapakan/yii2-balance 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/ */

    

tapakan / yii2-balance example snippets


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

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

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

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

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

        // 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)
        ]);