All Projects → bavix → Laravel Wallet

bavix / Laravel Wallet

Licence: mit
Easy work with virtual wallet

Projects that are alternatives of or similar to Laravel Wallet

Laravel Translator
An Eloquent translator for Laravel
Stars: ✭ 275 (-31.42%)
Mutual labels:  eloquent, laravel, composer
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-90.27%)
Mutual labels:  eloquent, laravel, composer
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (-40.65%)
Mutual labels:  eloquent, laravel, composer
Decoy
A Laravel model-based CMS
Stars: ✭ 303 (-24.44%)
Mutual labels:  eloquent, laravel
Eloquent Builder
Provides an advanced filter for Laravel or Lumen model.
Stars: ✭ 264 (-34.16%)
Mutual labels:  eloquent, laravel
Laravel Eloquent Join
This package introduces the join magic for eloquent models and relations.
Stars: ✭ 270 (-32.67%)
Mutual labels:  eloquent, laravel
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+589.03%)
Mutual labels:  eloquent, laravel
Laravel Model Cleanup
Clean up unneeded records
Stars: ✭ 388 (-3.24%)
Mutual labels:  eloquent, laravel
Laravel
A Vimeo bridge for Laravel
Stars: ✭ 302 (-24.69%)
Mutual labels:  laravel, composer
Laravel Bookings
Rinvex Bookable is a generic resource booking system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Stars: ✭ 309 (-22.94%)
Mutual labels:  eloquent, laravel
Plans
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
Stars: ✭ 326 (-18.7%)
Mutual labels:  eloquent, laravel
Quicksand
Easily schedule regular cleanup of old soft-deleted Eloquent data.
Stars: ✭ 259 (-35.41%)
Mutual labels:  eloquent, laravel
eloquent-mongodb-repository
Eloquent MongoDB Repository Implementation
Stars: ✭ 18 (-95.51%)
Mutual labels:  composer, eloquent
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (-20.45%)
Mutual labels:  laravel, composer
Laravel Feed
Laravelium Feed package for Laravel.
Stars: ✭ 356 (-11.22%)
Mutual labels:  laravel, composer
E Wallet
Wallet project based on laravel. The project is integrated with stripe for card payments and paypal APIs. It is 90% complete with features including deposits send money with cool ui. Clone the project and start your wallet system asap. cheers
Stars: ✭ 65 (-83.79%)
Mutual labels:  wallet, laravel
Laravel Attributes
Rinvex Attributable is a robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
Stars: ✭ 304 (-24.19%)
Mutual labels:  eloquent, laravel
Laravel Shareable Models
Create shareable links from your eloquent models.
Stars: ✭ 225 (-43.89%)
Mutual labels:  eloquent, laravel
Coastercms
The repository for Coaster CMS (coastercms.org), a full featured, Laravel based Content Management System
Stars: ✭ 380 (-5.24%)
Mutual labels:  laravel, composer
Corcel
Use WordPress backend with Laravel or any PHP application
Stars: ✭ 3,504 (+773.82%)
Mutual labels:  eloquent, laravel

Laravel Wallet

Maintainability Test Coverage Financial Contributors on Open Collective Mutation testing badge

Package Rank Latest Stable Version Latest Unstable Version License composer.lock

Sparkline

laravel-wallet - Easy work with virtual wallet.

[Documentation] [Get Started]

[Документация] [Как начать]

  • Vendor: bavix
  • Package: laravel-wallet
  • Version: Latest Stable Version
  • PHP Version: 7.3+ (if you are using version 5.x then 7.2+)
  • Laravel Version: 5.5, 5.6, 5.7, 5.8, 6.x, 7.x, 8.x
  • Composer: composer require bavix/laravel-wallet

Upgrade Guide

Starting with version 5.x, support for Laravel 5 has been discontinued. Update laravel or use version 4.x.

To perform the migration, you will be helped by the instruction.

Extensions

Extension Description
Swap Addition to the laravel-wallet library for quick setting of exchange rates
Vacuum Addition to the laravel-wallet library for quick fix race condition

Usage

Add the HasWallet trait and Wallet interface to model.

use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Wallet;

class User extends Model implements Wallet
{
    use HasWallet;
}

Now we make transactions.

$user = User::first();
$user->balance; // int(0)

$user->deposit(10);
$user->balance; // int(10)

$user->withdraw(1);
$user->balance; // int(9)

$user->forceWithdraw(200, ['description' => 'payment of taxes']);
$user->balance; // int(-191)

Purchases

Add the CanPay trait and Customer interface to your User model.

use Bavix\Wallet\Traits\CanPay;
use Bavix\Wallet\Interfaces\Customer;

class User extends Model implements Customer
{
    use CanPay;
}

Add the HasWallet trait and Product interface to Item model.

use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Product;
use Bavix\Wallet\Interfaces\Customer;

class Item extends Model implements Product
{
    use HasWallet;

    public function canBuy(Customer $customer, int $quantity = 1, bool $force = null): bool
    {
        /**
         * If the service can be purchased once, then
         *  return !$customer->paid($this);
         */
        return true; 
    }
    
    public function getAmountProduct(Customer $customer)
    {
        return 100;
    }

    public function getMetaProduct(): ?array
    {
        return [
            'title' => $this->title, 
            'description' => 'Purchase of Product #' . $this->id,
        ];
    }
    
    public function getUniqueId(): string
    {
        return (string)$this->getKey();
    }
}

Proceed to purchase.

$user = User::first();
$user->balance; // int(100)

$item = Item::first();
$user->pay($item); // If you do not have enough money, throw an exception
var_dump($user->balance); // int(0)

if ($user->safePay($item)) {
  // try to buy again )
}

var_dump((bool)$user->paid($item)); // bool(true)

var_dump($user->refund($item)); // bool(true)
var_dump((bool)$user->paid($item)); // bool(false)

Eager Loading

User::with('wallet');

How to work with fractional numbers?

Add the HasWalletFloat trait and WalletFloat interface to model.

use Bavix\Wallet\Traits\HasWalletFloat;
use Bavix\Wallet\Interfaces\WalletFloat;
use Bavix\Wallet\Interfaces\Wallet;

class User extends Model implements Wallet, WalletFloat
{
    use HasWalletFloat;
}

Now we make transactions.

$user = User::first();
$user->balance; // int(100)
$user->balanceFloat; // float(1.00)

$user->depositFloat(1.37);
$user->balance; // int(237)
$user->balanceFloat; // float(2.37)

Supported by

Supported by JetBrains

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].