Skip to content

Commit 8b20340

Browse files
committed
fix bugs
1 parent ebdb041 commit 8b20340

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/Models/Transaction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
class Transaction extends Model
2121
{
2222

23+
public const TYPE_DEPOSIT = 'deposit';
24+
public const TYPE_WITHDRAW = 'withdraw';
25+
2326
/**
2427
* @var array
2528
*/

src/Traits/HasWallet.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private function checkAmount(int $amount): void
5555
public function forceWithdraw(int $amount, ?array $meta = null, bool $confirmed = true): Transaction
5656
{
5757
$this->checkAmount($amount);
58-
return $this->change(-$amount, $meta, $confirmed);
58+
return $this->change(Transaction::TYPE_WITHDRAW, -$amount, $meta, $confirmed);
5959
}
6060

6161
/**
@@ -70,7 +70,7 @@ public function forceWithdraw(int $amount, ?array $meta = null, bool $confirmed
7070
public function deposit(int $amount, ?array $meta = null, bool $confirmed = true): Transaction
7171
{
7272
$this->checkAmount($amount);
73-
return $this->change($amount, $meta, $confirmed);
73+
return $this->change(Transaction::TYPE_DEPOSIT, $amount, $meta, $confirmed);
7474
}
7575

7676
/**
@@ -190,15 +190,16 @@ protected function assemble(Wallet $wallet, Transaction $withdraw, Transaction $
190190
/**
191191
* this method adds a new transaction to the translation table
192192
*
193+
* @param string $type
193194
* @param int $amount
194195
* @param array|null $meta
195196
* @param bool $confirmed
196197
* @return Transaction
197198
* @throws
198199
*/
199-
protected function change(int $amount, ?array $meta, bool $confirmed): Transaction
200+
protected function change(string $type, int $amount, ?array $meta, bool $confirmed): Transaction
200201
{
201-
return DB::transaction(function () use ($amount, $meta, $confirmed) {
202+
return DB::transaction(function () use ($type, $amount, $meta, $confirmed) {
202203

203204
$wallet = $this;
204205
if (!($this instanceof WalletModel)) {
@@ -210,7 +211,7 @@ protected function change(int $amount, ?array $meta, bool $confirmed): Transacti
210211
}
211212

212213
return $this->transactions()->create([
213-
'type' => $amount > 0 ? 'deposit' : 'withdraw',
214+
'type' => $type,
214215
'wallet_id' => $wallet->getKey(),
215216
'uuid' => Uuid::uuid4()->toString(),
216217
'confirmed' => $confirmed,

tests/migrations/2014_10_12_000000_create_users_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class CreateUsersTable extends Migration
88
{
99
/**
10-
* Run the migrations_v2.
10+
* Run the migrations.
1111
*
1212
* @return void
1313
*/
@@ -22,7 +22,7 @@ public function up()
2222
}
2323

2424
/**
25-
* Reverse the migrations_v2.
25+
* Reverse the migrations.
2626
*
2727
* @return void
2828
*/

tests/migrations/2018_11_08_214421_create_items_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class CreateItemsTable extends Migration
88
{
99
/**
10-
* Run the migrations_v2.
10+
* Run the migrations.
1111
*
1212
* @return void
1313
*/
@@ -23,7 +23,7 @@ public function up()
2323
}
2424

2525
/**
26-
* Reverse the migrations_v2.
26+
* Reverse the migrations.
2727
*
2828
* @return void
2929
*/

0 commit comments

Comments
 (0)