mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
|
|
|
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
|
use App\Classes\Modules\Wallets\Services\CreatesWallet;
|
|
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
|
|
use App\Http\Resources\WalletResource;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateWalletLogic extends AbstractControllersLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Company Wallet',
|
|
'message' => 'You have successfully created a company wallet'
|
|
];
|
|
}
|
|
|
|
/** @var CreatesWallet */
|
|
private $createsWallet;
|
|
|
|
/** @var GeneratesWalletCode */
|
|
private $generatesWalletCode;
|
|
|
|
/** @var CanCreateCompanyWallet */
|
|
private $canCreateCompanyWallet;
|
|
|
|
/**
|
|
* CreateWalletLogic constructor.
|
|
* @param CreatesWallet $createsWallet
|
|
* @param GeneratesWalletCode $generatesWalletCode
|
|
* @param CanCreateCompanyWallet $canCreateCompanyWallet
|
|
*/
|
|
public function __construct(CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet)
|
|
{
|
|
$this->createsWallet = $createsWallet;
|
|
$this->generatesWalletCode = $generatesWalletCode;
|
|
$this->canCreateCompanyWallet = $canCreateCompanyWallet;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
$object = new WalletObject($request->input('currency_id'), $request->input('company_id'), $this->generatesWalletCode->execute());
|
|
|
|
$this->canCreateCompanyWallet->passes($object);
|
|
|
|
$wallet = $this->createsWallet->execute($object);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new WalletResource($wallet));
|
|
|
|
} catch (\Exception $exception) {
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
} |