File tree Expand file tree Collapse file tree 3 files changed +24
-8
lines changed Expand file tree Collapse file tree 3 files changed +24
-8
lines changed Original file line number Diff line number Diff line change 66
77use Bavix \Wallet \Exceptions \UnconfirmedInvalid ;
88use Bavix \Wallet \Exceptions \WalletOwnerInvalid ;
9+ use Bavix \Wallet \Interfaces \Wallet ;
910use Bavix \Wallet \Internal \Exceptions \ExceptionInterface ;
1011use Bavix \Wallet \Internal \Exceptions \RecordNotFoundException ;
1112use Bavix \Wallet \Internal \Exceptions \TransactionFailedException ;
@@ -24,6 +25,15 @@ final class TransactionObserver
2425 */
2526 public function deleting (Transaction $ model ): bool
2627 {
27- return $ model ->wallet ->resetConfirm ($ model );
28+ return $ this ->safeResetConfirm ($ model ->wallet , $ model );
29+ }
30+
31+ private function safeResetConfirm (Wallet $ model , Transaction $ transaction ): bool
32+ {
33+ try {
34+ return $ model ->resetConfirm ($ transaction );
35+ } catch (UnconfirmedInvalid ) {
36+ return true ;
37+ }
2838 }
2939}
Original file line number Diff line number Diff line change 66
77use Bavix \Wallet \Exceptions \UnconfirmedInvalid ;
88use Bavix \Wallet \Exceptions \WalletOwnerInvalid ;
9+ use Bavix \Wallet \Interfaces \Wallet ;
910use Bavix \Wallet \Internal \Exceptions \ExceptionInterface ;
1011use Bavix \Wallet \Internal \Exceptions \RecordNotFoundException ;
1112use Bavix \Wallet \Internal \Exceptions \TransactionFailedException ;
13+ use Bavix \Wallet \Models \Transaction ;
1214use Bavix \Wallet \Models \Transfer ;
1315use Bavix \Wallet \Services \AtomicServiceInterface ;
1416use Illuminate \Database \RecordsNotFoundException ;
@@ -31,8 +33,17 @@ public function __construct(
3133 public function deleting (Transfer $ model ): bool
3234 {
3335 return $ this ->atomicService ->blocks ([$ model ->from , $ model ->to ], function () use ($ model ) {
34- return $ model -> from -> resetConfirm ( $ model ->withdraw )
35- && $ model -> to -> resetConfirm ( $ model ->deposit );
36+ return $ this -> safeResetConfirm ( $ model -> from , $ model ->withdraw )
37+ && $ this -> safeResetConfirm ( $ model -> to , $ model ->deposit );
3638 });
3739 }
40+
41+ private function safeResetConfirm (Wallet $ model , Transaction $ transaction ): bool
42+ {
43+ try {
44+ return $ model ->resetConfirm ($ transaction );
45+ } catch (UnconfirmedInvalid ) {
46+ return true ;
47+ }
48+ }
3849}
Original file line number Diff line number Diff line change 44
55namespace Bavix \Wallet \Test \Units \Domain ;
66
7- use Bavix \Wallet \Exceptions \UnconfirmedInvalid ;
87use Bavix \Wallet \Test \Infra \Factories \BuyerFactory ;
98use Bavix \Wallet \Test \Infra \Models \Buyer ;
109use Bavix \Wallet \Test \Infra \TestCase ;
@@ -87,8 +86,6 @@ public function testTransactionDelete(): void
8786
8887 public function testTransactionDeleteIfNotConfirmed (): void
8988 {
90- $ this ->expectException (UnconfirmedInvalid::class);
91-
9289 /** @var Buyer $buyer */
9390 $ buyer = BuyerFactory::new ()->create ();
9491 self ::assertFalse ($ buyer ->relationLoaded ('wallet ' ));
@@ -141,8 +138,6 @@ public function testTransferDelete(): void
141138
142139 public function testTransferDeleteIfNotConfirmed (): void
143140 {
144- $ this ->expectException (UnconfirmedInvalid::class);
145-
146141 /** @var Buyer $user1 */
147142 /** @var Buyer $user2 */
148143 [$ user1 , $ user2 ] = BuyerFactory::times (2 )->create ();
You can’t perform that action at this time.
0 commit comments