Skip to content

Commit

Permalink
fix initializeMorphOneWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Mar 9, 2024
2 parents eed73be + ab1ee58 commit 22b2f45
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
19 changes: 19 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 10.1.4 - 2024-03-09

### What's Changed

* [10.x] fix initializeMorphOneWallet by [@rez1dent3](https://github.com/rez1dent3) in https://github.com/bavix/laravel-wallet/pull/905

**Full Changelog**: https://github.com/bavix/laravel-wallet/compare/10.1.3...10.1.4

## 10.1.3 - 2024-02-01

### What's Changed
Expand Down Expand Up @@ -2182,11 +2190,17 @@ Added a patch from version 4.2.1 #150
### Added

- written README.

- Project configuration file created.

- Migration 2018_11_06_222923_create_transactions_table.

- Migration 2018_11_07_192923_create_transfers_table.

- `HasWallet` trait and `Wallet` interface.

- methods:

- private checkAmount(int $amount): void
- public forceWithdraw(int $amount, ?array $meta = null, bool $confirmed = true): Transaction
- public deposit(int $amount, ?array $meta = null, bool $confirmed = true): Transaction
Expand All @@ -2200,14 +2214,17 @@ Added a patch from version 4.2.1 #150
- public resetBalance(): void

- relations:

- public transactions(): MorphMany
- public transfers(): MorphMany

- magic property

- public getBalanceAttribute(): int


- `CanBePaid` trait and `Product`, `Costomer` interface's

- methods:
- public pay(Product $product): Transfer
- public safePay(Product $product): ?Transfer
Expand All @@ -2216,7 +2233,9 @@ Added a patch from version 4.2.1 #150


- Exceptions: AmountInvalid, BalanceIsEmpty.

- Models: Transfer, Transaction.


## What's Changed

Expand Down
10 changes: 5 additions & 5 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public function getCurrencyAttribute(): string
return $this->meta['currency'] ?? Str::upper($this->slug);
}

protected function initializeMorphOneWallet(): void
{
$this->uuid ??= app(UuidFactoryServiceInterface::class)->uuid4();
}

/**
* returns all the receiving transfers to this wallet.
*
Expand All @@ -168,9 +173,4 @@ public function receivedTransfers(): HasMany
{
return $this->hasMany(config('wallet.transfer.model', Transfer::class), 'to_id');
}

protected function initializeMorphOneWallet(): void
{
$this->uuid = app(UuidFactoryServiceInterface::class)->uuid4();
}
}
4 changes: 4 additions & 0 deletions tests/Units/Domain/EagerLoadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ final class EagerLoadingTest extends TestCase
{
public function testUuidDuplicate(): void
{
$expected = [];

/** @var Collection<int, Buyer> $buyerTimes */
$buyerTimes = BuyerFactory::times(10)->create();
foreach ($buyerTimes as $buyerTime) {
self::assertTrue($buyerTime->wallet->relationLoaded('holder'));
$buyerTime->deposit(100);
$expected[] = $buyerTime->wallet->uuid;
}

/** @var Collection<int, Buyer> $buyers */
Expand All @@ -47,6 +50,7 @@ public function testUuidDuplicate(): void

self::assertCount(10, array_unique($uuids));
self::assertCount(1, array_unique($balances));
self::assertEquals($expected, $uuids);
}

public function testTransferTransactions(): void
Expand Down

0 comments on commit 22b2f45

Please sign in to comment.