Skip to content

Commit 25c2fcc

Browse files
committed
An old bug that prevented full uuid support.
1 parent 4521cb0 commit 25c2fcc

File tree

8 files changed

+24
-16
lines changed

8 files changed

+24
-16
lines changed

src/Services/PrepareService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public function transferLazy(
9797

9898
return $this->transferLazyDtoAssembler->create(
9999
$from,
100-
$to,
100+
$toWallet,
101101
$discount,
102102
$fee,
103103
$this->withdraw($from, $withdrawAmount, $withdrawOption->getMeta(), $withdrawOption->isConfirmed()),
104-
$this->deposit($to, $depositAmount, $depositOption->getMeta(), $depositOption->isConfirmed()),
104+
$this->deposit($toWallet, $depositAmount, $depositOption->getMeta(), $depositOption->isConfirmed()),
105105
$status
106106
);
107107
}

src/Services/PurchaseService.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
final class PurchaseService implements PurchaseServiceInterface
1313
{
14+
public function __construct(private CastServiceInterface $castService)
15+
{
16+
}
17+
1418
public function already(Customer $customer, BasketDtoInterface $basketDto, bool $gifts = false): array
1519
{
1620
$status = $gifts
@@ -20,8 +24,7 @@ public function already(Customer $customer, BasketDtoInterface $basketDto, bool
2024
$arrays = [];
2125
$query = $customer->transfers();
2226
foreach ($basketDto->items() as $itemDto) {
23-
/** @var Model $product */
24-
$product = $itemDto->product();
27+
$wallet = $this->castService->getWallet($itemDto->product());
2528

2629
/**
2730
* As part of my work, "with" was added, it gives a 50x boost for a huge number of returns. In this case,
@@ -30,8 +33,8 @@ public function already(Customer $customer, BasketDtoInterface $basketDto, bool
3033
*/
3134
$arrays[] = (clone $query)
3235
->with(['deposit', 'withdraw.wallet'])
33-
->where('to_type', $product->getMorphClass())
34-
->where('to_id', $product->getKey())
36+
->where('to_type', $wallet->getMorphClass())
37+
->where('to_id', $wallet->getKey())
3538
->whereIn('status', $status)
3639
->orderBy('id', 'desc')
3740
->limit(count($itemDto))

src/Traits/HasGift.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function gift(Wallet $to, ProductInterface $product, bool $force = false)
8484
$withdraw->getKey(),
8585
Transfer::STATUS_GIFT,
8686
$castService->getWallet($to),
87-
$castService->getModel($product),
87+
$castService->getWallet($product),
8888
$discount,
8989
$fee
9090
);

tests/Infra/Models/Item.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Bavix\Wallet\Models\Transfer;
1010
use Bavix\Wallet\Models\Wallet;
1111
use Bavix\Wallet\Services\CastService;
12+
use Bavix\Wallet\Services\CastServiceInterface;
1213
use Bavix\Wallet\Traits\HasWallet;
1314
use Illuminate\Database\Eloquent\Model;
1415
use Illuminate\Database\Eloquent\Relations\MorphMany;
@@ -55,7 +56,8 @@ public function getMetaProduct(): ?array
5556
*/
5657
public function boughtGoods(array $walletIds): MorphMany
5758
{
58-
return $this
59+
return app(CastServiceInterface::class)
60+
->getWallet($this)
5961
->morphMany(config('wallet.transfer.model', Transfer::class), 'to')
6062
->where('status', Transfer::STATUS_PAID)
6163
->where('from_type', config('wallet.wallet.model', Wallet::class))

tests/Units/Domain/DiscountTaxTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ public function testPay(): void
6565

6666
self::assertInstanceOf(Buyer::class, $transfer->from->holder);
6767
self::assertInstanceOf(Wallet::class, $transfer->from);
68-
self::assertInstanceOf(Item::class, $transfer->to);
68+
self::assertInstanceOf(Item::class, $transfer->to->holder);
6969
self::assertInstanceOf(Wallet::class, $transfer->to->wallet);
7070

7171
self::assertSame($buyer->wallet->getKey(), $transfer->from->getKey());
7272
self::assertSame($buyer->getKey(), $transfer->from->holder->getKey());
73-
self::assertSame($product->getKey(), $transfer->to->getKey());
73+
self::assertSame($product->wallet->getKey(), $transfer->to->getKey());
74+
self::assertSame($product->getKey(), $transfer->to->holder->getKey());
7475
}
7576

7677
public function testRefundPersonalDiscountAndTax(): void

tests/Units/Domain/DiscountTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ public function testPay(): void
6060

6161
self::assertInstanceOf(Buyer::class, $transfer->from->holder);
6262
self::assertInstanceOf(Wallet::class, $transfer->from);
63-
self::assertInstanceOf(Item::class, $transfer->to);
63+
self::assertInstanceOf(Item::class, $transfer->to->holder);
6464
self::assertInstanceOf(Wallet::class, $transfer->to->wallet);
6565

6666
self::assertSame($buyer->wallet->getKey(), $transfer->from->getKey());
6767
self::assertSame($buyer->getKey(), $transfer->from->holder->getKey());
68-
self::assertSame($product->getKey(), $transfer->to->getKey());
68+
self::assertSame($product->wallet->getKey(), $transfer->to->getKey());
69+
self::assertSame($product->getKey(), $transfer->to->holder->getKey());
6970
}
7071

7172
public function testItemTransactions(): void

tests/Units/Domain/MultiWalletTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public function testPay(): void
500500
self::assertInstanceOf(UserMulti::class, $paidTransfer->withdraw->payable);
501501
self::assertSame($user->getKey(), $paidTransfer->withdraw->payable->getKey());
502502
self::assertSame($transfer->from->id, $a->id);
503-
self::assertSame($transfer->to->id, $product->id);
503+
self::assertSame($transfer->to->id, $product->wallet->id);
504504
self::assertSame($transfer->status, Transfer::STATUS_PAID);
505505
self::assertSame($a->balanceInt, 0);
506506
self::assertSame($product->balanceInt, $product->getAmountProduct($a));
@@ -512,7 +512,7 @@ public function testPay(): void
512512
self::assertInstanceOf(UserMulti::class, $paidTransfer->withdraw->payable);
513513
self::assertSame($user->getKey(), $paidTransfer->withdraw->payable->getKey());
514514
self::assertSame($transfer->from->id, $b->id);
515-
self::assertSame($transfer->to->id, $product->id);
515+
self::assertSame($transfer->to->id, $product->wallet->id);
516516
self::assertSame($transfer->status, Transfer::STATUS_PAID);
517517
self::assertSame($b->balanceInt, 0);
518518
self::assertSame($product->balanceInt, $product->getAmountProduct($b) * 2);

tests/Units/Domain/ProductTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ public function testPay(): void
6060

6161
self::assertInstanceOf(Buyer::class, $transfer->from->holder);
6262
self::assertInstanceOf(Wallet::class, $transfer->from);
63-
self::assertInstanceOf(Item::class, $transfer->to);
63+
self::assertInstanceOf(Item::class, $transfer->to->holder);
6464
self::assertInstanceOf(Wallet::class, $transfer->to->wallet);
6565

6666
self::assertSame($buyer->wallet->getKey(), $transfer->from->getKey());
6767
self::assertSame($buyer->getKey(), $transfer->from->holder->getKey());
68-
self::assertSame($product->getKey(), $transfer->to->getKey());
68+
self::assertSame($product->wallet->getKey(), $transfer->to->getKey());
69+
self::assertSame($product->getKey(), $transfer->to->holder->getKey());
6970

7071
self::assertSame(0, $buyer->balanceInt);
7172
self::assertNull($buyer->safePay($product));

0 commit comments

Comments
 (0)