An easy-to-use virtual wallet implementation for Laravel

Related tags

Laravel wallet
Overview

Laravel Wallet

Some apps require a prepayment system like a virtual wallet where customers can recharge credits which they can then use to pay in app stuff. With this package you can equip your eloquent models with one or multiple digital wallets that handle that for you. All the wallet activities are tracked with transactions.

Installation

Install the package with composer:

composer require muath-ye/wallet

Run Migrations

Per default the package will automatically load the migrations from the vendor folder.

If you want more flexibility, you can publish the migration files to your own migration directory with the following artisan command:

php artisan vendor:publish --provider="Muathye\Wallet\WalletServiceProvider" --tag=migrations

Make sure to deactivate automatic migration loadingby setting the config variable load_migrations to false when you have published the migration file.

Configuration

You can publish the config file with this artisan command:

php artisan vendor:publish --provider="Muathye\Wallet\WalletServiceProvider" --tag=config

This will merge the wallet.php config file where you can specify the Users, Wallets & Transactions classes if you have custom ones.

Usage

Add the HasWallet trait to your User model.

use Muathye\Wallet\Traits\HasWallet;

class User extends Model
{
    use HasWallet;

    ...
}

Then you can easily make transactions from your user model.

$user = User::find(1);
$user->wallet->balance; // 0

$user->wallet->deposit(100);
$user->wallet->balance; // 100

$user->wallet->withdraw(50);
$user->wallet->balance; // 50

$user->wallet->forceWithdraw(200);
$user->wallet->balance; // -150

You can easily add meta information to the transactions to suit your needs.

$user = User::find(1);
$user->wallet->deposit(100, ['stripe_source' => 'ch_V2IEyiB3HzGNh17bf4hsQ0fO', 'description' => 'Deposit of 100 credits from Stripe Payment']);
$user->wallet->withdraw(10, ['description' => 'Purchase of Item #12']);

Testing

This package makes use of orchestral/testbench to create a laravel testing environment. The tests will execute with a pre-configured in-memory sqlite database, so you don't need setup a database on your own.

To run the phpunit tests just make sure to install the package dependencies first via

composer install

Then execute from within the project root directory

composer test

License

The MIT License (MIT). Please see License File for more information.

You might also like...
A flexible, seamless and easy to use multitenancy solution for Laravel
A flexible, seamless and easy to use multitenancy solution for Laravel

Main: Develop: Tenanted Laravel A flexible, seamless and easy to use multitenancy solution for Laravel This package is currently under development. Ch

Livewire DataTables components for back-end. Modular, easy to use, with tons of features.

Livewire DataTables Livewire DataTables components for back-end. Modular, easy to use, with tons of features. Inspired by Caleb's Livewire Screencasts

Barcode generator in PHP that is easy to use, non-bloated and framework independent.

PHP Barcode Generator This is an easy to use, non-bloated, framework independent, barcode generator in PHP. It creates SVG, PNG, JPG and HTML images,

A collection of easy-to-use filters with clause conditions to Filament
A collection of easy-to-use filters with clause conditions to Filament

Filament Advanced Filter A collection of easy-to-use filters with clause conditions to Filament Installation Install the package via composer (require

A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.
A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.

QueryBuilderParser Status Label Status Value Build Insights Code Climate Test Coverage QueryBuilderParser is designed mainly to be used inside Laravel

A Laravel package that allows you to use multiple
A Laravel package that allows you to use multiple ".env" files in a precedent manner. Use ".env" files per domain (multi-tentant)!

Laravel Multi ENVs Use multiple .envs files and have a chain of precedence for the environment variables in these different .envs files. Use the .env

A super simple package allowing for use MySQL 'USE INDEX' and 'FORCE INDEX' statements.
A super simple package allowing for use MySQL 'USE INDEX' and 'FORCE INDEX' statements.

Laravel MySQL Use Index Scope A super simple package allowing for use MySQL USE INDEX and FORCE INDEX statements. Requirements PHP ^7.4 | ^8.0 Laravel

Implementation Package Spatie/Laravel-Permission

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

A lightway implementation of Laravel's belongs To many

A lightweigth implementation of Laravel's belongs To many relationship in cases you don't need pivot table.

Releases(v9.0.0)
Owner
Muath Assawadi
Software Engineer On a mission to improve programming quality. It's me, a full-stack web and mobile developer.
Muath Assawadi
An easy-to-use virtual wallet implementation for Laravel.

Laravel Wallet Some apps require a prepayment system like a virtual wallet where customers can recharge credits which they can then use to pay in app

Muathye 1 Feb 6, 2022
A simple wallet implementation for Laravel

Laravel Wallet A simple wallet implementation for Laravel. Installation You can install the package via composer: composer require stephenjude/laravel

Stephen Jude 216 Dec 29, 2022
Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaScript, Bootstrap e Mysql.

StampGeek Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaSc

Pablo Silva 1 Jan 13, 2022
Easy Laravel Server-Side implementation of PrimeVue Datatables

Laravel + PrimeVue Datatables This is a simple, clean and fluent serve-side implementation of PrimeVue Datatables in Laravel. Features Global Search i

Savannabits 11 Dec 29, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Rahul Thapa 2 Oct 16, 2022
Nebula is a minimalistic and easy to use administration tool for Laravel applications, made with Laravel, Alpine.js, and Tailwind CSS.

Nebula Nebula is a minimalistic and easy to use administration tool for Laravel applications, made with Laravel, Alpine.js, and Tailwind CSS. Nebula m

Nebula 228 Nov 11, 2022
A premade, easy to use local development setup to be used for authoring Laravel applications

Laravel Drydock This project is a premade, easy to use local development setup to be used for authoring Laravel applications. The deliverables of this

Alexander Trauzzi 19 Nov 11, 2022
Laravel Setting - Easily save, update and get titles, descriptions, and more. it is very easy to use.

Laravel Setting Easily save, update and get titles, descriptions, and more. it is very easy to use. This is great for storing and receiving general si

Ali Ranjbar 2 Aug 23, 2022
Easy-to-use SDK for implementing Neshan APIs in your Laravel projects.

Neshan Laravel SDK Easy-to-use SDK for implementing Neshan APIs in your Laravel projects. Install The easiest way to install is by using Composer: com

null 1 Oct 22, 2022