����JFIF��x�x����'
Server IP : 66.29.137.217 / Your IP : 18.221.70.17 Web Server : LiteSpeed System : Linux premium294.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : gltevjme ( 1095) PHP Version : 7.0.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/./gltevjme/cbt.bofirm.com/vendor/bavix/laravel-wallet/src/Traits/ |
Upload File : |
<?php namespace Bavix\Wallet\Traits; use Bavix\Wallet\Exceptions\BalanceIsEmpty; use Bavix\Wallet\Exceptions\ConfirmedInvalid; use Bavix\Wallet\Exceptions\InsufficientFunds; use Bavix\Wallet\Exceptions\WalletOwnerInvalid; use Bavix\Wallet\Interfaces\Confirmable; use Bavix\Wallet\Interfaces\Mathable; use Bavix\Wallet\Interfaces\Wallet; use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Services\CommonService; use Bavix\Wallet\Services\DbService; use Bavix\Wallet\Services\LockService; use Bavix\Wallet\Services\WalletService; trait CanConfirm { /** * @param Transaction $transaction * * @return bool * * @throws BalanceIsEmpty * @throws InsufficientFunds * @throws ConfirmedInvalid * @throws WalletOwnerInvalid */ public function confirm(Transaction $transaction): bool { return app(LockService::class)->lock($this, __FUNCTION__, function () use ($transaction) { /** @var Wallet|Confirmable $self */ $self = $this; return app(DbService::class)->transaction(static function () use ($self, $transaction) { $wallet = app(WalletService::class)->getWallet($self); if (! $wallet->refreshBalance()) { return false; } if ($transaction->type === Transaction::TYPE_WITHDRAW) { app(CommonService::class)->verifyWithdraw( $wallet, app(Mathable::class)->abs($transaction->amount) ); } return $self->forceConfirm($transaction); }); }); } /** * @param Transaction $transaction * * @return bool */ public function safeConfirm(Transaction $transaction): bool { try { return $this->confirm($transaction); } catch (\Throwable $throwable) { return false; } } /** * Removal of confirmation (forced), use at your own peril and risk. * * @param Transaction $transaction * * @return bool * * @throws ConfirmedInvalid */ public function resetConfirm(Transaction $transaction): bool { return app(LockService::class)->lock($this, __FUNCTION__, function () use ($transaction) { /** @var Wallet $self */ $self = $this; return app(DbService::class)->transaction(static function () use ($self, $transaction) { $wallet = app(WalletService::class)->getWallet($self); if (! $wallet->refreshBalance()) { return false; } if (! $transaction->confirmed) { throw new ConfirmedInvalid(trans('wallet::errors.unconfirmed_invalid')); } $mathService = app(Mathable::class); $negativeAmount = $mathService->negative($transaction->amount); return $transaction->update(['confirmed' => false]) && // update balance app(CommonService::class) ->addBalance($wallet, $negativeAmount); }); }); } /** * @param Transaction $transaction * * @return bool */ public function safeResetConfirm(Transaction $transaction): bool { try { return $this->resetConfirm($transaction); } catch (\Throwable $throwable) { return false; } } /** * @param Transaction $transaction * * @return bool * * @throws ConfirmedInvalid * @throws WalletOwnerInvalid */ public function forceConfirm(Transaction $transaction): bool { return app(LockService::class)->lock($this, __FUNCTION__, function () use ($transaction) { /** @var Wallet $self */ $self = $this; return app(DbService::class)->transaction(static function () use ($self, $transaction) { $wallet = app(WalletService::class) ->getWallet($self); if ($transaction->confirmed) { throw new ConfirmedInvalid(trans('wallet::errors.confirmed_invalid')); } if ($wallet->getKey() !== $transaction->wallet_id) { throw new WalletOwnerInvalid(trans('wallet::errors.owner_invalid')); } return $transaction->update(['confirmed' => true]) && // update balance app(CommonService::class) ->addBalance($wallet, $transaction->amount); }); }); } }