Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
5040cea
Split product interface
rez1dent3 Apr 16, 2022
ef750e5
fix units
rez1dent3 Apr 16, 2022
593060e
remove @internal
rez1dent3 Apr 16, 2022
b502e40
ExtraDtoInterface
rez1dent3 Apr 19, 2022
effdf59
fix deptrac
rez1dent3 Apr 19, 2022
6196100
fix phpstan
rez1dent3 Apr 19, 2022
66ff727
add confirmed in exchange/transfer
rez1dent3 Apr 19, 2022
7da55b7
sort union types
rez1dent3 Apr 19, 2022
d8927c2
sort union types
rez1dent3 Apr 19, 2022
a30306c
micro optimize
rez1dent3 Apr 19, 2022
725bfa7
add unit
rez1dent3 Apr 19, 2022
ccd2dec
Improved eager loading. Quick refund goods
rez1dent3 Apr 20, 2022
853b524
fix query
rez1dent3 Apr 20, 2022
1c762d1
PHP 8+ Union types
rez1dent3 Apr 20, 2022
e65664a
fix contract
rez1dent3 Apr 20, 2022
7518b84
fix contract
rez1dent3 Apr 20, 2022
2e0ef6c
drop legacy methods
rez1dent3 Apr 20, 2022
fd04208
delete MetaServiceLegacy
rez1dent3 Apr 20, 2022
cf18d5b
delete CommonServiceLegacy
rez1dent3 Apr 20, 2022
9e5f790
Increased the severity of code style. Preparing to work with a binary…
rez1dent3 Apr 21, 2022
9f278d1
phpdoc
rez1dent3 Apr 21, 2022
bc085c5
rector
rez1dent3 Apr 21, 2022
1b93890
fix .phpstorm.meta.php
rez1dent3 Apr 21, 2022
08122fd
gtag
rez1dent3 Apr 21, 2022
b9ada5d
update ga id
rez1dent3 Apr 21, 2022
e897a08
add $balanceFloatNum
rez1dent3 Apr 21, 2022
5a8fbb1
add $balanceFloatNum
rez1dent3 Apr 21, 2022
5e1c684
fix method "getMeta"
rez1dent3 Apr 21, 2022
7899860
Support policy added
rez1dent3 Apr 21, 2022
63587ec
Support policy added
rez1dent3 Apr 21, 2022
ff56790
update readme,migrations,contracts
rez1dent3 Apr 22, 2022
df526a1
fix phpdoc
rez1dent3 Apr 22, 2022
a54ac86
An old bug that prevented full uuid support.
rez1dent3 Apr 22, 2022
7438a19
ecs-fix
rez1dent3 Apr 22, 2022
ddd35d8
Custom price with shopping cart
rez1dent3 Apr 23, 2022
1f4b7ec
Fixed phpstan, rector, ecs errors
rez1dent3 Apr 25, 2022
aaf0c30
fix contract
rez1dent3 Apr 25, 2022
7f05c84
optimize calc price
rez1dent3 Apr 25, 2022
54595a1
fix
rez1dent3 Apr 25, 2022
806128e
[custom price] fix bug
rez1dent3 Apr 25, 2022
21e628c
fix test
rez1dent3 Apr 25, 2022
e8e8acb
add test getQuantity
rez1dent3 Apr 25, 2022
c7ce67a
update docs. 9.x
rez1dent3 Apr 26, 2022
7ebaa9b
Documentation update and minor fixes
rez1dent3 Apr 26, 2022
9ec76c6
Improved eager loading for fund transfers
rez1dent3 Apr 26, 2022
4107053
fix units
rez1dent3 Apr 26, 2022
058c11b
optimizing the depth of relationships
rez1dent3 Apr 26, 2022
4028d58
fix MorphOneWallet
rez1dent3 Apr 26, 2022
31ab393
update composer.json
rez1dent3 Apr 26, 2022
e93232f
remove facade use. DB::raw()
rez1dent3 Apr 26, 2022
ada2587
codacy fix
rez1dent3 Apr 26, 2022
bd5c494
eager loading fix
rez1dent3 Apr 26, 2022
045a512
fix attribute
rez1dent3 Apr 27, 2022
cfd91a8
fix CR
rez1dent3 Apr 27, 2022
42eb5e2
update bundle
rez1dent3 Apr 27, 2022
fc14b5f
Examples of solving problems that arise for users.
rez1dent3 Apr 27, 2022
e95ffa3
fix union types
rez1dent3 Apr 27, 2022
2507fb7
added lazy loading of product wallet.
rez1dent3 Apr 29, 2022
39d068b
fix test for mariadb
rez1dent3 Apr 29, 2022
8e3c454
update docs
rez1dent3 May 2, 2022
27e0e9d
update changelog.md
rez1dent3 May 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 1 addition & 91 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -1,97 +1,7 @@
<?php

