PHPackages                             moecasts/laravel-wallet - 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. [Payment Processing](/categories/payments)
4. /
5. moecasts/laravel-wallet

ActiveLibrary[Payment Processing](/categories/payments)

moecasts/laravel-wallet
=======================

A laravel wallet package

1.3.2(5y ago)211905MITPHPPHP &gt;=7.1CI failing

Since May 28Pushed 5y agoCompare

[ Source](https://github.com/MoeCasts/laravel-wallet)[ Packagist](https://packagist.org/packages/moecasts/laravel-wallet)[ RSS](/packages/moecasts-laravel-wallet/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (4)Versions (7)Used By (0)

Wallet
======

[](#wallet)

- [中文](readme_ZH.md)
- [English](readme.md)

[![Build Status](https://camo.githubusercontent.com/215e3616fa5f7251d71a36242c9fc0a72a05c39e6470c8951e8d66efda692485/68747470733a2f2f7777772e7472617669732d63692e6f72672f4d6f6543617374732f6c61726176656c2d77616c6c65742e7376673f6272616e63683d6d6173746572)](https://www.travis-ci.org/MoeCasts/laravel-wallet)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b76cd159679540ab00032e76db90f58b7355e09fe8858171abb9febe2088d58c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4d6f6543617374732f6c61726176656c2d77616c6c65742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/MoeCasts/laravel-wallet/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/e4d792658fa2724870ba8fd49592ffde5c008eaff819a63574a501f337a3b9b5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4d6f6543617374732f6c61726176656c2d77616c6c65742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/MoeCasts/laravel-wallet/?branch=master)[![Build Status](https://camo.githubusercontent.com/2dd18329fb325b54802c0eb01f7497758334702fbcbca35ea9c73a2147f73e7d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4d6f6543617374732f6c61726176656c2d77616c6c65742f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/MoeCasts/laravel-wallet/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/7dd199701f831c615fdd98f9af126d10f8ca84ad294b0f75a595e202e13347fe/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4d6f6543617374732f6c61726176656c2d77616c6c65742f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)

Feature
-------

[](#feature)

- HasWallet
- Deposit
- Withdraw
- Exchange
- Transfer
- Pay
- Refund

Installation
------------

[](#installation)

### Required

[](#required)

- PHP 7.0+
- Laravel 5.5+

You can install the package using composer

```
composer require moecasts/laravel-wallet
```

If you are using Laravel &lt; 5.5, you need to add provider to your config/app.php providers array:

```
Moecasts\Laravel\Wallet\WalletServiceProvider,
```

Publish the mirgrations file:

```
php artisan vendor:publish --tag=wallet-migrations
```

As optional if you want to modify the default configuration, you can publish the configuration file:

```
php artisan vendor:publish --tag=wallet-config
```

And create tables:

```
php artisan migrate
```

Finally, add feature trait into User model:

```
use Moecasts\Laravel\Wallet\Traits\HasWallets;

class User extends Model
{
    use HasWallets;
}
```

Configurations
--------------

[](#configurations)

### Currencies

[](#currencies)

Here you can set supported currencies and its coefficient.

```
return [
    'currencies' => [
        'POI',
        'COI',
        'CNY'
    ],
    'coefficient' => [
        'COI' => 100.,
        'POI' => 1
    ],
    'exchange' => [
        'COI' => [
            'POI' => 100,
            'CNY' => 1
        ],
        'CNY' => [
            'COI' => 1
        ]
    ],
];
```

### Wallet

[](#wallet-1)

Here you can add default wallet.

```
return [
    'wallet' => [
        'table' => 'wallets',
        'model' => \Moecasts\Laravel\Wallet\Models\Wallet::class,
        'default' => [
            'currency' => 'POI'
        ],
    ],
];
```

Usage
-----

[](#usage)

### Get Wallet

[](#get-wallet)

This function will return the wallet of the currency if the currency is supported.

```
$wallet = $user->getWallet($currency)

$wallet->balance

// return the user transfers of all his wallets
$user->transfers
// return the wallet transfers
$wallet->transfers

// return the user transactions of all his wallets
$user->transactions
// return the wallet transactions
$wallet->transactions
```

### Deposit

[](#deposit)

```
$wallet->deposit($amount, $meta = [], $confirmed = true)

$wallet->deposit(233)
$wallet->deposit(233, ['description' => 'Deposit Testing'])
```

### Withdraw

[](#withdraw)

```
$wallet->withdraw($amount, $meta = [], $confirmed = true)

$wallet->withdraw(233)
$wallet->withdraw(233, ['description' => 'withdraw Testing'])

// forceWithdraw though balance is not enough
$wallet->forceWithdraw(233)
```

### Exchage

[](#exchage)

Add the `exchange` configurations to your `config/wallet.php`.

```
return [
    'exchange' => [
        // To be exchanged cuurency
        'COI' => [
            // target currency => (one to be exchanged cuurency = ? target currency)
            'POI' => 100,
            'CNY' => 1
        ],
    ]
];
```

Add the `Exchangeable` interface to `User` model.

```
use Illuminate\Database\Eloquent\Model;
use Moecasts\Laravel\Wallet\Interfaces\Exchangeable;
use Moecasts\Laravel\Wallet\Traits\HasWallets;

class User extends Model implements Exchangeable
{
    use HasWallets;
}
```

Then you can do this:

```
$wallet = $userWallet->getWallet('COI')

// $wallet->exchange(string $currency, float $mouant)
$wallet->exchange('POI', 10)
// This will return null but not exception when it failed.
$wallet->safeExchange('POI', 10)
// This will exchange though balance is not enough
$wallet->forceExchange('POI', 10)
```

### Transfer

[](#transfer)

Add the `Transferable ` interface to `User` model.

```
use Moecasts\Laravel\Wallet\Interfaces\Transferable;
use Moecasts\Laravel\Wallet\Traits\HasWallets;

class User extends Model implements Transferable
{
    use HasWallets;
}
```

Then you can do this:

```
$user = User::find(1);
$transferable = User::find(2);

$wallet = $user->getWallet($currency);

// $wallet->transfer(Transferable $transferable,float $amount,?array $meta = [], string $action = 'transfer'))
$wallet->transfer($transferable, 233);

// This will return null but not exception when it failed.
$wallet->safeTransfer($transferable, 233);
```

Wallet with the same currency of the `Transferable` will receive the payment.

### Pay

[](#pay)

Add the `HasWallets` trait and `Product` interface to `Item` model.

```
use Moecasts\Laravel\Wallet\Interfaces\Product;

class Item extends Model implements Product
{
    use HasWallets;

    public function canBePaid(string $action = 'paid'): bool
    {
        return true;
    }

    public function getProductAmount(string $action = 'paid'): float
    {
        switch ($action) {
            case 'paid':
                return 10;
                break;

            default:
                return 23.3;
                break;
        }
    }

    public function getProductMeta(string $action = 'PAID'): ?array
    {
        return [
            'title' => 'Paid for #' . $this->id
        ];
    }

    public function getReceiptWallet(string $currency): Wallet
    {
        return $this->getWallet($currency);
    }
}
```

If you want to pay to the author, you can do this.

As optional you can remove `HasWallets` trait.

```
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Moecasts\Laravel\Wallet\Interfaces\Product;

class Item extends Model implements Product
{
    public function author(): BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function canBePaid(string $action = 'paid'): bool
    {
        return true;
    }

    public function getProductAmount(string $action = 'paid'): float
    {
        switch ($action) {
            case 'paid':
                return 10;
                break;

            default:
                return 23.3;
                break;
        }
    }

    public function getProductMeta(string $action = 'paid'): ?array
    {
        return [
            'title' => 'Paid for #' . $this->id
        ];
    }

    public function getReceiptWallet(string $currency): Wallet
    {
        return $this->author->getWallet($currency);
    }
}
```

Then you can do this.

```
$user = User::first();
$product = Item::first();

$wallet = $user->getWallet($currency);

// $wallet->pay(Product $item, string $action = 'paid', bool $force = false)
$wallet->pay($item)
$wallet->pay($item, 'read')

// This will return null but not exception when it failed.
$wallet->safePay($item, 'paid')

// return bool
$wallet->paid($item, $action = 'paid')
```

Refund
------

[](#refund)

Add the `Refundable` interface to `Item` model.

```
use Moecasts\Laravel\Wallet\Interfaces\Product;
use Moecasts\Laravel\Wallet\Interfaces\Refundable;

class Item extends Model implements Product, Refundable
{
    use HasWallets;

    public function canBePaid(string $action = 'paid'): bool
    {
        return true;
    }

    public function getProductAmount(string $action = 'paid'): float
    {
        switch ($action) {
            case 'paid':
                return 10;
                break;

            default:
                return 23.3;
                break;
        }
    }

    public function getProductMeta(string $action = 'PAID'): ?array
    {
        return [
            'title' => 'Paid for #' . $this->id
        ];
    }

    public function getReceiptWallet(string $currency): Wallet
    {
        return $this->getWallet($currency);
    }
}
```

Then you can do this.

```
// $wallet->refund(Refundable $item, string $action = 'paid')
$wallet->refund($item)
$wallet->refund($item, 'read')

// This will return null but not exception when it failed.
$wallet->safeRefund($item, 'read')
```

### Let's enjoy coding!

[](#lets-enjoy-coding)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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 ~100 days

Recently: every ~117 days

Total

6

Last Release

2090d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.0

1.3.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/33d985a42d1eba6a6c5cd25ffb577f25c3ed94255269a71be995ee0b81f060c6?d=identicon)[MoeCasts](/maintainers/MoeCasts)

---

Top Contributors

[![moecasts](https://avatars.githubusercontent.com/u/37169906?v=4)](https://github.com/moecasts "moecasts (24 commits)")

---

Tags

laravelcurrencypaymentslaravel5walletlaravel6virtualcreditslaravel-walletlaravel5-packagemoecasts

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/moecasts-laravel-wallet/health.svg)

```
[![Health](https://phpackages.com/badges/moecasts-laravel-wallet/health.svg)](https://phpackages.com/packages/moecasts-laravel-wallet)
```

###  Alternatives

[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.2M19](/packages/bavix-laravel-wallet)[bavix/laravel-wallet-swap

Addition to the package laravel-wallet.

2428.9k](/packages/bavix-laravel-wallet-swap)[mannikj/laravel-wallet

Easy to use virtual wallet for your app

4311.6k](/packages/mannikj-laravel-wallet)[depsimon/laravel-wallet

Easy to use virtual wallet for your app

9521.6k1](/packages/depsimon-laravel-wallet)

PHPackages © 2026

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