Skip to content

Commit 39dc347

Browse files
authored
Merge pull request #51 from bavix/3.1
Exchangeable
2 parents 583e85c + 5c0c1cd commit 39dc347

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1577
-115
lines changed

.phpstorm.meta.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
namespace PHPSTORM_META {
44

5+
use Bavix\Wallet\Interfaces\Rateable;
56
use Bavix\Wallet\Models\Transaction;
67
use Bavix\Wallet\Models\Transfer;
78
use Bavix\Wallet\Models\Wallet;
89
use Bavix\Wallet\Services\CommonService;
10+
use Bavix\Wallet\Services\ExchangeService;
911
use Bavix\Wallet\Services\ProxyService;
1012
use Bavix\Wallet\Services\WalletService;
1113

1214
override(\app(0), map([
15+
ExchangeService::class => ExchangeService::class,
1316
CommonService::class => CommonService::class,
1417
ProxyService::class => ProxyService::class,
1518
WalletService::class => WalletService::class,
1619
Wallet::class => Wallet::class,
1720
Transfer::class => Transfer::class,
1821
Transaction::class => Transaction::class,
22+
Rateable::class => Rateable::class,
1923
]));
2024

2125
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ laravel-wallet - Easy work with virtual wallet.
2323
* **Package**: laravel-wallet
2424
* **Version**: [![Latest Stable Version](https://poser.pugx.org/bavix/laravel-wallet/v/stable)](https://packagist.org/packages/bavix/laravel-wallet)
2525
* **PHP Version**: 7.1+
26-
* **Laravel Version**: `5.5`, `5.6`, `5.7`, `5.8`
26+
* **Laravel Version**: `5.5`, `5.6`, `5.7`, `5.8`, `5.9`
2727
* **[Composer](https://getcomposer.org/):** `composer require bavix/laravel-wallet`
2828

2929
### Upgrade Guide

changelog.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [3.1.0] - 2019-07-27
10+
### Added
11+
- Add exchange method's.
12+
- Add confirm method's.
13+
- Add method `hasWallet`, sometimes required to verify wallet existence.
14+
- Add currency service (create usd, eur,...).
15+
- Add `MinimalTaxable`.
16+
- Add `Taxable`.
17+
- New exception's.
18+
- Add decimal places (replacement ratio).
19+
20+
### Changed
21+
- Updated dependencies (composer.json).
22+
- New status `exchange`.
23+
24+
### Fixed
25+
- Wallet is not always created. #63 #51
26+
- Migration mariadb, pgsql, mysql.
27+
- Fix documentation.
28+
- Optimize code, fasted 1.1x.
29+
30+
### Deprecated
31+
- class `Taxing`.
32+
33+
### Remove
34+
- The ability to change the ratio `coefficient`.
35+
- Removed private and protected methods, the traits turned out to be more clean.
36+
937
## [3.0.4] - 2019-07-22
1038
### Fixed
1139
- fixed PostgresSQL 11
@@ -313,7 +341,8 @@ The operation is now executed in the transaction and updates the new `refund` fi
313341
- Exceptions: AmountInvalid, BalanceIsEmpty.
314342
- Models: Transfer, Transaction.
315343

316-
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.0.4...HEAD
344+
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.1.0...HEAD
345+
[3.1.0]: https://github.com/bavix/laravel-wallet/compare/3.0.4...3.1.0
317346
[3.0.4]: https://github.com/bavix/laravel-wallet/compare/3.0.3...3.0.4
318347
[3.0.3]: https://github.com/bavix/laravel-wallet/compare/3.0.2...3.0.3
319348
[3.0.2]: https://github.com/bavix/laravel-wallet/compare/3.0.1...3.0.2

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
},
3232
"require-dev": {
3333
"orchestra/testbench": "^3.7",
34-
"phpstan/phpstan": "^0.11.7",
35-
"phpunit/phpunit": "^7.5|^8.1"
34+
"phpstan/phpstan": "^0.11",
35+
"phpunit/phpunit": "^7.5|^8.2"
3636
},
3737
"autoload": {
3838
"psr-4": {

config/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
return [
44
'package' => [
5-
'coefficient' => 100.,
5+
'rateable' => \Bavix\Wallet\Simple\Rate::class,
66
],
77
'services' => [
8+
'exchange' => \Bavix\Wallet\Services\ExchangeService::class,
89
'common' => \Bavix\Wallet\Services\CommonService::class,
910
'proxy' => \Bavix\Wallet\Services\ProxyService::class,
1011
'wallet' => \Bavix\Wallet\Services\WalletService::class,
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
use Bavix\Wallet\Models\Transfer;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\MySqlConnection;
6+
use Illuminate\Database\PostgresConnection;
7+
use Illuminate\Support\Facades\DB;
8+
9+
class AddExchangeStatusTransfersTable extends Migration
10+
{
11+
12+
/**
13+
* @return string
14+
*/
15+
protected function table(): string
16+
{
17+
return (new Transfer())->getTable();
18+
}
19+
20+
/**
21+
* @return void
22+
*/
23+
public function up(): void
24+
{
25+
$enums = [
26+
Transfer::STATUS_EXCHANGE,
27+
Transfer::STATUS_TRANSFER,
28+
Transfer::STATUS_PAID,
29+
Transfer::STATUS_REFUND,
30+
Transfer::STATUS_GIFT,
31+
];
32+
33+
if (DB::connection() instanceof MySqlConnection) {
34+
$table = $this->table();
35+
$enumString = implode('\', \'', $enums);
36+
$default = Transfer::STATUS_TRANSFER;
37+
DB::statement("ALTER TABLE $table CHANGE COLUMN status status ENUM('$enumString') NOT NULL DEFAULT '$default'");
38+
DB::statement("ALTER TABLE $table CHANGE COLUMN status_last status_last ENUM('$enumString') NULL");
39+
return;
40+
}
41+
42+
if (DB::connection() instanceof PostgresConnection) {
43+
$this->alterEnum($this->table(), 'status', $enums);
44+
$this->alterEnum($this->table(), 'status_last', $enums);
45+
return;
46+
}
47+
}
48+
49+
/**
50+
* @return void
51+
*/
52+
public function down(): void
53+
{
54+
$enums = [
55+
Transfer::STATUS_TRANSFER,
56+
Transfer::STATUS_PAID,
57+
Transfer::STATUS_REFUND,
58+
Transfer::STATUS_GIFT,
59+
];
60+
61+
if (DB::connection() instanceof MySqlConnection) {
62+
$table = $this->table();
63+
$enumString = implode('\', \'', $enums);
64+
$default = Transfer::STATUS_TRANSFER;
65+
DB::statement("ALTER TABLE $table CHANGE COLUMN status status ENUM('$enumString') NOT NULL DEFAULT '$default'");
66+
DB::statement("ALTER TABLE $table CHANGE COLUMN status_last status_last ENUM('$enumString') NULL");
67+
return;
68+
}
69+
70+
if (DB::connection() instanceof PostgresConnection) {
71+
$this->alterEnum($this->table(), 'status', $enums);
72+
$this->alterEnum($this->table(), 'status_last', $enums);
73+
return;
74+
}
75+
}
76+
77+
/**
78+
* Alter an enum field constraints
79+
* @param $table
80+
* @param $field
81+
* @param array $options
82+
*/
83+
protected function alterEnum($table, $field, array $options): void
84+
{
85+
$check = "${table}_${field}_check";
86+
87+
$enumList = [];
88+
89+
foreach ($options as $option) {
90+
$enumList[] = sprintf("'%s'::CHARACTER VARYING", $option);
91+
}
92+
93+
$enumString = implode(', ', $enumList);
94+
95+
DB::transaction(function () use ($table, $field, $check, $options, $enumString) {
96+
DB::statement(sprintf('ALTER TABLE %s DROP CONSTRAINT %s;', $table, $check));
97+
DB::statement(sprintf('ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s::TEXT = ANY (ARRAY[%s]::TEXT[]))', $table, $check, $field, $enumString));
98+
});
99+
}
100+
101+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Bavix\Wallet\Models\Wallet;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
class DecimalPlacesWalletsTable extends Migration
9+
{
10+
11+
/**
12+
* @return string
13+
*/
14+
protected function table(): string
15+
{
16+
return (new Wallet())->getTable();
17+
}
18+
19+
/**
20+
* @return void
21+
*/
22+
public function up(): void
23+
{
24+
Schema::table($this->table(), function (Blueprint $table) {
25+
$table->smallInteger('decimal_places')
26+
->default(2)
27+
->after('balance');
28+
});
29+
}
30+
31+
/**
32+
* @return void
33+
*/
34+
public function down(): void
35+
{
36+
Schema::table($this->table(), function (Blueprint $table) {
37+
$table->dropColumn('decimal_places');
38+
});
39+
}
40+
41+
}

docs/_sidebar.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,25 @@
1212
- [Withdraw](withdraw)
1313
- [Transfer](transfer)
1414
- [Refresh balance](refresh)
15+
- [Confirm](confirm)
16+
<!-- - [Exchange](exchange)-->
17+
- [Withdraw taxing](taxing)
1518

1619
- Purchases
1720

1821
- [Payment](payment)
19-
- [Cart](cart)
2022
- [Payment Free](pay-free)
2123
- [Refund](refund)
24+
- [Gift](gift)
25+
- [Cart](cart)
2226

2327
- Multi Wallets
2428

2529
- [New Wallet](new-wallet)
2630
- [Transfer](wallet-transfer)
31+
32+
<!--- Currencies-->
33+
34+
<!-- - [Rate Service](rate)-->
35+
<!-- - [Create Wallet](rate-wallet)-->
36+
<!-- - [Taxing](rate-taxing)-->

docs/confirm.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## User Model
2+
3+
Add the `CanConfirm` trait and `Confirmable` interface to your User model.
4+
5+
```php
6+
use Bavix\Wallet\Interfaces\Confirmable;
7+
use Bavix\Wallet\Interfaces\Wallet;
8+
use Bavix\Wallet\Traits\CanConfirm;
9+
use Bavix\Wallet\Traits\HasWallet;
10+
11+
class UserConfirm extends Model implements Wallet, Confirmable
12+
{
13+
use HasWallet, CanConfirm;
14+
}
15+
```
16+
17+
### Example:
18+
19+
Sometimes you need to create an operation and confirm its field.
20+
That is what this trey does.
21+
22+
```php
23+
$user->balance; // int(0)
24+
$transaction = $user->deposit(100, null, false); // not confirm
25+
$transaction->confirmed; // bool(false)
26+
$user->balance; // int(0)
27+
28+
$user->confirm($transaction); // bool(true)
29+
$transaction->confirmed; // bool(true)
30+
31+
$user->balance; // int(100)
32+
```
33+
34+
It worked!

docs/exchange.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Exchange
2+
3+
A description of this feature will appear later. Wait!
4+
For now you can study to see the code in the unit test.

0 commit comments

Comments
 (0)