Skip to content

Commit 1c59b95

Browse files
authored
Merge pull request #108 from bavix/extends
#106 #105 add example
2 parents f59eaf4 + 613fbd9 commit 1c59b95

20 files changed

+323
-98
lines changed

.phpstorm.meta.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
use Bavix\Wallet\Models\Transaction;
77
use Bavix\Wallet\Models\Transfer;
88
use Bavix\Wallet\Models\Wallet;
9+
use Bavix\Wallet\Objects\Bring;
10+
use Bavix\Wallet\Objects\Cart;
11+
use Bavix\Wallet\Objects\EmptyLock;
12+
use Bavix\Wallet\Objects\Operation;
913
use Bavix\Wallet\Services\CommonService;
1014
use Bavix\Wallet\Services\ExchangeService;
1115
use Bavix\Wallet\Services\ProxyService;
1216
use Bavix\Wallet\Services\WalletService;
13-
use Bavix\Wallet\Services\MakeService;
1417

1518
override(\app(0), map([
16-
MakeService::class => MakeService::class,
19+
Cart::class => Cart::class,
20+
Bring::class => Bring::class,
21+
Operation::class => Operation::class,
22+
EmptyLock::class => EmptyLock::class,
1723
ExchangeService::class => ExchangeService::class,
1824
CommonService::class => CommonService::class,
1925
ProxyService::class => ProxyService::class,

config/config.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22

3+
use Bavix\Wallet\Objects\Bring;
4+
use Bavix\Wallet\Objects\Cart;
5+
use Bavix\Wallet\Objects\EmptyLock;
6+
use Bavix\Wallet\Objects\Operation;
37
use Bavix\Wallet\Services\ExchangeService;
48
use Bavix\Wallet\Services\CommonService;
5-
use Bavix\Wallet\Services\MakeService;
69
use Bavix\Wallet\Services\ProxyService;
710
use Bavix\Wallet\Services\WalletService;
811
use Bavix\Wallet\Services\LockService;
@@ -50,7 +53,13 @@
5053
'proxy' => ProxyService::class,
5154
'wallet' => WalletService::class,
5255
'lock' => LockService::class,
53-
'make' => MakeService::class,
56+
],
57+
58+
'objects' => [
59+
'bring' => Bring::class,
60+
'cart' => Cart::class,
61+
'emptyLock' => EmptyLock::class,
62+
'operation' => Operation::class,
5463
],
5564

5665
/**

src/Objects/Cart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Cart implements Countable
2525

2626
/**
2727
* @return static
28-
* @deprecated use app(MakeService::class)->makeCart()
28+
* @deprecated use app(Cart::class)
2929
*/
3030
public static function make(): self
3131
{

src/Services/CommonService.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Bavix\Wallet\Models\Transfer;
1010
use Bavix\Wallet\Models\Wallet as WalletModel;
1111
use Bavix\Wallet\Objects\Bring;
12+
use Bavix\Wallet\Objects\Operation;
1213
use Bavix\Wallet\Traits\HasWallet;
1314
use Illuminate\Support\Facades\DB;
1415
use function app;
@@ -52,8 +53,7 @@ public function forceTransfer(Wallet $from, Wallet $to, int $amount, ?array $met
5253
->getWallet($from);
5354

5455
$transfers = $this->multiBrings([
55-
app(MakeService::class)
56-
->makeBring()
56+
app(Bring::class)
5757
->setStatus($status)
5858
->setDeposit($deposit)
5959
->setWithdraw($withdraw)
@@ -84,8 +84,7 @@ public function forceWithdraw(Wallet $wallet, int $amount, ?array $meta, bool $c
8484
$wallet = $walletService->getWallet($wallet);
8585

8686
$transactions = $this->multiOperation($wallet, [
87-
app(MakeService::class)
88-
->makeOperation()
87+
app(Operation::class)
8988
->setType(Transaction::TYPE_WITHDRAW)
9089
->setConfirmed($confirmed)
9190
->setAmount(-$amount)
@@ -115,8 +114,7 @@ public function deposit(Wallet $wallet, int $amount, ?array $meta, bool $confirm
115114
$wallet = $walletService->getWallet($wallet);
116115

117116
$transactions = $this->multiOperation($wallet, [
118-
app(MakeService::class)
119-
->makeOperation()
117+
app(Operation::class)
120118
->setType(Transaction::TYPE_DEPOSIT)
121119
->setConfirmed($confirmed)
122120
->setAmount($amount)

src/Services/LockService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bavix\Wallet\Services;
44

5+
use Bavix\Wallet\Objects\EmptyLock;
56
use Illuminate\Contracts\Cache\Lock;
67
use Illuminate\Contracts\Cache\LockProvider;
78
use Illuminate\Contracts\Cache\Store;
@@ -87,8 +88,7 @@ protected function lockProvider($self, string $name, int $seconds): Lock
8788
}
8889
// @codeCoverageIgnoreEnd
8990

90-
return app(MakeService::class)
91-
->makeEmptyLock();
91+
return app(EmptyLock::class);
9292
}
9393

9494
}

src/Services/MakeService.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Traits/CanExchange.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
use Bavix\Wallet\Interfaces\Wallet;
66
use Bavix\Wallet\Models\Transfer;
7+
use Bavix\Wallet\Objects\Bring;
78
use Bavix\Wallet\Services\CommonService;
89
use Bavix\Wallet\Services\ExchangeService;
910
use Bavix\Wallet\Services\LockService;
10-
use Bavix\Wallet\Services\MakeService;
1111
use Bavix\Wallet\Services\WalletService;
1212
use Illuminate\Support\Facades\DB;
1313

@@ -62,8 +62,7 @@ public function forceExchange(Wallet $to, int $amount, ?array $meta = null): Tra
6262
->deposit($to, $amount * $rate, $meta);
6363

6464
$transfers = app(CommonService::class)->multiBrings([
65-
app(MakeService::class)
66-
->makeBring()
65+
app(Bring::class)
6766
->setStatus(Transfer::STATUS_EXCHANGE)
6867
->setDeposit($deposit)
6968
->setWithdraw($withdraw)

src/Traits/CanPay.php

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

55
use Bavix\Wallet\Interfaces\Product;
66
use Bavix\Wallet\Models\Transfer;
7-
use Bavix\Wallet\Services\MakeService;
7+
use Bavix\Wallet\Objects\Cart;
88
use function current;
99

1010
trait CanPay
@@ -19,7 +19,7 @@ trait CanPay
1919
*/
2020
public function payFree(Product $product): Transfer
2121
{
22-
return current($this->payFreeCart(app(MakeService::class)->makeCart()->addItem($product)));
22+
return current($this->payFreeCart(app(Cart::class)->addItem($product)));
2323
}
2424

2525
/**
@@ -29,7 +29,7 @@ public function payFree(Product $product): Transfer
2929
*/
3030
public function safePay(Product $product, bool $force = null): ?Transfer
3131
{
32-
return current($this->safePayCart(app(MakeService::class)->makeCart()->addItem($product), $force)) ?: null;
32+
return current($this->safePayCart(app(Cart::class)->addItem($product), $force)) ?: null;
3333
}
3434

3535
/**
@@ -40,7 +40,7 @@ public function safePay(Product $product, bool $force = null): ?Transfer
4040
*/
4141
public function pay(Product $product, bool $force = null): Transfer
4242
{
43-
return current($this->payCart(app(MakeService::class)->makeCart()->addItem($product), $force));
43+
return current($this->payCart(app(Cart::class)->addItem($product), $force));
4444
}
4545

4646
/**
@@ -50,7 +50,7 @@ public function pay(Product $product, bool $force = null): Transfer
5050
*/
5151
public function forcePay(Product $product): Transfer
5252
{
53-
return current($this->forcePayCart(app(MakeService::class)->makeCart()->addItem($product)));
53+
return current($this->forcePayCart(app(Cart::class)->addItem($product)));
5454
}
5555

5656
/**
@@ -61,7 +61,7 @@ public function forcePay(Product $product): Transfer
6161
*/
6262
public function safeRefund(Product $product, bool $force = null, bool $gifts = null): bool
6363
{
64-
return $this->safeRefundCart(app(MakeService::class)->makeCart()->addItem($product), $force, $gifts);
64+
return $this->safeRefundCart(app(Cart::class)->addItem($product), $force, $gifts);
6565
}
6666

6767
/**
@@ -73,7 +73,7 @@ public function safeRefund(Product $product, bool $force = null, bool $gifts = n
7373
*/
7474
public function refund(Product $product, bool $force = null, bool $gifts = null): bool
7575
{
76-
return $this->refundCart(app(MakeService::class)->makeCart()->addItem($product), $force, $gifts);
76+
return $this->refundCart(app(Cart::class)->addItem($product), $force, $gifts);
7777
}
7878

7979
/**
@@ -84,7 +84,7 @@ public function refund(Product $product, bool $force = null, bool $gifts = null)
8484
*/
8585
public function forceRefund(Product $product, bool $gifts = null): bool
8686
{
87-
return $this->forceRefundCart(app(MakeService::class)->makeCart()->addItem($product), $gifts);
87+
return $this->forceRefundCart(app(Cart::class)->addItem($product), $gifts);
8888
}
8989

9090
/**
@@ -94,7 +94,7 @@ public function forceRefund(Product $product, bool $gifts = null): bool
9494
*/
9595
public function safeRefundGift(Product $product, bool $force = null): bool
9696
{
97-
return $this->safeRefundGiftCart(app(MakeService::class)->makeCart()->addItem($product), $force);
97+
return $this->safeRefundGiftCart(app(Cart::class)->addItem($product), $force);
9898
}
9999

100100
/**
@@ -105,7 +105,7 @@ public function safeRefundGift(Product $product, bool $force = null): bool
105105
*/
106106
public function refundGift(Product $product, bool $force = null): bool
107107
{
108-
return $this->refundGiftCart(app(MakeService::class)->makeCart()->addItem($product), $force);
108+
return $this->refundGiftCart(app(Cart::class)->addItem($product), $force);
109109
}
110110

111111
/**
@@ -115,7 +115,7 @@ public function refundGift(Product $product, bool $force = null): bool
115115
*/
116116
public function forceRefundGift(Product $product): bool
117117
{
118-
return $this->forceRefundGiftCart(app(MakeService::class)->makeCart()->addItem($product));
118+
return $this->forceRefundGiftCart(app(Cart::class)->addItem($product));
119119
}
120120

121121
}

src/Traits/CartPay.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Bavix\Wallet\Models\Transfer;
88
use Bavix\Wallet\Objects\Cart;
99
use Bavix\Wallet\Services\CommonService;
10-
use Bavix\Wallet\Services\MakeService;
1110
use Illuminate\Database\Eloquent\ModelNotFoundException;
1211
use Illuminate\Support\Facades\DB;
1312
use Throwable;
@@ -230,7 +229,7 @@ public function forceRefundGiftCart(Cart $cart): bool
230229
*/
231230
public function paid(Product $product, bool $gifts = null): ?Transfer
232231
{
233-
return current(app(MakeService::class)->makeCart()->addItem($product)->alreadyBuy($this, $gifts)) ?: null;
232+
return current(app(Cart::class)->addItem($product)->alreadyBuy($this, $gifts)) ?: null;
234233
}
235234

236235
}

src/Traits/HasGift.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use Bavix\Wallet\Interfaces\Product;
66
use Bavix\Wallet\Interfaces\Wallet;
77
use Bavix\Wallet\Models\Transfer;
8+
use Bavix\Wallet\Objects\Bring;
89
use Bavix\Wallet\Services\CommonService;
910
use Bavix\Wallet\Services\LockService;
10-
use Bavix\Wallet\Services\MakeService;
1111
use Bavix\Wallet\Services\WalletService;
1212
use Illuminate\Support\Facades\DB;
1313
use Throwable;
@@ -86,8 +86,7 @@ public function gift(Wallet $to, Product $product, bool $force = null): Transfer
8686
->getWallet($to);
8787

8888
$transfers = $commonService->assemble([
89-
app(MakeService::class)
90-
->makeBring()
89+
app(Bring::class)
9190
->setStatus(Transfer::STATUS_GIFT)
9291
->setDeposit($deposit)
9392
->setWithdraw($withdraw)

0 commit comments

Comments
 (0)