namespace PHPSTORM_META {

use Bavix\Wallet\Internal\Assembler\AvailabilityDtoAssemblerInterface;
use Bavix\Wallet\Internal\Assembler\TransactionDtoAssemblerInterface;
use Bavix\Wallet\Internal\Assembler\TransactionQueryAssemblerInterface;
use Bavix\Wallet\Internal\Assembler\TransferDtoAssemblerInterface;
use Bavix\Wallet\Internal\Assembler\TransferLazyDtoAssemblerInterface;
use Bavix\Wallet\Internal\Assembler\TransferQueryAssemblerInterface;
use Bavix\Wallet\Internal\Repository\TransactionRepositoryInterface;
use Bavix\Wallet\Internal\Repository\TransferRepositoryInterface;
use Bavix\Wallet\Services\AtomicService;
use Bavix\Wallet\Services\AtomicServiceInterface;
use Bavix\Wallet\Services\CastServiceInterface;
use Bavix\Wallet\Internal\Service\JsonServiceInterface;
use Bavix\Wallet\Services\DiscountServiceInterface;
use Bavix\Wallet\Services\PrepareServiceInterface;
use Bavix\Wallet\Internal\Transform\TransactionDtoTransformerInterface;
use Bavix\Wallet\Internal\Transform\TransferDtoTransformerInterface;
use Bavix\Wallet\Models\Transaction;
use Bavix\Wallet\Models\Transfer;
use Bavix\Wallet\Models\Wallet;
use Bavix\Wallet\Services\AssistantServiceInterface;
use Bavix\Wallet\Services\AtmServiceInterface;
use Bavix\Wallet\Services\BasketServiceInterface;
use Bavix\Wallet\Services\BookkeeperServiceInterface;
use Bavix\Wallet\Interfaces\CartInterface;
use Bavix\Wallet\Services\ConsistencyServiceInterface;
use Bavix\Wallet\Internal\Service\DatabaseServiceInterface;
use Bavix\Wallet\Services\ExchangeServiceInterface;
use Bavix\Wallet\Internal\Service\LockServiceInterface;
use Bavix\Wallet\Internal\Service\MathServiceInterface;
use Bavix\Wallet\Services\PurchaseServiceInterface;
use Bavix\Wallet\Internal\Service\StorageServiceInterface;
use Bavix\Wallet\Internal\Service\TranslatorServiceInterface;
use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface;
use Bavix\Wallet\Objects\Cart;
use Bavix\Wallet\Services\CommonServiceLegacy;
use Bavix\Wallet\Services\MetaServiceLegacy;
use Bavix\Wallet\Services\TaxServiceInterface;

override(\app(0), map([
// internal.assembler
AvailabilityDtoAssemblerInterface::class => AvailabilityDtoAssemblerInterface::class,
TransactionDtoAssemblerInterface::class => TransactionDtoAssemblerInterface::class,
TransferDtoAssemblerInterface::class => TransferDtoAssemblerInterface::class,
TransferLazyDtoAssemblerInterface::class => TransferLazyDtoAssemblerInterface::class,
// internal.query in assembler
TransactionQueryAssemblerInterface::class => TransactionQueryAssemblerInterface::class,
TransferQueryAssemblerInterface::class => TransferQueryAssemblerInterface::class,

// internal.repositories
TransactionRepositoryInterface::class => TransactionRepositoryInterface::class,
TransferRepositoryInterface::class => TransferRepositoryInterface::class,

// internal.service
DatabaseServiceInterface::class => DatabaseServiceInterface::class,
JsonServiceInterface::class => JsonServiceInterface::class,
LockServiceInterface::class => LockServiceInterface::class,
MathServiceInterface::class => MathServiceInterface::class,
StorageServiceInterface::class => StorageServiceInterface::class,
TranslatorServiceInterface::class => TranslatorServiceInterface::class,
UuidFactoryServiceInterface::class => UuidFactoryServiceInterface::class,

// internal.transform
TransactionDtoTransformerInterface::class => TransactionDtoTransformerInterface::class,
TransferDtoTransformerInterface::class => TransferDtoTransformerInterface::class,

// legacy.models
Wallet::class => Wallet::class,
Transfer::class => Transfer::class,
Transaction::class => Transaction::class,

// legacy.objects
Cart::class => Cart::class,

// services
AssistantServiceInterface::class => AssistantServiceInterface::class,
AtmServiceInterface::class => AtmServiceInterface::class,
AtomicServiceInterface::class => AtomicServiceInterface::class,
BasketServiceInterface::class => BasketServiceInterface::class,
BookkeeperServiceInterface::class => BookkeeperServiceInterface::class,
CastServiceInterface::class => CastServiceInterface::class,
ConsistencyServiceInterface::class => ConsistencyServiceInterface::class,
DiscountServiceInterface::class => DiscountServiceInterface::class,
ExchangeServiceInterface::class => ExchangeServiceInterface::class,
PrepareServiceInterface::class => PrepareServiceInterface::class,
PurchaseServiceInterface::class => PurchaseServiceInterface::class,
TaxServiceInterface::class => TaxServiceInterface::class,

// lagacy.services
CommonServiceLegacy::class => CommonServiceLegacy::class,
MetaServiceLegacy::class => MetaServiceLegacy::class,
'' => '@',
]));

}
66 changes: 58 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ laravel-wallet - Easy work with virtual wallet.
* **Laravel Version**: `9.x`
* **[Composer](https://getcomposer.org/):** `composer require bavix/laravel-wallet`


### Support Policy

| Version | Laravel | PHP | End of improvements | End of support |
|------------|----------------|-------------|---------------------|----------------|
| 7.x | ^6.0,^7.0,^8.0 | 7.4,8.0,8.1 | 1 Mar 2022 | 6 Sep 2022 |
| 8.x | ^9.0 | 8.0,8.1 | 1 May 2022 | 1 Jun 2022 |
| 9.x [LTS] | ^9.0 | 8.0,8.1 | 1 Feb 2023 | 6 Nov 2023 |

### Upgrade Guide

To perform the migration, you will be [helped by the instruction](https://bavix.github.io/laravel-wallet/#/upgrade-guide).

### Extensions

| Extension | Description |
| ----- | ----- |
| [Swap](https://github.com/bavix/laravel-wallet-swap) | Addition to the laravel-wallet library for quick setting of exchange rates |
| [Warm Up](https://github.com/bavix/laravel-wallet-warmup) | Addition to the laravel-wallet library for refresh balance wallets |
| Extension | Description |
|-----------------------------------------------------------|----------------------------------------------------------------------------|
| [Swap](https://github.com/bavix/laravel-wallet-swap) | Addition to the laravel-wallet library for quick setting of exchange rates |
| [Warm Up](https://github.com/bavix/laravel-wallet-warmup) | Addition to the laravel-wallet library for refresh balance wallets |

### Usage
Add the `HasWallet` trait and `Wallet` interface to model.
Expand Down Expand Up @@ -78,19 +87,52 @@ class User extends Model implements Customer
}
```

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

Starting from version 9.x there are two product interfaces:
- For an unlimited number of products (`ProductLimitedInterface`);
- For a limited number of products (`ProductInterface`);

An example with an unlimited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Product;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductInterface;

class Item extends Model implements Product
class Item extends Model implements ProductInterface
{
use HasWallet;

public function getAmountProduct(Customer $customer)
{
return 100;
}

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

Example with a limited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductLimitedInterface;

class Item extends Model implements ProductLimitedInterface
{
use HasWallet;

public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
{
/**
* This is where you implement the constraint logic.
*
* If the service can be purchased once, then
* return !$customer->paid($this);
*/
Expand All @@ -112,6 +154,10 @@ class Item extends Model implements Product
}
```

I do not recommend using the limited interface when working with a shopping cart.
If you are working with a shopping cart, then you should override the `PurchaseServiceInterface` interface.
With it, you can check the availability of all products with one request, there will be no N-queries in the database.

Proceed to purchase.

```php
Expand All @@ -123,7 +169,7 @@ $user->pay($item); // If you do not have enough money, throw an exception
var_dump($user->balance); // 0

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

var_dump((bool)$user->paid($item)); // bool(true)
Expand All @@ -135,7 +181,11 @@ var_dump((bool)$user->paid($item)); // bool(false)
### Eager Loading

```php
// When working with one wallet
User::with('wallet');

// When using the multi-wallet functionality
User::with('wallets');
```

### How to work with fractional numbers?
Expand Down
28 changes: 27 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [9.0.0] - 2022-05-02 #481
### Added
- ExtraDtoInterface #479
- Product custom price #485

### Changed
- Changing the logic of funds transfers #483
- Split Product interface #474
- PHP 8+ Union types #482
- Eager loading #480

### Removed
- method `Cart::addItems`
- method `Cart::addItem`
- method `Cart::setMeta`

### Updated
- Performance just got a little better
- Public contracts have become stricter
- Inside is now strongly typed

### Deprecated
- interface `Product`
- method `CartPay::paid`

## [8.4.1] - 2022-04-26
### Deprecated
- Cart::getUniqueItems
Expand Down Expand Up @@ -843,7 +868,8 @@ The operation is now executed in the transaction and updates the new `refund` fi
- Exceptions: AmountInvalid, BalanceIsEmpty.
- Models: Transfer, Transaction.

[Unreleased]: https://github.com/bavix/laravel-wallet/compare/8.4.1...develop
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/9.0.0...develop
[9.0.0]: https://github.com/bavix/laravel-wallet/compare/8.4.1...9.0.0
[8.4.1]: https://github.com/bavix/laravel-wallet/compare/8.4.0...8.4.1
[8.4.0]: https://github.com/bavix/laravel-wallet/compare/8.3.0...8.4.0
[8.3.0]: https://github.com/bavix/laravel-wallet/compare/8.2.1...8.3.0
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"infection/infection": "~0.26",
"laravel/cashier": "^13.8",
"nunomaduro/collision": "^6.2",
"orchestra/testbench": "^7.3",
"phpstan/phpstan": "^1.5",
"orchestra/testbench": "^7.4",
"phpstan/phpstan": "^1.6",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.12",
"symplify/easy-coding-standard": "^10.1",
"symplify/easy-coding-standard": "^10.2",
"vimeo/psalm": "^4.22"
},
"suggest": {
Expand Down
10 changes: 10 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Bavix\Wallet\Internal\Assembler\AvailabilityDtoAssembler;
use Bavix\Wallet\Internal\Assembler\BalanceUpdatedEventAssembler;
use Bavix\Wallet\Internal\Assembler\ExtraDtoAssembler;
use Bavix\Wallet\Internal\Assembler\OptionDtoAssembler;
use Bavix\Wallet\Internal\Assembler\TransactionDtoAssembler;
use Bavix\Wallet\Internal\Assembler\TransactionQueryAssembler;
use Bavix\Wallet\Internal\Assembler\TransferDtoAssembler;
Expand Down Expand Up @@ -36,11 +38,14 @@
use Bavix\Wallet\Services\CastService;
use Bavix\Wallet\Services\ConsistencyService;
use Bavix\Wallet\Services\DiscountService;
use Bavix\Wallet\Services\EagerLoaderService;
use Bavix\Wallet\Services\ExchangeService;
use Bavix\Wallet\Services\PrepareService;
use Bavix\Wallet\Services\PurchaseService;
use Bavix\Wallet\Services\RegulatorService;
use Bavix\Wallet\Services\TaxService;
use Bavix\Wallet\Services\TransactionService;
use Bavix\Wallet\Services\TransferService;
use Bavix\Wallet\Services\WalletService;

return [
Expand Down Expand Up @@ -96,10 +101,13 @@
'cast' => CastService::class,
'consistency' => ConsistencyService::class,
'discount' => DiscountService::class,
'eager_loader' => EagerLoaderService::class,
'exchange' => ExchangeService::class,
'prepare' => PrepareService::class,
'purchase' => PurchaseService::class,
'tax' => TaxService::class,
'transaction' => TransactionService::class,
'transfer' => TransferService::class,
'wallet' => WalletService::class,
],

Expand All @@ -126,6 +134,8 @@
'assemblers' => [
'availability' => AvailabilityDtoAssembler::class,
'balance_updated_event' => BalanceUpdatedEventAssembler::class,
'extra' => ExtraDtoAssembler::class,
'option' => OptionDtoAssembler::class,
'transaction' => TransactionDtoAssembler::class,
'transfer_lazy' => TransferLazyDtoAssembler::class,
'transfer' => TransferDtoAssembler::class,
Expand Down
5 changes: 2 additions & 3 deletions database/2018_11_06_222923_create_transactions_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTransactionsTable extends Migration
{
return new class() extends Migration {
public function up(): void
{
Schema::create($this->table(), function (Blueprint $table) {
Expand Down Expand Up @@ -42,4 +41,4 @@ private function table(): string
{
return (new Transaction())->getTable();
}
}
};
5 changes: 2 additions & 3 deletions database/2018_11_07_192923_create_transfers_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTransfersTable extends Migration
{
return new class() extends Migration {
public function up(): void
{
Schema::create($this->table(), function (Blueprint $table) {
Expand Down Expand Up @@ -70,4 +69,4 @@ private function transactionTable(): string
{
return (new Transaction())->getTable();
}
}
};
5 changes: 2 additions & 3 deletions database/2018_11_15_124230_create_wallets_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateWalletsTable extends Migration
{
return new class() extends Migration {
public function up(): void
{
Schema::create($this->table(), function (Blueprint $table) {
Expand Down Expand Up @@ -63,4 +62,4 @@ private function transactionTable(): string
{
return (new Transaction())->getTable();
}
}
};
7 changes: 3 additions & 4 deletions database/2021_11_02_202021_update_wallets_uuid_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Schema;

class UpdateWalletsUuidTable extends Migration
{
return new class() extends Migration {
public function up(): void
{
if (Schema::hasColumn($this->table(), 'uuid')) {
return;
}

// upgrade from 6.x
Schema::table($this->table(), function (Blueprint $table) {
Schema::table($this->table(), static function (Blueprint $table) {
$table->uuid('uuid')
->after('slug')
->nullable()
Expand Down Expand Up @@ -49,4 +48,4 @@ protected function table(): string
{
return (new Wallet())->getTable();
}
}
};
Loading